nwo
stringlengths
5
106
sha
stringlengths
40
40
path
stringlengths
4
174
language
stringclasses
1 value
identifier
stringlengths
1
140
parameters
stringlengths
0
87.7k
argument_list
stringclasses
1 value
return_statement
stringlengths
0
426k
docstring
stringlengths
0
64.3k
docstring_summary
stringlengths
0
26.3k
docstring_tokens
list
function
stringlengths
18
4.83M
function_tokens
list
url
stringlengths
83
304
pymedusa/Medusa
1405fbb6eb8ef4d20fcca24c32ddca52b11f0f38
ext/tvdbapiv2/models/user_favorites_data.py
python
UserFavoritesData.data
(self, data)
Sets the data of this UserFavoritesData. :param data: The data of this UserFavoritesData. :type: UserFavorites
Sets the data of this UserFavoritesData.
[ "Sets", "the", "data", "of", "this", "UserFavoritesData", "." ]
def data(self, data): """ Sets the data of this UserFavoritesData. :param data: The data of this UserFavoritesData. :type: UserFavorites """ self._data = data
[ "def", "data", "(", "self", ",", "data", ")", ":", "self", ".", "_data", "=", "data" ]
https://github.com/pymedusa/Medusa/blob/1405fbb6eb8ef4d20fcca24c32ddca52b11f0f38/ext/tvdbapiv2/models/user_favorites_data.py#L64-L72
keiffster/program-y
8c99b56f8c32f01a7b9887b5daae9465619d0385
src/programy/processors/processing.py
python
PostQuestionProcessor.__init__
(self)
[]
def __init__(self): Processor.__init__(self)
[ "def", "__init__", "(", "self", ")", ":", "Processor", ".", "__init__", "(", "self", ")" ]
https://github.com/keiffster/program-y/blob/8c99b56f8c32f01a7b9887b5daae9465619d0385/src/programy/processors/processing.py#L138-L139
owid/covid-19-data
936aeae6cfbdc0163939ed7bd8ecdbb2582c0a92
scripts/src/cowidev/vax/batch/greece.py
python
Greece.read
(self)
return ( df.rename( columns={ "referencedate": "date", "totaldistinctpersons": "people_vaccinated", "totaldose2": "people_fully_vaccinated", "totaldose3": "total_boosters", "totalvaccinations": "total_vaccinations", } )[["people_vaccinated", "people_fully_vaccinated", "total_boosters", "total_vaccinations", "date"]] .groupby("date") .sum() .reset_index() )
[]
def read(self) -> pd.DataFrame: data = requests.get(self.source_url, headers={"Authorization": f"Token {self.token}"}).json() df = pd.DataFrame.from_records(data) check_known_columns( df, [ "area", "areaid", "dailydose1", "dailydose2", "dailydose3", "daydiff", "daytotal", "referencedate", "totaldistinctpersons", "totaldose1", "totaldose2", "totaldose3", "totalvaccinations", ], ) return ( df.rename( columns={ "referencedate": "date", "totaldistinctpersons": "people_vaccinated", "totaldose2": "people_fully_vaccinated", "totaldose3": "total_boosters", "totalvaccinations": "total_vaccinations", } )[["people_vaccinated", "people_fully_vaccinated", "total_boosters", "total_vaccinations", "date"]] .groupby("date") .sum() .reset_index() )
[ "def", "read", "(", "self", ")", "->", "pd", ".", "DataFrame", ":", "data", "=", "requests", ".", "get", "(", "self", ".", "source_url", ",", "headers", "=", "{", "\"Authorization\"", ":", "f\"Token {self.token}\"", "}", ")", ".", "json", "(", ")", "df", "=", "pd", ".", "DataFrame", ".", "from_records", "(", "data", ")", "check_known_columns", "(", "df", ",", "[", "\"area\"", ",", "\"areaid\"", ",", "\"dailydose1\"", ",", "\"dailydose2\"", ",", "\"dailydose3\"", ",", "\"daydiff\"", ",", "\"daytotal\"", ",", "\"referencedate\"", ",", "\"totaldistinctpersons\"", ",", "\"totaldose1\"", ",", "\"totaldose2\"", ",", "\"totaldose3\"", ",", "\"totalvaccinations\"", ",", "]", ",", ")", "return", "(", "df", ".", "rename", "(", "columns", "=", "{", "\"referencedate\"", ":", "\"date\"", ",", "\"totaldistinctpersons\"", ":", "\"people_vaccinated\"", ",", "\"totaldose2\"", ":", "\"people_fully_vaccinated\"", ",", "\"totaldose3\"", ":", "\"total_boosters\"", ",", "\"totalvaccinations\"", ":", "\"total_vaccinations\"", ",", "}", ")", "[", "[", "\"people_vaccinated\"", ",", "\"people_fully_vaccinated\"", ",", "\"total_boosters\"", ",", "\"total_vaccinations\"", ",", "\"date\"", "]", "]", ".", "groupby", "(", "\"date\"", ")", ".", "sum", "(", ")", ".", "reset_index", "(", ")", ")" ]
https://github.com/owid/covid-19-data/blob/936aeae6cfbdc0163939ed7bd8ecdbb2582c0a92/scripts/src/cowidev/vax/batch/greece.py#L17-L51
itamarst/eliot
74e0aa2ec501d9684f1a63c26d0d51963517eddc
eliot/_validation.py
python
Field.serialize
(self, input)
return self._serializer(input)
Convert the given input to a value that can actually be logged. @param input: An input value supposedly serializable by this L{Field}. @return: A serialized value.
Convert the given input to a value that can actually be logged.
[ "Convert", "the", "given", "input", "to", "a", "value", "that", "can", "actually", "be", "logged", "." ]
def serialize(self, input): """ Convert the given input to a value that can actually be logged. @param input: An input value supposedly serializable by this L{Field}. @return: A serialized value. """ return self._serializer(input)
[ "def", "serialize", "(", "self", ",", "input", ")", ":", "return", "self", ".", "_serializer", "(", "input", ")" ]
https://github.com/itamarst/eliot/blob/74e0aa2ec501d9684f1a63c26d0d51963517eddc/eliot/_validation.py#L98-L106
owid/covid-19-data
936aeae6cfbdc0163939ed7bd8ecdbb2582c0a92
scripts/src/cowidev/vax/incremental/brazil.py
python
Brazil.pipe_location
(self, ds: pd.Series)
return enrich_data(ds, "location", self.location)
[]
def pipe_location(self, ds: pd.Series) -> pd.Series: return enrich_data(ds, "location", self.location)
[ "def", "pipe_location", "(", "self", ",", "ds", ":", "pd", ".", "Series", ")", "->", "pd", ".", "Series", ":", "return", "enrich_data", "(", "ds", ",", "\"location\"", ",", "self", ".", "location", ")" ]
https://github.com/owid/covid-19-data/blob/936aeae6cfbdc0163939ed7bd8ecdbb2582c0a92/scripts/src/cowidev/vax/incremental/brazil.py#L28-L29
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/matrix/special.py
python
random_diagonalizable_matrix
(parent,eigenvalues=None,dimensions=None)
return eigenvector_matrix*diagonal_matrix*(eigenvector_matrix.inverse())
Create a random matrix that diagonalizes nicely. To be used as a teaching tool. Return matrices have only real eigenvalues. INPUT: If eigenvalues and dimensions are not specified in a list, they will be assigned randomly. - ``parent`` - the desired size of the square matrix. - ``eigenvalues`` - the list of desired eigenvalues (default=None). - ``dimensions`` - the list of dimensions corresponding to each eigenspace (default=None). OUTPUT: A square, diagonalizable, matrix with only integer entries. The eigenspaces of this matrix, if computed by hand, give basis vectors with only integer entries. .. note:: It is easiest to use this function via a call to the :func:`~sage.matrix.constructor.random_matrix` function with the ``algorithm='diagonalizable'`` keyword. We provide one example accessing this function directly, while the remainder will use this more general function. EXAMPLES: A diagonalizable matrix, size 5. :: sage: from sage.matrix.constructor import random_diagonalizable_matrix sage: matrix_space = sage.matrix.matrix_space.MatrixSpace(QQ, 5) sage: A = random_diagonalizable_matrix(matrix_space) sage: eigenvalues = A.eigenvalues() sage: S = A.right_eigenmatrix()[1] sage: eigenvalues2 = (S.inverse()*A*S).diagonal() sage: sorted(eigenvalues) == sorted(eigenvalues2) True A diagonalizable matrix with eigenvalues and dimensions designated, with a check that if eigenvectors were calculated by hand entries would all be integers. :: sage: eigenvalues = [ZZ.random_element() for _ in range(3)] sage: B = random_matrix(QQ, 6, algorithm='diagonalizable', eigenvalues=eigenvalues, dimensions=[2,3,1]) sage: all(x in ZZ for x in (B-(-12*identity_matrix(6))).rref().list()) True sage: all(x in ZZ for x in (B-(4*identity_matrix(6))).rref().list()) True sage: all(x in ZZ for x in (B-(6*identity_matrix(6))).rref().list()) True sage: S = B.right_eigenmatrix()[1] sage: eigenvalues2 = (S.inverse()*B*S).diagonal() sage: all(e in eigenvalues for e in eigenvalues2) True TESTS: Eigenvalues must all be integers. :: sage: random_matrix(QQ,3,algorithm='diagonalizable', eigenvalues=[2+I,2-I,2],dimensions=[1,1,1]) Traceback (most recent call last): ... TypeError: eigenvalues must be integers. Diagonal matrices must be square. :: sage: random_matrix(QQ, 5, 7, algorithm='diagonalizable', eigenvalues=[-5,2,-3], dimensions=[1,1,3]) Traceback (most recent call last): ... TypeError: a diagonalizable matrix must be square. A list of eigenvalues must be accompanied with a list of dimensions. :: sage: random_matrix(QQ,10,algorithm='diagonalizable',eigenvalues=[4,8]) Traceback (most recent call last): ... ValueError: the list of eigenvalues must have a list of dimensions corresponding to each eigenvalue. A list of dimensions must be accompanied with a list of eigenvalues. :: sage: random_matrix(QQ, 10,algorithm='diagonalizable',dimensions=[2,2,4,2]) Traceback (most recent call last): ... ValueError: the list of dimensions must have a list of corresponding eigenvalues. The sum of the eigenvalue dimensions must equal the size of the matrix. :: sage: random_matrix(QQ,12,algorithm='diagonalizable',eigenvalues=[4,2,6,-1],dimensions=[2,3,5,1]) Traceback (most recent call last): ... ValueError: the size of the matrix must equal the sum of the dimensions. Each eigenspace dimension must be at least 1. :: sage: random_matrix(QQ,9,algorithm='diagonalizable',eigenvalues=[-15,22,8,-4,90,12],dimensions=[4,2,2,4,-3,0]) Traceback (most recent call last): ... ValueError: eigenspaces must have a dimension of at least 1. Each eigenvalue must have a corresponding eigenspace dimension. :: sage: random_matrix(QQ,12,algorithm='diagonalizable',eigenvalues=[4,2,6,-1],dimensions=[4,3,5]) Traceback (most recent call last): ... ValueError: each eigenvalue must have a corresponding dimension and each dimension a corresponding eigenvalue. Each dimension must have an eigenvalue paired to it. :: sage: random_matrix(QQ,12,algorithm='diagonalizable',eigenvalues=[4,2,6],dimensions=[2,3,5,2]) Traceback (most recent call last): ... ValueError: each eigenvalue must have a corresponding dimension and each dimension a corresponding eigenvalue. .. TODO:: Modify the routine to allow for complex eigenvalues. AUTHOR: Billy Wonderly (2010-07)
Create a random matrix that diagonalizes nicely.
[ "Create", "a", "random", "matrix", "that", "diagonalizes", "nicely", "." ]
def random_diagonalizable_matrix(parent,eigenvalues=None,dimensions=None): """ Create a random matrix that diagonalizes nicely. To be used as a teaching tool. Return matrices have only real eigenvalues. INPUT: If eigenvalues and dimensions are not specified in a list, they will be assigned randomly. - ``parent`` - the desired size of the square matrix. - ``eigenvalues`` - the list of desired eigenvalues (default=None). - ``dimensions`` - the list of dimensions corresponding to each eigenspace (default=None). OUTPUT: A square, diagonalizable, matrix with only integer entries. The eigenspaces of this matrix, if computed by hand, give basis vectors with only integer entries. .. note:: It is easiest to use this function via a call to the :func:`~sage.matrix.constructor.random_matrix` function with the ``algorithm='diagonalizable'`` keyword. We provide one example accessing this function directly, while the remainder will use this more general function. EXAMPLES: A diagonalizable matrix, size 5. :: sage: from sage.matrix.constructor import random_diagonalizable_matrix sage: matrix_space = sage.matrix.matrix_space.MatrixSpace(QQ, 5) sage: A = random_diagonalizable_matrix(matrix_space) sage: eigenvalues = A.eigenvalues() sage: S = A.right_eigenmatrix()[1] sage: eigenvalues2 = (S.inverse()*A*S).diagonal() sage: sorted(eigenvalues) == sorted(eigenvalues2) True A diagonalizable matrix with eigenvalues and dimensions designated, with a check that if eigenvectors were calculated by hand entries would all be integers. :: sage: eigenvalues = [ZZ.random_element() for _ in range(3)] sage: B = random_matrix(QQ, 6, algorithm='diagonalizable', eigenvalues=eigenvalues, dimensions=[2,3,1]) sage: all(x in ZZ for x in (B-(-12*identity_matrix(6))).rref().list()) True sage: all(x in ZZ for x in (B-(4*identity_matrix(6))).rref().list()) True sage: all(x in ZZ for x in (B-(6*identity_matrix(6))).rref().list()) True sage: S = B.right_eigenmatrix()[1] sage: eigenvalues2 = (S.inverse()*B*S).diagonal() sage: all(e in eigenvalues for e in eigenvalues2) True TESTS: Eigenvalues must all be integers. :: sage: random_matrix(QQ,3,algorithm='diagonalizable', eigenvalues=[2+I,2-I,2],dimensions=[1,1,1]) Traceback (most recent call last): ... TypeError: eigenvalues must be integers. Diagonal matrices must be square. :: sage: random_matrix(QQ, 5, 7, algorithm='diagonalizable', eigenvalues=[-5,2,-3], dimensions=[1,1,3]) Traceback (most recent call last): ... TypeError: a diagonalizable matrix must be square. A list of eigenvalues must be accompanied with a list of dimensions. :: sage: random_matrix(QQ,10,algorithm='diagonalizable',eigenvalues=[4,8]) Traceback (most recent call last): ... ValueError: the list of eigenvalues must have a list of dimensions corresponding to each eigenvalue. A list of dimensions must be accompanied with a list of eigenvalues. :: sage: random_matrix(QQ, 10,algorithm='diagonalizable',dimensions=[2,2,4,2]) Traceback (most recent call last): ... ValueError: the list of dimensions must have a list of corresponding eigenvalues. The sum of the eigenvalue dimensions must equal the size of the matrix. :: sage: random_matrix(QQ,12,algorithm='diagonalizable',eigenvalues=[4,2,6,-1],dimensions=[2,3,5,1]) Traceback (most recent call last): ... ValueError: the size of the matrix must equal the sum of the dimensions. Each eigenspace dimension must be at least 1. :: sage: random_matrix(QQ,9,algorithm='diagonalizable',eigenvalues=[-15,22,8,-4,90,12],dimensions=[4,2,2,4,-3,0]) Traceback (most recent call last): ... ValueError: eigenspaces must have a dimension of at least 1. Each eigenvalue must have a corresponding eigenspace dimension. :: sage: random_matrix(QQ,12,algorithm='diagonalizable',eigenvalues=[4,2,6,-1],dimensions=[4,3,5]) Traceback (most recent call last): ... ValueError: each eigenvalue must have a corresponding dimension and each dimension a corresponding eigenvalue. Each dimension must have an eigenvalue paired to it. :: sage: random_matrix(QQ,12,algorithm='diagonalizable',eigenvalues=[4,2,6],dimensions=[2,3,5,2]) Traceback (most recent call last): ... ValueError: each eigenvalue must have a corresponding dimension and each dimension a corresponding eigenvalue. .. TODO:: Modify the routine to allow for complex eigenvalues. AUTHOR: Billy Wonderly (2010-07) """ from sage.misc.prandom import randint size = parent.nrows() if parent.nrows() != parent.ncols(): raise TypeError("a diagonalizable matrix must be square.") if eigenvalues is not None and dimensions is None: raise ValueError("the list of eigenvalues must have a list of dimensions corresponding to each eigenvalue.") if eigenvalues is None and dimensions is not None: raise ValueError("the list of dimensions must have a list of corresponding eigenvalues.") if eigenvalues is None and dimensions is None: values = [] #create a list with "size" number of entries for eigen_index in range(size): eigenvalue = randint(-10, 10) values.append(eigenvalue) values.sort() dimensions = [] eigenvalues = [] #create a list with no duplicate values to be the eigenvalues for eigenvalue in range(size): if values[eigenvalue] not in eigenvalues: eigenvalues.append(values[eigenvalue]) for dimension in range(len(eigenvalues)): #dimension is equal to how many times an eigenvalue was generated in the 'values' list dimensions.append(values.count(eigenvalues[dimension])) size_check = 0 for check in range(len(dimensions)): size_check = size_check + dimensions[check] if not all(x in ZZ for x in eigenvalues): raise TypeError("eigenvalues must be integers.") if size != size_check: raise ValueError("the size of the matrix must equal the sum of the dimensions.") if min(dimensions) < 1: raise ValueError("eigenspaces must have a dimension of at least 1.") if len(eigenvalues) != len(dimensions): raise ValueError("each eigenvalue must have a corresponding dimension and each dimension a corresponding eigenvalue.") #sort the dimensions in order of increasing size, and sort the eigenvalues list in an identical fashion, to maintain corresponding values. dimensions_sort = sorted(zip(dimensions, eigenvalues)) dimensions = [x[0] for x in dimensions_sort] eigenvalues = [x[1] for x in dimensions_sort] #Create the matrix of eigenvalues on the diagonal. Use a lower limit and upper limit determined by the eigenvalue dimensions. diagonal_matrix = matrix(QQ, size) up_bound = 0 low_bound = 0 for row_index in range(len(dimensions)): up_bound = up_bound + dimensions[row_index] for entry in range(low_bound,up_bound): diagonal_matrix[entry, entry] = eigenvalues[row_index] low_bound=low_bound+dimensions[row_index] # Create a matrix to hold each of the eigenvectors as its columns, begin with an identity matrix so that after row and column # operations the resulting matrix will be unimodular. eigenvector_matrix = matrix(QQ, size, size, 1) upper_limit = 0 lower_limit = 0 #run the routine over the necessary number of columns corresponding eigenvalue dimension. for dimension_index in range(len(dimensions)-1): upper_limit=upper_limit+dimensions[dimension_index] lowest_index_row_with_one=size-dimensions[dimension_index] #assign a one to the row that is the eigenvalue dimension rows up from the bottom row then assign ones diagonally down to the right. for eigen_ones in range(lower_limit,upper_limit): eigenvector_matrix[lowest_index_row_with_one,eigen_ones]=1 lowest_index_row_with_one+=1 lower_limit=lower_limit+dimensions[dimension_index] #Create a list to give the eigenvalue dimension corresponding to each column. dimension_check = [] for i in range(len(dimensions)): for k in range(dimensions[i]): dimension_check.append(dimensions[i]) #run routine over the rows that are in the range of the protected ones. Use addition of column multiples to fill entries. for dimension_multiplicity in range(max(dimensions),min(dimensions),-1): highest_one_row=size-dimension_multiplicity highest_one_column=0 #find the column with the protected one in the lowest indexed row. while eigenvector_matrix[highest_one_row,highest_one_column]==0: highest_one_column+=1 #dimension_check determines if column has a low enough eigenvalue dimension to take a column multiple. for bottom_entry_filler in range(len(dimension_check)): if dimension_check[bottom_entry_filler]<dimension_multiplicity and eigenvector_matrix[highest_one_row,bottom_entry_filler]==0: # randint range determined experimentally to keep entries manageable. eigenvector_matrix.add_multiple_of_column(bottom_entry_filler,highest_one_column,randint(-4,4)) #Fill remaining rows using scalar row addition. for row in range(size-max(dimensions),size): for upper_row in range(size-max(dimensions)): # range of multiplier determined experimentally so that entries stay manageable for small matrices eigenvector_matrix.add_multiple_of_row(upper_row,row,randint(-4,4)) return eigenvector_matrix*diagonal_matrix*(eigenvector_matrix.inverse())
[ "def", "random_diagonalizable_matrix", "(", "parent", ",", "eigenvalues", "=", "None", ",", "dimensions", "=", "None", ")", ":", "from", "sage", ".", "misc", ".", "prandom", "import", "randint", "size", "=", "parent", ".", "nrows", "(", ")", "if", "parent", ".", "nrows", "(", ")", "!=", "parent", ".", "ncols", "(", ")", ":", "raise", "TypeError", "(", "\"a diagonalizable matrix must be square.\"", ")", "if", "eigenvalues", "is", "not", "None", "and", "dimensions", "is", "None", ":", "raise", "ValueError", "(", "\"the list of eigenvalues must have a list of dimensions corresponding to each eigenvalue.\"", ")", "if", "eigenvalues", "is", "None", "and", "dimensions", "is", "not", "None", ":", "raise", "ValueError", "(", "\"the list of dimensions must have a list of corresponding eigenvalues.\"", ")", "if", "eigenvalues", "is", "None", "and", "dimensions", "is", "None", ":", "values", "=", "[", "]", "#create a list with \"size\" number of entries", "for", "eigen_index", "in", "range", "(", "size", ")", ":", "eigenvalue", "=", "randint", "(", "-", "10", ",", "10", ")", "values", ".", "append", "(", "eigenvalue", ")", "values", ".", "sort", "(", ")", "dimensions", "=", "[", "]", "eigenvalues", "=", "[", "]", "#create a list with no duplicate values to be the eigenvalues", "for", "eigenvalue", "in", "range", "(", "size", ")", ":", "if", "values", "[", "eigenvalue", "]", "not", "in", "eigenvalues", ":", "eigenvalues", ".", "append", "(", "values", "[", "eigenvalue", "]", ")", "for", "dimension", "in", "range", "(", "len", "(", "eigenvalues", ")", ")", ":", "#dimension is equal to how many times an eigenvalue was generated in the 'values' list", "dimensions", ".", "append", "(", "values", ".", "count", "(", "eigenvalues", "[", "dimension", "]", ")", ")", "size_check", "=", "0", "for", "check", "in", "range", "(", "len", "(", "dimensions", ")", ")", ":", "size_check", "=", "size_check", "+", "dimensions", "[", "check", "]", "if", "not", "all", "(", "x", "in", "ZZ", "for", "x", "in", "eigenvalues", ")", ":", "raise", "TypeError", "(", "\"eigenvalues must be integers.\"", ")", "if", "size", "!=", "size_check", ":", "raise", "ValueError", "(", "\"the size of the matrix must equal the sum of the dimensions.\"", ")", "if", "min", "(", "dimensions", ")", "<", "1", ":", "raise", "ValueError", "(", "\"eigenspaces must have a dimension of at least 1.\"", ")", "if", "len", "(", "eigenvalues", ")", "!=", "len", "(", "dimensions", ")", ":", "raise", "ValueError", "(", "\"each eigenvalue must have a corresponding dimension and each dimension a corresponding eigenvalue.\"", ")", "#sort the dimensions in order of increasing size, and sort the eigenvalues list in an identical fashion, to maintain corresponding values.", "dimensions_sort", "=", "sorted", "(", "zip", "(", "dimensions", ",", "eigenvalues", ")", ")", "dimensions", "=", "[", "x", "[", "0", "]", "for", "x", "in", "dimensions_sort", "]", "eigenvalues", "=", "[", "x", "[", "1", "]", "for", "x", "in", "dimensions_sort", "]", "#Create the matrix of eigenvalues on the diagonal. Use a lower limit and upper limit determined by the eigenvalue dimensions.", "diagonal_matrix", "=", "matrix", "(", "QQ", ",", "size", ")", "up_bound", "=", "0", "low_bound", "=", "0", "for", "row_index", "in", "range", "(", "len", "(", "dimensions", ")", ")", ":", "up_bound", "=", "up_bound", "+", "dimensions", "[", "row_index", "]", "for", "entry", "in", "range", "(", "low_bound", ",", "up_bound", ")", ":", "diagonal_matrix", "[", "entry", ",", "entry", "]", "=", "eigenvalues", "[", "row_index", "]", "low_bound", "=", "low_bound", "+", "dimensions", "[", "row_index", "]", "# Create a matrix to hold each of the eigenvectors as its columns, begin with an identity matrix so that after row and column", "# operations the resulting matrix will be unimodular.", "eigenvector_matrix", "=", "matrix", "(", "QQ", ",", "size", ",", "size", ",", "1", ")", "upper_limit", "=", "0", "lower_limit", "=", "0", "#run the routine over the necessary number of columns corresponding eigenvalue dimension.", "for", "dimension_index", "in", "range", "(", "len", "(", "dimensions", ")", "-", "1", ")", ":", "upper_limit", "=", "upper_limit", "+", "dimensions", "[", "dimension_index", "]", "lowest_index_row_with_one", "=", "size", "-", "dimensions", "[", "dimension_index", "]", "#assign a one to the row that is the eigenvalue dimension rows up from the bottom row then assign ones diagonally down to the right.", "for", "eigen_ones", "in", "range", "(", "lower_limit", ",", "upper_limit", ")", ":", "eigenvector_matrix", "[", "lowest_index_row_with_one", ",", "eigen_ones", "]", "=", "1", "lowest_index_row_with_one", "+=", "1", "lower_limit", "=", "lower_limit", "+", "dimensions", "[", "dimension_index", "]", "#Create a list to give the eigenvalue dimension corresponding to each column.", "dimension_check", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "dimensions", ")", ")", ":", "for", "k", "in", "range", "(", "dimensions", "[", "i", "]", ")", ":", "dimension_check", ".", "append", "(", "dimensions", "[", "i", "]", ")", "#run routine over the rows that are in the range of the protected ones. Use addition of column multiples to fill entries.", "for", "dimension_multiplicity", "in", "range", "(", "max", "(", "dimensions", ")", ",", "min", "(", "dimensions", ")", ",", "-", "1", ")", ":", "highest_one_row", "=", "size", "-", "dimension_multiplicity", "highest_one_column", "=", "0", "#find the column with the protected one in the lowest indexed row.", "while", "eigenvector_matrix", "[", "highest_one_row", ",", "highest_one_column", "]", "==", "0", ":", "highest_one_column", "+=", "1", "#dimension_check determines if column has a low enough eigenvalue dimension to take a column multiple.", "for", "bottom_entry_filler", "in", "range", "(", "len", "(", "dimension_check", ")", ")", ":", "if", "dimension_check", "[", "bottom_entry_filler", "]", "<", "dimension_multiplicity", "and", "eigenvector_matrix", "[", "highest_one_row", ",", "bottom_entry_filler", "]", "==", "0", ":", "# randint range determined experimentally to keep entries manageable.", "eigenvector_matrix", ".", "add_multiple_of_column", "(", "bottom_entry_filler", ",", "highest_one_column", ",", "randint", "(", "-", "4", ",", "4", ")", ")", "#Fill remaining rows using scalar row addition.", "for", "row", "in", "range", "(", "size", "-", "max", "(", "dimensions", ")", ",", "size", ")", ":", "for", "upper_row", "in", "range", "(", "size", "-", "max", "(", "dimensions", ")", ")", ":", "# range of multiplier determined experimentally so that entries stay manageable for small matrices", "eigenvector_matrix", ".", "add_multiple_of_row", "(", "upper_row", ",", "row", ",", "randint", "(", "-", "4", ",", "4", ")", ")", "return", "eigenvector_matrix", "*", "diagonal_matrix", "*", "(", "eigenvector_matrix", ".", "inverse", "(", ")", ")" ]
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/matrix/special.py#L3010-L3225
wucng/TensorExpand
4ea58f64f5c5082b278229b799c9f679536510b7
TensorExpand/Object detection/YOLO/darkflow/darkflow/net/build.py
python
TFNet.build_forward
(self)
[]
def build_forward(self): verbalise = self.FLAGS.verbalise # Placeholders inp_size = [None] + self.meta['inp_size'] self.inp = tf.placeholder(tf.float32, inp_size, 'input') self.feed = dict() # other placeholders # Build the forward pass state = identity(self.inp) roof = self.num_layer - self.ntrain self.say(HEADER, LINE) for i, layer in enumerate(self.darknet.layers): scope = '{}-{}'.format(str(i),layer.type) args = [layer, state, i, roof, self.feed] state = op_create(*args) mess = state.verbalise() self.say(mess) self.say(LINE) self.top = state self.out = tf.identity(state.out, name='output')
[ "def", "build_forward", "(", "self", ")", ":", "verbalise", "=", "self", ".", "FLAGS", ".", "verbalise", "# Placeholders", "inp_size", "=", "[", "None", "]", "+", "self", ".", "meta", "[", "'inp_size'", "]", "self", ".", "inp", "=", "tf", ".", "placeholder", "(", "tf", ".", "float32", ",", "inp_size", ",", "'input'", ")", "self", ".", "feed", "=", "dict", "(", ")", "# other placeholders", "# Build the forward pass", "state", "=", "identity", "(", "self", ".", "inp", ")", "roof", "=", "self", ".", "num_layer", "-", "self", ".", "ntrain", "self", ".", "say", "(", "HEADER", ",", "LINE", ")", "for", "i", ",", "layer", "in", "enumerate", "(", "self", ".", "darknet", ".", "layers", ")", ":", "scope", "=", "'{}-{}'", ".", "format", "(", "str", "(", "i", ")", ",", "layer", ".", "type", ")", "args", "=", "[", "layer", ",", "state", ",", "i", ",", "roof", ",", "self", ".", "feed", "]", "state", "=", "op_create", "(", "*", "args", ")", "mess", "=", "state", ".", "verbalise", "(", ")", "self", ".", "say", "(", "mess", ")", "self", ".", "say", "(", "LINE", ")", "self", ".", "top", "=", "state", "self", ".", "out", "=", "tf", ".", "identity", "(", "state", ".", "out", ",", "name", "=", "'output'", ")" ]
https://github.com/wucng/TensorExpand/blob/4ea58f64f5c5082b278229b799c9f679536510b7/TensorExpand/Object detection/YOLO/darkflow/darkflow/net/build.py#L100-L121
aajanki/yle-dl
b0aa1bb5d943fdbd9a18da2604f21bb2094eadd7
yledl/extractors.py
python
url_language
(url)
[]
def url_language(url): arenan = re.match(r'^https?://arenan\.yle\.fi/', url) is not None arkivet = re.match(r'^https?://svenska\.yle\.fi/artikel/', url) is not None if arenan or arkivet: return 'swe' else: return 'fin'
[ "def", "url_language", "(", "url", ")", ":", "arenan", "=", "re", ".", "match", "(", "r'^https?://arenan\\.yle\\.fi/'", ",", "url", ")", "is", "not", "None", "arkivet", "=", "re", ".", "match", "(", "r'^https?://svenska\\.yle\\.fi/artikel/'", ",", "url", ")", "is", "not", "None", "if", "arenan", "or", "arkivet", ":", "return", "'swe'", "else", ":", "return", "'fin'" ]
https://github.com/aajanki/yle-dl/blob/b0aa1bb5d943fdbd9a18da2604f21bb2094eadd7/yledl/extractors.py#L48-L54
python-diamond/Diamond
7000e16cfdf4508ed9291fc4b3800592557b2431
src/collectors/kafkastat/kafkastat.py
python
KafkaCollector.get_default_config_help
(self)
return config_help
[]
def get_default_config_help(self): config_help = super(KafkaCollector, self).get_default_config_help() config_help.update({ 'host': "", 'port': "", }) return config_help
[ "def", "get_default_config_help", "(", "self", ")", ":", "config_help", "=", "super", "(", "KafkaCollector", ",", "self", ")", ".", "get_default_config_help", "(", ")", "config_help", ".", "update", "(", "{", "'host'", ":", "\"\"", ",", "'port'", ":", "\"\"", ",", "}", ")", "return", "config_help" ]
https://github.com/python-diamond/Diamond/blob/7000e16cfdf4508ed9291fc4b3800592557b2431/src/collectors/kafkastat/kafkastat.py#L37-L43
gwastro/pycbc
1e1c85534b9dba8488ce42df693230317ca63dea
pycbc/tmpltbank/option_utils.py
python
insert_mass_range_option_group
(parser,nonSpin=False)
return massOpts
Adds the options used to specify mass ranges in the bank generation codes to an argparser as an OptionGroup. This should be used if you want to use these options in your code. Parameters ----------- parser : object OptionParser instance. nonSpin : boolean, optional (default=False) If this is provided the spin-related options will not be added.
Adds the options used to specify mass ranges in the bank generation codes to an argparser as an OptionGroup. This should be used if you want to use these options in your code. Parameters ----------- parser : object OptionParser instance. nonSpin : boolean, optional (default=False) If this is provided the spin-related options will not be added.
[ "Adds", "the", "options", "used", "to", "specify", "mass", "ranges", "in", "the", "bank", "generation", "codes", "to", "an", "argparser", "as", "an", "OptionGroup", ".", "This", "should", "be", "used", "if", "you", "want", "to", "use", "these", "options", "in", "your", "code", ".", "Parameters", "-----------", "parser", ":", "object", "OptionParser", "instance", ".", "nonSpin", ":", "boolean", "optional", "(", "default", "=", "False", ")", "If", "this", "is", "provided", "the", "spin", "-", "related", "options", "will", "not", "be", "added", "." ]
def insert_mass_range_option_group(parser,nonSpin=False): """ Adds the options used to specify mass ranges in the bank generation codes to an argparser as an OptionGroup. This should be used if you want to use these options in your code. Parameters ----------- parser : object OptionParser instance. nonSpin : boolean, optional (default=False) If this is provided the spin-related options will not be added. """ massOpts = parser.add_argument_group("Options related to mass and spin " "limits for bank generation") massOpts.add_argument("--min-mass1", action="store", type=positive_float, required=True, help="Minimum mass1: must be >= min-mass2. " "REQUIRED. UNITS=Solar mass") massOpts.add_argument("--max-mass1", action="store", type=positive_float, required=True, help="Maximum mass1: must be >= max-mass2. " "REQUIRED. UNITS=Solar mass") massOpts.add_argument("--min-mass2", action="store", type=positive_float, required=True, help="Minimum mass2. REQUIRED. UNITS=Solar mass") massOpts.add_argument("--max-mass2", action="store", type=positive_float, required=True, help="Maximum mass2. REQUIRED. UNITS=Solar mass") massOpts.add_argument("--max-total-mass", action="store", type=positive_float, default=None, help="Maximum total mass. OPTIONAL, if not provided " "the max total mass is determined by the component " "masses. UNITS=Solar mass") massOpts.add_argument("--min-total-mass", action="store", type=positive_float, default=None, help="Minimum total mass. OPTIONAL, if not provided the " "min total mass is determined by the component masses." " UNITS=Solar mass") massOpts.add_argument("--max-chirp-mass", action="store", type=positive_float, default=None, help="Maximum chirp mass. OPTIONAL, if not provided the " "max chirp mass is determined by the component masses." " UNITS=Solar mass") massOpts.add_argument("--min-chirp-mass", action="store", type=positive_float, default=None, help="Minimum total mass. OPTIONAL, if not provided the " "min chirp mass is determined by the component masses." " UNITS=Solar mass") massOpts.add_argument("--max-eta", action="store", type=positive_float, default=0.25, help="Maximum symmetric mass ratio. OPTIONAL, no upper bound" " on eta will be imposed if not provided. " "UNITS=Solar mass.") massOpts.add_argument("--min-eta", action="store", type=nonnegative_float, default=0., help="Minimum symmetric mass ratio. OPTIONAL, no lower bound" " on eta will be imposed if not provided. " "UNITS=Solar mass.") massOpts.add_argument("--ns-eos", action="store", default=None, help="Select the EOS to be used for the NS when calculating " "the remnant disk mass. Only 2H is currently supported. " "OPTIONAL") massOpts.add_argument("--remnant-mass-threshold", action="store", type=nonnegative_float, default=None, help="Setting this filters EM dim NS-BH binaries: if the " "remnant disk mass does not exceed this value, the NS-BH " "binary is dropped from the target parameter space. " "When it is set to None (default value) the EM dim " "filter is not activated. OPTIONAL") massOpts.add_argument("--use-eos-max-ns-mass", action="store_true", default=False, help="Cut the mass range of the smaller object to the maximum " "mass allowed by EOS. " "OPTIONAL") massOpts.add_argument("--delta-bh-spin", action="store", type=positive_float, default=None, help="Grid spacing used for the BH spin z component when " "generating the surface of the minumum minimum symmetric " "mass ratio as a function of BH spin and NS mass required " "to produce a remnant disk mass that exceeds the threshold " "specificed in --remnant-mass-threshold. " "OPTIONAL (0.1 by default) ") massOpts.add_argument("--delta-ns-mass", action="store", type=positive_float, default=None, help="Grid spacing used for the NS mass when generating the " "surface of the minumum minimum symmetric mass ratio as " "a function of BH spin and NS mass required to produce " "a remnant disk mass that exceeds the thrsehold specified " "in --remnant-mass-threshold. " "OPTIONAL (0.1 by default) ") if nonSpin: parser.add_argument_group(massOpts) return massOpts massOpts.add_argument("--max-ns-spin-mag", action="store", type=nonnegative_float, default=None, help="Maximum neutron star spin magnitude. Neutron stars " "are defined as components lighter than the NS-BH " "boundary (3 Msun by default). REQUIRED if min-mass2 " "< ns-bh-boundary-mass") massOpts.add_argument("--max-bh-spin-mag", action="store", type=nonnegative_float, default=None, help="Maximum black hole spin magnitude. Black holes are " "defined as components at or above the NS-BH boundary " "(3 Msun by default). REQUIRED if max-mass1 >= " "ns-bh-boundary-mass") # Mutually exclusive group prevents both options being set on command line # If --nsbh-flag is True then spinning bank generation must ignore the # default value of ns-bh-boundary-mass. action = massOpts.add_mutually_exclusive_group(required=False) action.add_argument("--ns-bh-boundary-mass", action='store', type=positive_float, help="Mass boundary between neutron stars and black holes. " "Components below this mass are considered neutron " "stars and are subject to the neutron star spin limits. " "Components at/above are subject to the black hole spin " "limits. OPTIONAL, default=%f. UNITS=Solar mass" \ % massRangeParameters.default_nsbh_boundary_mass) action.add_argument("--nsbh-flag", action="store_true", default=False, help="Set this flag if generating a bank that contains only " "systems with 1 black hole and 1 neutron star. With " "this flag set the heavier body will always be subject " "to the black hole spin restriction and the lighter " "to the neutron star spin restriction, regardless of " "mass. OPTIONAL. If set, the value of " "--ns-bh-boundary-mass will be ignored.") return massOpts
[ "def", "insert_mass_range_option_group", "(", "parser", ",", "nonSpin", "=", "False", ")", ":", "massOpts", "=", "parser", ".", "add_argument_group", "(", "\"Options related to mass and spin \"", "\"limits for bank generation\"", ")", "massOpts", ".", "add_argument", "(", "\"--min-mass1\"", ",", "action", "=", "\"store\"", ",", "type", "=", "positive_float", ",", "required", "=", "True", ",", "help", "=", "\"Minimum mass1: must be >= min-mass2. \"", "\"REQUIRED. UNITS=Solar mass\"", ")", "massOpts", ".", "add_argument", "(", "\"--max-mass1\"", ",", "action", "=", "\"store\"", ",", "type", "=", "positive_float", ",", "required", "=", "True", ",", "help", "=", "\"Maximum mass1: must be >= max-mass2. \"", "\"REQUIRED. UNITS=Solar mass\"", ")", "massOpts", ".", "add_argument", "(", "\"--min-mass2\"", ",", "action", "=", "\"store\"", ",", "type", "=", "positive_float", ",", "required", "=", "True", ",", "help", "=", "\"Minimum mass2. REQUIRED. UNITS=Solar mass\"", ")", "massOpts", ".", "add_argument", "(", "\"--max-mass2\"", ",", "action", "=", "\"store\"", ",", "type", "=", "positive_float", ",", "required", "=", "True", ",", "help", "=", "\"Maximum mass2. REQUIRED. UNITS=Solar mass\"", ")", "massOpts", ".", "add_argument", "(", "\"--max-total-mass\"", ",", "action", "=", "\"store\"", ",", "type", "=", "positive_float", ",", "default", "=", "None", ",", "help", "=", "\"Maximum total mass. OPTIONAL, if not provided \"", "\"the max total mass is determined by the component \"", "\"masses. UNITS=Solar mass\"", ")", "massOpts", ".", "add_argument", "(", "\"--min-total-mass\"", ",", "action", "=", "\"store\"", ",", "type", "=", "positive_float", ",", "default", "=", "None", ",", "help", "=", "\"Minimum total mass. OPTIONAL, if not provided the \"", "\"min total mass is determined by the component masses.\"", "\" UNITS=Solar mass\"", ")", "massOpts", ".", "add_argument", "(", "\"--max-chirp-mass\"", ",", "action", "=", "\"store\"", ",", "type", "=", "positive_float", ",", "default", "=", "None", ",", "help", "=", "\"Maximum chirp mass. OPTIONAL, if not provided the \"", "\"max chirp mass is determined by the component masses.\"", "\" UNITS=Solar mass\"", ")", "massOpts", ".", "add_argument", "(", "\"--min-chirp-mass\"", ",", "action", "=", "\"store\"", ",", "type", "=", "positive_float", ",", "default", "=", "None", ",", "help", "=", "\"Minimum total mass. OPTIONAL, if not provided the \"", "\"min chirp mass is determined by the component masses.\"", "\" UNITS=Solar mass\"", ")", "massOpts", ".", "add_argument", "(", "\"--max-eta\"", ",", "action", "=", "\"store\"", ",", "type", "=", "positive_float", ",", "default", "=", "0.25", ",", "help", "=", "\"Maximum symmetric mass ratio. OPTIONAL, no upper bound\"", "\" on eta will be imposed if not provided. \"", "\"UNITS=Solar mass.\"", ")", "massOpts", ".", "add_argument", "(", "\"--min-eta\"", ",", "action", "=", "\"store\"", ",", "type", "=", "nonnegative_float", ",", "default", "=", "0.", ",", "help", "=", "\"Minimum symmetric mass ratio. OPTIONAL, no lower bound\"", "\" on eta will be imposed if not provided. \"", "\"UNITS=Solar mass.\"", ")", "massOpts", ".", "add_argument", "(", "\"--ns-eos\"", ",", "action", "=", "\"store\"", ",", "default", "=", "None", ",", "help", "=", "\"Select the EOS to be used for the NS when calculating \"", "\"the remnant disk mass. Only 2H is currently supported. \"", "\"OPTIONAL\"", ")", "massOpts", ".", "add_argument", "(", "\"--remnant-mass-threshold\"", ",", "action", "=", "\"store\"", ",", "type", "=", "nonnegative_float", ",", "default", "=", "None", ",", "help", "=", "\"Setting this filters EM dim NS-BH binaries: if the \"", "\"remnant disk mass does not exceed this value, the NS-BH \"", "\"binary is dropped from the target parameter space. \"", "\"When it is set to None (default value) the EM dim \"", "\"filter is not activated. OPTIONAL\"", ")", "massOpts", ".", "add_argument", "(", "\"--use-eos-max-ns-mass\"", ",", "action", "=", "\"store_true\"", ",", "default", "=", "False", ",", "help", "=", "\"Cut the mass range of the smaller object to the maximum \"", "\"mass allowed by EOS. \"", "\"OPTIONAL\"", ")", "massOpts", ".", "add_argument", "(", "\"--delta-bh-spin\"", ",", "action", "=", "\"store\"", ",", "type", "=", "positive_float", ",", "default", "=", "None", ",", "help", "=", "\"Grid spacing used for the BH spin z component when \"", "\"generating the surface of the minumum minimum symmetric \"", "\"mass ratio as a function of BH spin and NS mass required \"", "\"to produce a remnant disk mass that exceeds the threshold \"", "\"specificed in --remnant-mass-threshold. \"", "\"OPTIONAL (0.1 by default) \"", ")", "massOpts", ".", "add_argument", "(", "\"--delta-ns-mass\"", ",", "action", "=", "\"store\"", ",", "type", "=", "positive_float", ",", "default", "=", "None", ",", "help", "=", "\"Grid spacing used for the NS mass when generating the \"", "\"surface of the minumum minimum symmetric mass ratio as \"", "\"a function of BH spin and NS mass required to produce \"", "\"a remnant disk mass that exceeds the thrsehold specified \"", "\"in --remnant-mass-threshold. \"", "\"OPTIONAL (0.1 by default) \"", ")", "if", "nonSpin", ":", "parser", ".", "add_argument_group", "(", "massOpts", ")", "return", "massOpts", "massOpts", ".", "add_argument", "(", "\"--max-ns-spin-mag\"", ",", "action", "=", "\"store\"", ",", "type", "=", "nonnegative_float", ",", "default", "=", "None", ",", "help", "=", "\"Maximum neutron star spin magnitude. Neutron stars \"", "\"are defined as components lighter than the NS-BH \"", "\"boundary (3 Msun by default). REQUIRED if min-mass2 \"", "\"< ns-bh-boundary-mass\"", ")", "massOpts", ".", "add_argument", "(", "\"--max-bh-spin-mag\"", ",", "action", "=", "\"store\"", ",", "type", "=", "nonnegative_float", ",", "default", "=", "None", ",", "help", "=", "\"Maximum black hole spin magnitude. Black holes are \"", "\"defined as components at or above the NS-BH boundary \"", "\"(3 Msun by default). REQUIRED if max-mass1 >= \"", "\"ns-bh-boundary-mass\"", ")", "# Mutually exclusive group prevents both options being set on command line", "# If --nsbh-flag is True then spinning bank generation must ignore the", "# default value of ns-bh-boundary-mass.", "action", "=", "massOpts", ".", "add_mutually_exclusive_group", "(", "required", "=", "False", ")", "action", ".", "add_argument", "(", "\"--ns-bh-boundary-mass\"", ",", "action", "=", "'store'", ",", "type", "=", "positive_float", ",", "help", "=", "\"Mass boundary between neutron stars and black holes. \"", "\"Components below this mass are considered neutron \"", "\"stars and are subject to the neutron star spin limits. \"", "\"Components at/above are subject to the black hole spin \"", "\"limits. OPTIONAL, default=%f. UNITS=Solar mass\"", "%", "massRangeParameters", ".", "default_nsbh_boundary_mass", ")", "action", ".", "add_argument", "(", "\"--nsbh-flag\"", ",", "action", "=", "\"store_true\"", ",", "default", "=", "False", ",", "help", "=", "\"Set this flag if generating a bank that contains only \"", "\"systems with 1 black hole and 1 neutron star. With \"", "\"this flag set the heavier body will always be subject \"", "\"to the black hole spin restriction and the lighter \"", "\"to the neutron star spin restriction, regardless of \"", "\"mass. OPTIONAL. If set, the value of \"", "\"--ns-bh-boundary-mass will be ignored.\"", ")", "return", "massOpts" ]
https://github.com/gwastro/pycbc/blob/1e1c85534b9dba8488ce42df693230317ca63dea/pycbc/tmpltbank/option_utils.py#L420-L547
Georce/lepus
5b01bae82b5dc1df00c9e058989e2eb9b89ff333
lepus/pymongo-2.7/pymongo/mongo_client.py
python
MongoClient.copy_database
(self, from_name, to_name, from_host=None, username=None, password=None)
Copy a database, potentially from another host. Raises :class:`TypeError` if `from_name` or `to_name` is not an instance of :class:`basestring` (:class:`str` in python 3). Raises :class:`~pymongo.errors.InvalidName` if `to_name` is not a valid database name. If `from_host` is ``None`` the current host is used as the source. Otherwise the database is copied from `from_host`. If the source database requires authentication, `username` and `password` must be specified. :Parameters: - `from_name`: the name of the source database - `to_name`: the name of the target database - `from_host` (optional): host name to copy from - `username` (optional): username for source database - `password` (optional): password for source database .. note:: Specifying `username` and `password` requires server version **>= 1.3.3+**. .. versionadded:: 1.5
Copy a database, potentially from another host.
[ "Copy", "a", "database", "potentially", "from", "another", "host", "." ]
def copy_database(self, from_name, to_name, from_host=None, username=None, password=None): """Copy a database, potentially from another host. Raises :class:`TypeError` if `from_name` or `to_name` is not an instance of :class:`basestring` (:class:`str` in python 3). Raises :class:`~pymongo.errors.InvalidName` if `to_name` is not a valid database name. If `from_host` is ``None`` the current host is used as the source. Otherwise the database is copied from `from_host`. If the source database requires authentication, `username` and `password` must be specified. :Parameters: - `from_name`: the name of the source database - `to_name`: the name of the target database - `from_host` (optional): host name to copy from - `username` (optional): username for source database - `password` (optional): password for source database .. note:: Specifying `username` and `password` requires server version **>= 1.3.3+**. .. versionadded:: 1.5 """ if not isinstance(from_name, basestring): raise TypeError("from_name must be an instance " "of %s" % (basestring.__name__,)) if not isinstance(to_name, basestring): raise TypeError("to_name must be an instance " "of %s" % (basestring.__name__,)) database._check_name(to_name) command = {"fromdb": from_name, "todb": to_name} if from_host is not None: command["fromhost"] = from_host try: self.start_request() if username is not None: nonce = self.admin.command("copydbgetnonce", fromhost=from_host)["nonce"] command["username"] = username command["nonce"] = nonce command["key"] = auth._auth_key(nonce, username, password) return self.admin.command("copydb", **command) finally: self.end_request()
[ "def", "copy_database", "(", "self", ",", "from_name", ",", "to_name", ",", "from_host", "=", "None", ",", "username", "=", "None", ",", "password", "=", "None", ")", ":", "if", "not", "isinstance", "(", "from_name", ",", "basestring", ")", ":", "raise", "TypeError", "(", "\"from_name must be an instance \"", "\"of %s\"", "%", "(", "basestring", ".", "__name__", ",", ")", ")", "if", "not", "isinstance", "(", "to_name", ",", "basestring", ")", ":", "raise", "TypeError", "(", "\"to_name must be an instance \"", "\"of %s\"", "%", "(", "basestring", ".", "__name__", ",", ")", ")", "database", ".", "_check_name", "(", "to_name", ")", "command", "=", "{", "\"fromdb\"", ":", "from_name", ",", "\"todb\"", ":", "to_name", "}", "if", "from_host", "is", "not", "None", ":", "command", "[", "\"fromhost\"", "]", "=", "from_host", "try", ":", "self", ".", "start_request", "(", ")", "if", "username", "is", "not", "None", ":", "nonce", "=", "self", ".", "admin", ".", "command", "(", "\"copydbgetnonce\"", ",", "fromhost", "=", "from_host", ")", "[", "\"nonce\"", "]", "command", "[", "\"username\"", "]", "=", "username", "command", "[", "\"nonce\"", "]", "=", "nonce", "command", "[", "\"key\"", "]", "=", "auth", ".", "_auth_key", "(", "nonce", ",", "username", ",", "password", ")", "return", "self", ".", "admin", ".", "command", "(", "\"copydb\"", ",", "*", "*", "command", ")", "finally", ":", "self", ".", "end_request", "(", ")" ]
https://github.com/Georce/lepus/blob/5b01bae82b5dc1df00c9e058989e2eb9b89ff333/lepus/pymongo-2.7/pymongo/mongo_client.py#L1370-L1423
angr/angr
4b04d56ace135018083d36d9083805be8146688b
angr/knowledge_plugins/xrefs/xref.py
python
XRef.parse_from_cmessage
(cls, cmsg, bits=None, **kwargs)
return cr
[]
def parse_from_cmessage(cls, cmsg, bits=None, **kwargs): # pylint:disable=arguments-differ # Note that we cannot recover _memory_data from cmsg # delayed import from ...engines.light import SpOffset # pylint:disable=import-outside-toplevel if not isinstance(bits, int): raise TypeError("bits must be provided.") if cmsg.target_type == primitives_pb2.CodeReference.StackTarget: # pylint:disable=no-member dst = SpOffset(bits, cmsg.data_ea, is_base=False) else: dst = cmsg.data_ea cr = XRef(ins_addr=cmsg.ea, block_addr=cmsg.block_ea, stmt_idx=cmsg.stmt_idx, insn_op_idx=None if cmsg.operand_idx == -1 else cmsg.opearnd_idx, dst=dst, xref_type=cmsg.ref_type) return cr
[ "def", "parse_from_cmessage", "(", "cls", ",", "cmsg", ",", "bits", "=", "None", ",", "*", "*", "kwargs", ")", ":", "# pylint:disable=arguments-differ", "# Note that we cannot recover _memory_data from cmsg", "# delayed import", "from", ".", ".", ".", "engines", ".", "light", "import", "SpOffset", "# pylint:disable=import-outside-toplevel", "if", "not", "isinstance", "(", "bits", ",", "int", ")", ":", "raise", "TypeError", "(", "\"bits must be provided.\"", ")", "if", "cmsg", ".", "target_type", "==", "primitives_pb2", ".", "CodeReference", ".", "StackTarget", ":", "# pylint:disable=no-member", "dst", "=", "SpOffset", "(", "bits", ",", "cmsg", ".", "data_ea", ",", "is_base", "=", "False", ")", "else", ":", "dst", "=", "cmsg", ".", "data_ea", "cr", "=", "XRef", "(", "ins_addr", "=", "cmsg", ".", "ea", ",", "block_addr", "=", "cmsg", ".", "block_ea", ",", "stmt_idx", "=", "cmsg", ".", "stmt_idx", ",", "insn_op_idx", "=", "None", "if", "cmsg", ".", "operand_idx", "==", "-", "1", "else", "cmsg", ".", "opearnd_idx", ",", "dst", "=", "dst", ",", "xref_type", "=", "cmsg", ".", "ref_type", ")", "return", "cr" ]
https://github.com/angr/angr/blob/4b04d56ace135018083d36d9083805be8146688b/angr/knowledge_plugins/xrefs/xref.py#L96-L113
wxWidgets/Phoenix
b2199e299a6ca6d866aa6f3d0888499136ead9d6
wx/lib/agw/hypertreelist.py
python
HyperTreeList.AddColumn
(self, text, width=_DEFAULT_COL_WIDTH, flag=wx.ALIGN_LEFT, image=-1, shown=True, colour=None, edit=False)
Appends a column to the :class:`HyperTreeList`. :param `text`: the column text label; :param `width`: the column width in pixels; :param `flag`: the column alignment flag, one of ``wx.ALIGN_LEFT``, ``wx.ALIGN_RIGHT``, ``wx.ALIGN_CENTER``; :param `image`: an index within the normal image list assigned to :class:`HyperTreeList` specifying the image to use for the column; :param `shown`: ``True`` to show the column, ``False`` to hide it; :param `colour`: a valid :class:`wx.Colour`, representing the text foreground colour for the column; :param `edit`: ``True`` to set the column as editable, ``False`` otherwise.
Appends a column to the :class:`HyperTreeList`.
[ "Appends", "a", "column", "to", "the", ":", "class", ":", "HyperTreeList", "." ]
def AddColumn(self, text, width=_DEFAULT_COL_WIDTH, flag=wx.ALIGN_LEFT, image=-1, shown=True, colour=None, edit=False): """ Appends a column to the :class:`HyperTreeList`. :param `text`: the column text label; :param `width`: the column width in pixels; :param `flag`: the column alignment flag, one of ``wx.ALIGN_LEFT``, ``wx.ALIGN_RIGHT``, ``wx.ALIGN_CENTER``; :param `image`: an index within the normal image list assigned to :class:`HyperTreeList` specifying the image to use for the column; :param `shown`: ``True`` to show the column, ``False`` to hide it; :param `colour`: a valid :class:`wx.Colour`, representing the text foreground colour for the column; :param `edit`: ``True`` to set the column as editable, ``False`` otherwise. """ self._header_win.AddColumn(text, width, flag, image, shown, colour, edit) self.DoHeaderLayout()
[ "def", "AddColumn", "(", "self", ",", "text", ",", "width", "=", "_DEFAULT_COL_WIDTH", ",", "flag", "=", "wx", ".", "ALIGN_LEFT", ",", "image", "=", "-", "1", ",", "shown", "=", "True", ",", "colour", "=", "None", ",", "edit", "=", "False", ")", ":", "self", ".", "_header_win", ".", "AddColumn", "(", "text", ",", "width", ",", "flag", ",", "image", ",", "shown", ",", "colour", ",", "edit", ")", "self", ".", "DoHeaderLayout", "(", ")" ]
https://github.com/wxWidgets/Phoenix/blob/b2199e299a6ca6d866aa6f3d0888499136ead9d6/wx/lib/agw/hypertreelist.py#L4897-L4915
chipmuenk/pyfda
665310b8548a940a575c0e5ff4bba94608d9ac26
pyfda/input_widgets/input_coeffs.py
python
ItemDelegate.__init__
(self, parent)
Pass instance `parent` of parent class (Input_Coeffs)
Pass instance `parent` of parent class (Input_Coeffs)
[ "Pass", "instance", "parent", "of", "parent", "class", "(", "Input_Coeffs", ")" ]
def __init__(self, parent): """ Pass instance `parent` of parent class (Input_Coeffs) """ super(ItemDelegate, self).__init__(parent) self.parent = parent
[ "def", "__init__", "(", "self", ",", "parent", ")", ":", "super", "(", "ItemDelegate", ",", "self", ")", ".", "__init__", "(", "parent", ")", "self", ".", "parent", "=", "parent" ]
https://github.com/chipmuenk/pyfda/blob/665310b8548a940a575c0e5ff4bba94608d9ac26/pyfda/input_widgets/input_coeffs.py#L68-L73
TencentCloud/tencentcloud-sdk-python
3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2
tencentcloud/cii/v20210408/models.py
python
DescribeStructureTaskResultRequest.__init__
(self)
r""" :param MainTaskId: 结构化任务ID :type MainTaskId: str
r""" :param MainTaskId: 结构化任务ID :type MainTaskId: str
[ "r", ":", "param", "MainTaskId", ":", "结构化任务ID", ":", "type", "MainTaskId", ":", "str" ]
def __init__(self): r""" :param MainTaskId: 结构化任务ID :type MainTaskId: str """ self.MainTaskId = None
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "MainTaskId", "=", "None" ]
https://github.com/TencentCloud/tencentcloud-sdk-python/blob/3677fd1cdc8c5fd626ce001c13fd3b59d1f279d2/tencentcloud/cii/v20210408/models.py#L710-L715
taomujian/linbing
fe772a58f41e3b046b51a866bdb7e4655abaf51a
python/app/thirdparty/dirsearch/thirdparty/socks.py
python
wrap_module
(module)
Attempts to replace a module's socket library with a SOCKS socket. Must set a default proxy using set_default_proxy(...) first. This will only work on modules that import socket directly into the namespace; most of the Python Standard Library falls into this category.
Attempts to replace a module's socket library with a SOCKS socket.
[ "Attempts", "to", "replace", "a", "module", "s", "socket", "library", "with", "a", "SOCKS", "socket", "." ]
def wrap_module(module): """Attempts to replace a module's socket library with a SOCKS socket. Must set a default proxy using set_default_proxy(...) first. This will only work on modules that import socket directly into the namespace; most of the Python Standard Library falls into this category.""" if socksocket.default_proxy: module.socket.socket = socksocket else: raise GeneralProxyError("No default proxy specified")
[ "def", "wrap_module", "(", "module", ")", ":", "if", "socksocket", ".", "default_proxy", ":", "module", ".", "socket", ".", "socket", "=", "socksocket", "else", ":", "raise", "GeneralProxyError", "(", "\"No default proxy specified\"", ")" ]
https://github.com/taomujian/linbing/blob/fe772a58f41e3b046b51a866bdb7e4655abaf51a/python/app/thirdparty/dirsearch/thirdparty/socks.py#L139-L148
ranaroussi/pywallet
468622dcf993a27a5b585289b2724986c02a1fbc
pywallet/utils/ethereum.py
python
PublicKey.from_bytes
(key_bytes)
return PublicKey(x, y)
Generates a public key object from a byte (or hex) string. The byte stream must be of the SEC variety (http://www.secg.org/): beginning with a single byte telling what key representation follows. A full, uncompressed key is represented by: 0x04 followed by 64 bytes containing the x and y components of the point. For compressed keys with an even y component, 0x02 is followed by 32 bytes containing the x component. For compressed keys with an odd y component, 0x03 is followed by 32 bytes containing the x component. Args: key_bytes (bytes or str): A byte stream that conforms to the above. Returns: PublicKey: A PublicKey object.
Generates a public key object from a byte (or hex) string.
[ "Generates", "a", "public", "key", "object", "from", "a", "byte", "(", "or", "hex", ")", "string", "." ]
def from_bytes(key_bytes): """ Generates a public key object from a byte (or hex) string. The byte stream must be of the SEC variety (http://www.secg.org/): beginning with a single byte telling what key representation follows. A full, uncompressed key is represented by: 0x04 followed by 64 bytes containing the x and y components of the point. For compressed keys with an even y component, 0x02 is followed by 32 bytes containing the x component. For compressed keys with an odd y component, 0x03 is followed by 32 bytes containing the x component. Args: key_bytes (bytes or str): A byte stream that conforms to the above. Returns: PublicKey: A PublicKey object. """ b = get_bytes(key_bytes) key_bytes_len = len(b) key_type = b[0] if key_type == 0x04: # Uncompressed if key_bytes_len != 65: raise ValueError("key_bytes must be exactly 65 bytes long when uncompressed.") x = int.from_bytes(b[1:33], 'big') y = int.from_bytes(b[33:65], 'big') elif key_type == 0x02 or key_type == 0x03: if key_bytes_len != 33: raise ValueError("key_bytes must be exactly 33 bytes long when compressed.") x = int.from_bytes(b[1:33], 'big') ys = bitcoin_curve.y_from_x(x) # Pick the one that corresponds to key_type last_bit = key_type - 0x2 for y in ys: if y & 0x1 == last_bit: break else: return None return PublicKey(x, y)
[ "def", "from_bytes", "(", "key_bytes", ")", ":", "b", "=", "get_bytes", "(", "key_bytes", ")", "key_bytes_len", "=", "len", "(", "b", ")", "key_type", "=", "b", "[", "0", "]", "if", "key_type", "==", "0x04", ":", "# Uncompressed", "if", "key_bytes_len", "!=", "65", ":", "raise", "ValueError", "(", "\"key_bytes must be exactly 65 bytes long when uncompressed.\"", ")", "x", "=", "int", ".", "from_bytes", "(", "b", "[", "1", ":", "33", "]", ",", "'big'", ")", "y", "=", "int", ".", "from_bytes", "(", "b", "[", "33", ":", "65", "]", ",", "'big'", ")", "elif", "key_type", "==", "0x02", "or", "key_type", "==", "0x03", ":", "if", "key_bytes_len", "!=", "33", ":", "raise", "ValueError", "(", "\"key_bytes must be exactly 33 bytes long when compressed.\"", ")", "x", "=", "int", ".", "from_bytes", "(", "b", "[", "1", ":", "33", "]", ",", "'big'", ")", "ys", "=", "bitcoin_curve", ".", "y_from_x", "(", "x", ")", "# Pick the one that corresponds to key_type", "last_bit", "=", "key_type", "-", "0x2", "for", "y", "in", "ys", ":", "if", "y", "&", "0x1", "==", "last_bit", ":", "break", "else", ":", "return", "None", "return", "PublicKey", "(", "x", ",", "y", ")" ]
https://github.com/ranaroussi/pywallet/blob/468622dcf993a27a5b585289b2724986c02a1fbc/pywallet/utils/ethereum.py#L576-L621
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/combinat/designs/resolvable_bibd.py
python
kirkman_triple_system
(v,existence=False)
r""" Return a Kirkman Triple System on `v` points. A Kirkman Triple System `KTS(v)` is a resolvable Steiner Triple System. It exists if and only if `v\equiv 3\pmod{6}`. INPUT: - `n` (integer) - ``existence`` (boolean; ``False`` by default) -- whether to build the `KTS(n)` or only answer whether it exists. .. SEEALSO:: :meth:`IncidenceStructure.is_resolvable` EXAMPLES: A solution to Kirkmman's original problem:: sage: kts = designs.kirkman_triple_system(15) sage: classes = kts.is_resolvable(1)[1] sage: names = '0123456789abcde' sage: def to_name(r_s_t): ....: r, s, t = r_s_t ....: return ' ' + names[r] + names[s] + names[t] + ' ' sage: rows = [' '.join(('Day {}'.format(i) for i in range(1,8)))] sage: rows.extend(' '.join(map(to_name,row)) for row in zip(*classes)) sage: print('\n'.join(rows)) Day 1 Day 2 Day 3 Day 4 Day 5 Day 6 Day 7 07e 18e 29e 3ae 4be 5ce 6de 139 24a 35b 46c 05d 167 028 26b 03c 14d 257 368 049 15a 458 569 06a 01b 12c 23d 347 acd 7bd 78c 89d 79a 8ab 9bc TESTS:: sage: for i in range(3,300,6): ....: _ = designs.kirkman_triple_system(i)
r""" Return a Kirkman Triple System on `v` points.
[ "r", "Return", "a", "Kirkman", "Triple", "System", "on", "v", "points", "." ]
def kirkman_triple_system(v,existence=False): r""" Return a Kirkman Triple System on `v` points. A Kirkman Triple System `KTS(v)` is a resolvable Steiner Triple System. It exists if and only if `v\equiv 3\pmod{6}`. INPUT: - `n` (integer) - ``existence`` (boolean; ``False`` by default) -- whether to build the `KTS(n)` or only answer whether it exists. .. SEEALSO:: :meth:`IncidenceStructure.is_resolvable` EXAMPLES: A solution to Kirkmman's original problem:: sage: kts = designs.kirkman_triple_system(15) sage: classes = kts.is_resolvable(1)[1] sage: names = '0123456789abcde' sage: def to_name(r_s_t): ....: r, s, t = r_s_t ....: return ' ' + names[r] + names[s] + names[t] + ' ' sage: rows = [' '.join(('Day {}'.format(i) for i in range(1,8)))] sage: rows.extend(' '.join(map(to_name,row)) for row in zip(*classes)) sage: print('\n'.join(rows)) Day 1 Day 2 Day 3 Day 4 Day 5 Day 6 Day 7 07e 18e 29e 3ae 4be 5ce 6de 139 24a 35b 46c 05d 167 028 26b 03c 14d 257 368 049 15a 458 569 06a 01b 12c 23d 347 acd 7bd 78c 89d 79a 8ab 9bc TESTS:: sage: for i in range(3,300,6): ....: _ = designs.kirkman_triple_system(i) """ if v%6 != 3: if existence: return False raise ValueError("There is no KTS({}) as v!=3 mod(6)".format(v)) if existence: return False elif v == 3: return BalancedIncompleteBlockDesign(3,[[0,1,2]],k=3,lambd=1) elif v == 9: classes = [[[0, 1, 5], [2, 6, 7], [3, 4, 8]], [[1, 6, 8], [3, 5, 7], [0, 2, 4]], [[1, 4, 7], [0, 3, 6], [2, 5, 8]], [[4, 5, 6], [0, 7, 8], [1, 2, 3]]] KTS = BalancedIncompleteBlockDesign(v,[tr for cl in classes for tr in cl],k=3,lambd=1,copy=False) KTS._classes = classes return KTS # Construction 1.1 from [Stinson91] (originally Theorem 6 from [RCW71]) # # For all prime powers q=1 mod 6, there exists a KTS(2q+1) elif ((v-1)//2)%6 == 1 and is_prime_power((v-1)//2): from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF q = (v-1)//2 K = GF(q,'x') a = K.primitive_element() t = (q - 1) // 6 # m is the solution of a^m=(a^t+1)/2 from sage.groups.generic import discrete_log m = discrete_log((a**t+1)/2, a) assert 2*a**m == a**t+1 # First parallel class first_class = [[(0,1),(0,2),'inf']] b0 = K.one() b1 = a**t b2 = a**m first_class.extend([(b0*a**i,1),(b1*a**i,1),(b2*a**i,2)] for i in list(range(t))+list(range(2*t,3*t))+list(range(4*t,5*t))) b0 = a**(m+t) b1 = a**(m+3*t) b2 = a**(m+5*t) first_class.extend([[(b0*a**i,2),(b1*a**i,2),(b2*a**i,2)] for i in range(t)]) # Action of K on the points action = lambda v,x : (v+x[0],x[1]) if len(x) == 2 else x # relabel to integer relabel = {(p,x): i+(x-1)*q for i,p in enumerate(K) for x in [1,2]} relabel['inf'] = 2*q classes = [[[relabel[action(p,x)] for x in tr] for tr in first_class] for p in K] KTS = BalancedIncompleteBlockDesign(v,[tr for cl in classes for tr in cl],k=3,lambd=1,copy=False) KTS._classes = classes return KTS # Construction 1.2 from [Stinson91] (originally Theorem 5 from [RCW71]) # # For all prime powers q=1 mod 6, there exists a KTS(3q) elif (v//3)%6 == 1 and is_prime_power(v//3): from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF q = v//3 K = GF(q,'x') a = K.primitive_element() t = (q - 1) // 6 A0 = [(0,0),(0,1),(0,2)] B = [[(a**i,j),(a**(i+2*t),j),(a**(i+4*t),j)] for j in range(3) for i in range(t)] A = [[(a**i,0),(a**(i+2*t),1),(a**(i+4*t),2)] for i in range(6*t)] # Action of K on the points action = lambda v,x: (v+x[0],x[1]) # relabel to integer relabel = {(p,j): i+j*q for i,p in enumerate(K) for j in range(3)} B0 = [A0] + B + A[t:2*t] + A[3*t:4*t] + A[5*t:6*t] # Classes classes = [[[relabel[action(p,x)] for x in tr] for tr in B0] for p in K] for i in list(range(t))+list(range(2*t,3*t))+list(range(4*t,5*t)): classes.append([[relabel[action(p,x)] for x in A[i]] for p in K]) KTS = BalancedIncompleteBlockDesign(v,[tr for cl in classes for tr in cl],k=3,lambd=1,copy=False) KTS._classes = classes return KTS else: # This is Lemma IX.6.4 from [BJL99]. # # This construction takes a (v,{4,7})-PBD. All points are doubled (x has # a copy x'), and an infinite point \infty is added. # # On all blocks of 2*4 points we "paste" a KTS(2*4+1) using the infinite # point, in such a way that all {x,x',infty} are set of the design. We # do the same for blocks with 2*7 points using a KTS(2*7+1). # # Note that the triples of points equal to {x,x',\infty} will be added # several times. # # As all those subdesigns are resolvable, each class of the KTS(n) is # obtained by considering a set {x,x',\infty} and all sets of all # parallel classes of the subdesign which contain this set. # We create the small KTS(n') we need, and relabel them such that # 01(n'-1),23(n'-1),... are blocks of the design. gdd4 = kirkman_triple_system(9) gdd7 = kirkman_triple_system(15) X = [B for B in gdd4 if 8 in B] for b in X: b.remove(8) X = sum(X, []) + [8] gdd4.relabel({v:i for i,v in enumerate(X)}) gdd4 = gdd4.is_resolvable(True)[1] # the relabeled classes X = [B for B in gdd7 if 14 in B] for b in X: b.remove(14) X = sum(X, []) + [14] gdd7.relabel({v:i for i,v in enumerate(X)}) gdd7 = gdd7.is_resolvable(True)[1] # the relabeled classes # The first parallel class contains 01(n'-1), the second contains # 23(n'-1), etc.. # Then remove the blocks containing (n'-1) for B in gdd4: for i, b in enumerate(B): if 8 in b: j = min(b) del B[i] B.insert(0, j) break gdd4.sort() for B in gdd4: B.pop(0) for B in gdd7: for i, b in enumerate(B): if 14 in b: j = min(b) del B[i] B.insert(0, j) break gdd7.sort() for B in gdd7: B.pop(0) # Pasting the KTS(n') without {x,x',\infty} blocks classes = [[] for i in range((v-1) // 2)] gdd = {4:gdd4, 7: gdd7} for B in PBD_4_7((v-1)//2,check=False): for i,classs in enumerate(gdd[len(B)]): classes[B[i]].extend([[2*B[x//2]+x%2 for x in BB] for BB in classs]) # The {x,x',\infty} blocks for i,classs in enumerate(classes): classs.append([2*i,2*i+1,v-1]) KTS = BalancedIncompleteBlockDesign(v, blocks = [tr for cl in classes for tr in cl], k=3, lambd=1, check=True, copy=False) KTS._classes = classes assert KTS.is_resolvable() return KTS
[ "def", "kirkman_triple_system", "(", "v", ",", "existence", "=", "False", ")", ":", "if", "v", "%", "6", "!=", "3", ":", "if", "existence", ":", "return", "False", "raise", "ValueError", "(", "\"There is no KTS({}) as v!=3 mod(6)\"", ".", "format", "(", "v", ")", ")", "if", "existence", ":", "return", "False", "elif", "v", "==", "3", ":", "return", "BalancedIncompleteBlockDesign", "(", "3", ",", "[", "[", "0", ",", "1", ",", "2", "]", "]", ",", "k", "=", "3", ",", "lambd", "=", "1", ")", "elif", "v", "==", "9", ":", "classes", "=", "[", "[", "[", "0", ",", "1", ",", "5", "]", ",", "[", "2", ",", "6", ",", "7", "]", ",", "[", "3", ",", "4", ",", "8", "]", "]", ",", "[", "[", "1", ",", "6", ",", "8", "]", ",", "[", "3", ",", "5", ",", "7", "]", ",", "[", "0", ",", "2", ",", "4", "]", "]", ",", "[", "[", "1", ",", "4", ",", "7", "]", ",", "[", "0", ",", "3", ",", "6", "]", ",", "[", "2", ",", "5", ",", "8", "]", "]", ",", "[", "[", "4", ",", "5", ",", "6", "]", ",", "[", "0", ",", "7", ",", "8", "]", ",", "[", "1", ",", "2", ",", "3", "]", "]", "]", "KTS", "=", "BalancedIncompleteBlockDesign", "(", "v", ",", "[", "tr", "for", "cl", "in", "classes", "for", "tr", "in", "cl", "]", ",", "k", "=", "3", ",", "lambd", "=", "1", ",", "copy", "=", "False", ")", "KTS", ".", "_classes", "=", "classes", "return", "KTS", "# Construction 1.1 from [Stinson91] (originally Theorem 6 from [RCW71])", "#", "# For all prime powers q=1 mod 6, there exists a KTS(2q+1)", "elif", "(", "(", "v", "-", "1", ")", "//", "2", ")", "%", "6", "==", "1", "and", "is_prime_power", "(", "(", "v", "-", "1", ")", "//", "2", ")", ":", "from", "sage", ".", "rings", ".", "finite_rings", ".", "finite_field_constructor", "import", "FiniteField", "as", "GF", "q", "=", "(", "v", "-", "1", ")", "//", "2", "K", "=", "GF", "(", "q", ",", "'x'", ")", "a", "=", "K", ".", "primitive_element", "(", ")", "t", "=", "(", "q", "-", "1", ")", "//", "6", "# m is the solution of a^m=(a^t+1)/2", "from", "sage", ".", "groups", ".", "generic", "import", "discrete_log", "m", "=", "discrete_log", "(", "(", "a", "**", "t", "+", "1", ")", "/", "2", ",", "a", ")", "assert", "2", "*", "a", "**", "m", "==", "a", "**", "t", "+", "1", "# First parallel class", "first_class", "=", "[", "[", "(", "0", ",", "1", ")", ",", "(", "0", ",", "2", ")", ",", "'inf'", "]", "]", "b0", "=", "K", ".", "one", "(", ")", "b1", "=", "a", "**", "t", "b2", "=", "a", "**", "m", "first_class", ".", "extend", "(", "[", "(", "b0", "*", "a", "**", "i", ",", "1", ")", ",", "(", "b1", "*", "a", "**", "i", ",", "1", ")", ",", "(", "b2", "*", "a", "**", "i", ",", "2", ")", "]", "for", "i", "in", "list", "(", "range", "(", "t", ")", ")", "+", "list", "(", "range", "(", "2", "*", "t", ",", "3", "*", "t", ")", ")", "+", "list", "(", "range", "(", "4", "*", "t", ",", "5", "*", "t", ")", ")", ")", "b0", "=", "a", "**", "(", "m", "+", "t", ")", "b1", "=", "a", "**", "(", "m", "+", "3", "*", "t", ")", "b2", "=", "a", "**", "(", "m", "+", "5", "*", "t", ")", "first_class", ".", "extend", "(", "[", "[", "(", "b0", "*", "a", "**", "i", ",", "2", ")", ",", "(", "b1", "*", "a", "**", "i", ",", "2", ")", ",", "(", "b2", "*", "a", "**", "i", ",", "2", ")", "]", "for", "i", "in", "range", "(", "t", ")", "]", ")", "# Action of K on the points", "action", "=", "lambda", "v", ",", "x", ":", "(", "v", "+", "x", "[", "0", "]", ",", "x", "[", "1", "]", ")", "if", "len", "(", "x", ")", "==", "2", "else", "x", "# relabel to integer", "relabel", "=", "{", "(", "p", ",", "x", ")", ":", "i", "+", "(", "x", "-", "1", ")", "*", "q", "for", "i", ",", "p", "in", "enumerate", "(", "K", ")", "for", "x", "in", "[", "1", ",", "2", "]", "}", "relabel", "[", "'inf'", "]", "=", "2", "*", "q", "classes", "=", "[", "[", "[", "relabel", "[", "action", "(", "p", ",", "x", ")", "]", "for", "x", "in", "tr", "]", "for", "tr", "in", "first_class", "]", "for", "p", "in", "K", "]", "KTS", "=", "BalancedIncompleteBlockDesign", "(", "v", ",", "[", "tr", "for", "cl", "in", "classes", "for", "tr", "in", "cl", "]", ",", "k", "=", "3", ",", "lambd", "=", "1", ",", "copy", "=", "False", ")", "KTS", ".", "_classes", "=", "classes", "return", "KTS", "# Construction 1.2 from [Stinson91] (originally Theorem 5 from [RCW71])", "#", "# For all prime powers q=1 mod 6, there exists a KTS(3q)", "elif", "(", "v", "//", "3", ")", "%", "6", "==", "1", "and", "is_prime_power", "(", "v", "//", "3", ")", ":", "from", "sage", ".", "rings", ".", "finite_rings", ".", "finite_field_constructor", "import", "FiniteField", "as", "GF", "q", "=", "v", "//", "3", "K", "=", "GF", "(", "q", ",", "'x'", ")", "a", "=", "K", ".", "primitive_element", "(", ")", "t", "=", "(", "q", "-", "1", ")", "//", "6", "A0", "=", "[", "(", "0", ",", "0", ")", ",", "(", "0", ",", "1", ")", ",", "(", "0", ",", "2", ")", "]", "B", "=", "[", "[", "(", "a", "**", "i", ",", "j", ")", ",", "(", "a", "**", "(", "i", "+", "2", "*", "t", ")", ",", "j", ")", ",", "(", "a", "**", "(", "i", "+", "4", "*", "t", ")", ",", "j", ")", "]", "for", "j", "in", "range", "(", "3", ")", "for", "i", "in", "range", "(", "t", ")", "]", "A", "=", "[", "[", "(", "a", "**", "i", ",", "0", ")", ",", "(", "a", "**", "(", "i", "+", "2", "*", "t", ")", ",", "1", ")", ",", "(", "a", "**", "(", "i", "+", "4", "*", "t", ")", ",", "2", ")", "]", "for", "i", "in", "range", "(", "6", "*", "t", ")", "]", "# Action of K on the points", "action", "=", "lambda", "v", ",", "x", ":", "(", "v", "+", "x", "[", "0", "]", ",", "x", "[", "1", "]", ")", "# relabel to integer", "relabel", "=", "{", "(", "p", ",", "j", ")", ":", "i", "+", "j", "*", "q", "for", "i", ",", "p", "in", "enumerate", "(", "K", ")", "for", "j", "in", "range", "(", "3", ")", "}", "B0", "=", "[", "A0", "]", "+", "B", "+", "A", "[", "t", ":", "2", "*", "t", "]", "+", "A", "[", "3", "*", "t", ":", "4", "*", "t", "]", "+", "A", "[", "5", "*", "t", ":", "6", "*", "t", "]", "# Classes", "classes", "=", "[", "[", "[", "relabel", "[", "action", "(", "p", ",", "x", ")", "]", "for", "x", "in", "tr", "]", "for", "tr", "in", "B0", "]", "for", "p", "in", "K", "]", "for", "i", "in", "list", "(", "range", "(", "t", ")", ")", "+", "list", "(", "range", "(", "2", "*", "t", ",", "3", "*", "t", ")", ")", "+", "list", "(", "range", "(", "4", "*", "t", ",", "5", "*", "t", ")", ")", ":", "classes", ".", "append", "(", "[", "[", "relabel", "[", "action", "(", "p", ",", "x", ")", "]", "for", "x", "in", "A", "[", "i", "]", "]", "for", "p", "in", "K", "]", ")", "KTS", "=", "BalancedIncompleteBlockDesign", "(", "v", ",", "[", "tr", "for", "cl", "in", "classes", "for", "tr", "in", "cl", "]", ",", "k", "=", "3", ",", "lambd", "=", "1", ",", "copy", "=", "False", ")", "KTS", ".", "_classes", "=", "classes", "return", "KTS", "else", ":", "# This is Lemma IX.6.4 from [BJL99].", "#", "# This construction takes a (v,{4,7})-PBD. All points are doubled (x has", "# a copy x'), and an infinite point \\infty is added.", "#", "# On all blocks of 2*4 points we \"paste\" a KTS(2*4+1) using the infinite", "# point, in such a way that all {x,x',infty} are set of the design. We", "# do the same for blocks with 2*7 points using a KTS(2*7+1).", "#", "# Note that the triples of points equal to {x,x',\\infty} will be added", "# several times.", "#", "# As all those subdesigns are resolvable, each class of the KTS(n) is", "# obtained by considering a set {x,x',\\infty} and all sets of all", "# parallel classes of the subdesign which contain this set.", "# We create the small KTS(n') we need, and relabel them such that", "# 01(n'-1),23(n'-1),... are blocks of the design.", "gdd4", "=", "kirkman_triple_system", "(", "9", ")", "gdd7", "=", "kirkman_triple_system", "(", "15", ")", "X", "=", "[", "B", "for", "B", "in", "gdd4", "if", "8", "in", "B", "]", "for", "b", "in", "X", ":", "b", ".", "remove", "(", "8", ")", "X", "=", "sum", "(", "X", ",", "[", "]", ")", "+", "[", "8", "]", "gdd4", ".", "relabel", "(", "{", "v", ":", "i", "for", "i", ",", "v", "in", "enumerate", "(", "X", ")", "}", ")", "gdd4", "=", "gdd4", ".", "is_resolvable", "(", "True", ")", "[", "1", "]", "# the relabeled classes", "X", "=", "[", "B", "for", "B", "in", "gdd7", "if", "14", "in", "B", "]", "for", "b", "in", "X", ":", "b", ".", "remove", "(", "14", ")", "X", "=", "sum", "(", "X", ",", "[", "]", ")", "+", "[", "14", "]", "gdd7", ".", "relabel", "(", "{", "v", ":", "i", "for", "i", ",", "v", "in", "enumerate", "(", "X", ")", "}", ")", "gdd7", "=", "gdd7", ".", "is_resolvable", "(", "True", ")", "[", "1", "]", "# the relabeled classes", "# The first parallel class contains 01(n'-1), the second contains", "# 23(n'-1), etc..", "# Then remove the blocks containing (n'-1)", "for", "B", "in", "gdd4", ":", "for", "i", ",", "b", "in", "enumerate", "(", "B", ")", ":", "if", "8", "in", "b", ":", "j", "=", "min", "(", "b", ")", "del", "B", "[", "i", "]", "B", ".", "insert", "(", "0", ",", "j", ")", "break", "gdd4", ".", "sort", "(", ")", "for", "B", "in", "gdd4", ":", "B", ".", "pop", "(", "0", ")", "for", "B", "in", "gdd7", ":", "for", "i", ",", "b", "in", "enumerate", "(", "B", ")", ":", "if", "14", "in", "b", ":", "j", "=", "min", "(", "b", ")", "del", "B", "[", "i", "]", "B", ".", "insert", "(", "0", ",", "j", ")", "break", "gdd7", ".", "sort", "(", ")", "for", "B", "in", "gdd7", ":", "B", ".", "pop", "(", "0", ")", "# Pasting the KTS(n') without {x,x',\\infty} blocks", "classes", "=", "[", "[", "]", "for", "i", "in", "range", "(", "(", "v", "-", "1", ")", "//", "2", ")", "]", "gdd", "=", "{", "4", ":", "gdd4", ",", "7", ":", "gdd7", "}", "for", "B", "in", "PBD_4_7", "(", "(", "v", "-", "1", ")", "//", "2", ",", "check", "=", "False", ")", ":", "for", "i", ",", "classs", "in", "enumerate", "(", "gdd", "[", "len", "(", "B", ")", "]", ")", ":", "classes", "[", "B", "[", "i", "]", "]", ".", "extend", "(", "[", "[", "2", "*", "B", "[", "x", "//", "2", "]", "+", "x", "%", "2", "for", "x", "in", "BB", "]", "for", "BB", "in", "classs", "]", ")", "# The {x,x',\\infty} blocks", "for", "i", ",", "classs", "in", "enumerate", "(", "classes", ")", ":", "classs", ".", "append", "(", "[", "2", "*", "i", ",", "2", "*", "i", "+", "1", ",", "v", "-", "1", "]", ")", "KTS", "=", "BalancedIncompleteBlockDesign", "(", "v", ",", "blocks", "=", "[", "tr", "for", "cl", "in", "classes", "for", "tr", "in", "cl", "]", ",", "k", "=", "3", ",", "lambd", "=", "1", ",", "check", "=", "True", ",", "copy", "=", "False", ")", "KTS", ".", "_classes", "=", "classes", "assert", "KTS", ".", "is_resolvable", "(", ")", "return", "KTS" ]
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/combinat/designs/resolvable_bibd.py#L141-L365
modflowpy/flopy
eecd1ad193c5972093c9712e5c4b7a83284f0688
flopy/utils/zonbud.py
python
ZoneBudget.read_zone_file
(cls, fname)
return zones
Method to read a zonebudget zone file into memory Parameters ---------- fname : str zone file name Returns ------- zones : np.array
Method to read a zonebudget zone file into memory
[ "Method", "to", "read", "a", "zonebudget", "zone", "file", "into", "memory" ]
def read_zone_file(cls, fname): """Method to read a zonebudget zone file into memory Parameters ---------- fname : str zone file name Returns ------- zones : np.array """ with open(fname, "r") as f: lines = f.readlines() # Initialize layer lay = 0 # Initialize data counter totlen = 0 i = 0 # First line contains array dimensions dimstring = lines.pop(0).strip().split() nlay, nrow, ncol = [int(v) for v in dimstring] zones = np.zeros((nlay, nrow, ncol), dtype=np.int32) # The number of values to read before placing # them into the zone array datalen = nrow * ncol # List of valid values for LOCAT locats = ["CONSTANT", "INTERNAL", "EXTERNAL"] # ITERATE OVER THE ROWS for line in lines: rowitems = line.strip().split() # Skip blank lines if len(rowitems) == 0: continue # HEADER if rowitems[0].upper() in locats: vals = [] locat = rowitems[0].upper() if locat == "CONSTANT": iconst = int(rowitems[1]) else: fmt = rowitems[1].strip("()") fmtin, iprn = [int(v) for v in fmt.split("I")] # ZONE DATA else: if locat == "CONSTANT": vals = np.ones((nrow, ncol), dtype=int) * iconst lay += 1 elif locat == "INTERNAL": # READ ZONES rowvals = [int(v) for v in rowitems] s = "Too many values encountered on this line." assert len(rowvals) <= fmtin, s vals.extend(rowvals) elif locat == "EXTERNAL": # READ EXTERNAL FILE fname = rowitems[0] if not os.path.isfile(fname): errmsg = f'Could not find external file "{fname}"' raise Exception(errmsg) with open(fname, "r") as ext_f: ext_flines = ext_f.readlines() for ext_frow in ext_flines: ext_frowitems = ext_frow.strip().split() rowvals = [int(v) for v in ext_frowitems] vals.extend(rowvals) if len(vals) != datalen: errmsg = ( "The number of values read from external " 'file "{}" does not match the expected ' "number.".format(len(vals)) ) raise Exception(errmsg) else: # Should not get here raise Exception(f"Locat not recognized: {locat}") # IGNORE COMPOSITE ZONES if len(vals) == datalen: # place values for the previous layer into the zone array vals = np.array(vals, dtype=int).reshape((nrow, ncol)) zones[lay, :, :] = vals[:, :] lay += 1 totlen += len(rowitems) i += 1 s = ( "The number of values read ({:,.0f})" " does not match the number expected" " ({:,.0f})".format(totlen, nlay * nrow * ncol) ) assert totlen == nlay * nrow * ncol, s return zones
[ "def", "read_zone_file", "(", "cls", ",", "fname", ")", ":", "with", "open", "(", "fname", ",", "\"r\"", ")", "as", "f", ":", "lines", "=", "f", ".", "readlines", "(", ")", "# Initialize layer", "lay", "=", "0", "# Initialize data counter", "totlen", "=", "0", "i", "=", "0", "# First line contains array dimensions", "dimstring", "=", "lines", ".", "pop", "(", "0", ")", ".", "strip", "(", ")", ".", "split", "(", ")", "nlay", ",", "nrow", ",", "ncol", "=", "[", "int", "(", "v", ")", "for", "v", "in", "dimstring", "]", "zones", "=", "np", ".", "zeros", "(", "(", "nlay", ",", "nrow", ",", "ncol", ")", ",", "dtype", "=", "np", ".", "int32", ")", "# The number of values to read before placing", "# them into the zone array", "datalen", "=", "nrow", "*", "ncol", "# List of valid values for LOCAT", "locats", "=", "[", "\"CONSTANT\"", ",", "\"INTERNAL\"", ",", "\"EXTERNAL\"", "]", "# ITERATE OVER THE ROWS", "for", "line", "in", "lines", ":", "rowitems", "=", "line", ".", "strip", "(", ")", ".", "split", "(", ")", "# Skip blank lines", "if", "len", "(", "rowitems", ")", "==", "0", ":", "continue", "# HEADER", "if", "rowitems", "[", "0", "]", ".", "upper", "(", ")", "in", "locats", ":", "vals", "=", "[", "]", "locat", "=", "rowitems", "[", "0", "]", ".", "upper", "(", ")", "if", "locat", "==", "\"CONSTANT\"", ":", "iconst", "=", "int", "(", "rowitems", "[", "1", "]", ")", "else", ":", "fmt", "=", "rowitems", "[", "1", "]", ".", "strip", "(", "\"()\"", ")", "fmtin", ",", "iprn", "=", "[", "int", "(", "v", ")", "for", "v", "in", "fmt", ".", "split", "(", "\"I\"", ")", "]", "# ZONE DATA", "else", ":", "if", "locat", "==", "\"CONSTANT\"", ":", "vals", "=", "np", ".", "ones", "(", "(", "nrow", ",", "ncol", ")", ",", "dtype", "=", "int", ")", "*", "iconst", "lay", "+=", "1", "elif", "locat", "==", "\"INTERNAL\"", ":", "# READ ZONES", "rowvals", "=", "[", "int", "(", "v", ")", "for", "v", "in", "rowitems", "]", "s", "=", "\"Too many values encountered on this line.\"", "assert", "len", "(", "rowvals", ")", "<=", "fmtin", ",", "s", "vals", ".", "extend", "(", "rowvals", ")", "elif", "locat", "==", "\"EXTERNAL\"", ":", "# READ EXTERNAL FILE", "fname", "=", "rowitems", "[", "0", "]", "if", "not", "os", ".", "path", ".", "isfile", "(", "fname", ")", ":", "errmsg", "=", "f'Could not find external file \"{fname}\"'", "raise", "Exception", "(", "errmsg", ")", "with", "open", "(", "fname", ",", "\"r\"", ")", "as", "ext_f", ":", "ext_flines", "=", "ext_f", ".", "readlines", "(", ")", "for", "ext_frow", "in", "ext_flines", ":", "ext_frowitems", "=", "ext_frow", ".", "strip", "(", ")", ".", "split", "(", ")", "rowvals", "=", "[", "int", "(", "v", ")", "for", "v", "in", "ext_frowitems", "]", "vals", ".", "extend", "(", "rowvals", ")", "if", "len", "(", "vals", ")", "!=", "datalen", ":", "errmsg", "=", "(", "\"The number of values read from external \"", "'file \"{}\" does not match the expected '", "\"number.\"", ".", "format", "(", "len", "(", "vals", ")", ")", ")", "raise", "Exception", "(", "errmsg", ")", "else", ":", "# Should not get here", "raise", "Exception", "(", "f\"Locat not recognized: {locat}\"", ")", "# IGNORE COMPOSITE ZONES", "if", "len", "(", "vals", ")", "==", "datalen", ":", "# place values for the previous layer into the zone array", "vals", "=", "np", ".", "array", "(", "vals", ",", "dtype", "=", "int", ")", ".", "reshape", "(", "(", "nrow", ",", "ncol", ")", ")", "zones", "[", "lay", ",", ":", ",", ":", "]", "=", "vals", "[", ":", ",", ":", "]", "lay", "+=", "1", "totlen", "+=", "len", "(", "rowitems", ")", "i", "+=", "1", "s", "=", "(", "\"The number of values read ({:,.0f})\"", "\" does not match the number expected\"", "\" ({:,.0f})\"", ".", "format", "(", "totlen", ",", "nlay", "*", "nrow", "*", "ncol", ")", ")", "assert", "totlen", "==", "nlay", "*", "nrow", "*", "ncol", ",", "s", "return", "zones" ]
https://github.com/modflowpy/flopy/blob/eecd1ad193c5972093c9712e5c4b7a83284f0688/flopy/utils/zonbud.py#L1444-L1548
openstack/magnum
fa298eeab19b1d87070d72c7c4fb26cd75b0781e
magnum/api/controllers/v1/cluster_actions.py
python
ActionsController.resize
(self, cluster_ident, cluster_resize_req)
return self._resize(cluster_ident, cluster_resize_req)
[]
def resize(self, cluster_ident, cluster_resize_req): if cluster_resize_req.node_count == 0: raise exception.ZeroNodeCountNotSupported() return self._resize(cluster_ident, cluster_resize_req)
[ "def", "resize", "(", "self", ",", "cluster_ident", ",", "cluster_resize_req", ")", ":", "if", "cluster_resize_req", ".", "node_count", "==", "0", ":", "raise", "exception", ".", "ZeroNodeCountNotSupported", "(", ")", "return", "self", ".", "_resize", "(", "cluster_ident", ",", "cluster_resize_req", ")" ]
https://github.com/openstack/magnum/blob/fa298eeab19b1d87070d72c7c4fb26cd75b0781e/magnum/api/controllers/v1/cluster_actions.py#L87-L90
DataBrewery/cubes
140133e8c2e3f2ff60631cc3ebc9966d16c1655e
cubes/mapper.py
python
Mapper.split_logical
(self, reference)
Returns tuple (`dimension`, `attribute`) from `logical_reference` string. Syntax of the string is: ``dimensions.attribute``.
Returns tuple (`dimension`, `attribute`) from `logical_reference` string. Syntax of the string is: ``dimensions.attribute``.
[ "Returns", "tuple", "(", "dimension", "attribute", ")", "from", "logical_reference", "string", ".", "Syntax", "of", "the", "string", "is", ":", "dimensions", ".", "attribute", "." ]
def split_logical(self, reference): """Returns tuple (`dimension`, `attribute`) from `logical_reference` string. Syntax of the string is: ``dimensions.attribute``.""" split = reference.split(".") if len(split) > 1: dim_name = split[0] attr_name = ".".join(split[1:]) return (dim_name, attr_name) else: return (None, reference)
[ "def", "split_logical", "(", "self", ",", "reference", ")", ":", "split", "=", "reference", ".", "split", "(", "\".\"", ")", "if", "len", "(", "split", ")", ">", "1", ":", "dim_name", "=", "split", "[", "0", "]", "attr_name", "=", "\".\"", ".", "join", "(", "split", "[", "1", ":", "]", ")", "return", "(", "dim_name", ",", "attr_name", ")", "else", ":", "return", "(", "None", ",", "reference", ")" ]
https://github.com/DataBrewery/cubes/blob/140133e8c2e3f2ff60631cc3ebc9966d16c1655e/cubes/mapper.py#L97-L108
alexMyG/AndroPyTool
e0412677c9602a8000339f119e758a360db18a80
FlowDroid/flowDroid/launchFlowDroidMod.py
python
create_logger
(log_filename)
return logger
[]
def create_logger(log_filename): logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) # create a file handler handler = logging.FileHandler(log_filename) handler.setLevel(logging.INFO) # create a logging format formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) # add the handlers to the logger logger.addHandler(handler) return logger
[ "def", "create_logger", "(", "log_filename", ")", ":", "logger", "=", "logging", ".", "getLogger", "(", "__name__", ")", "logger", ".", "setLevel", "(", "logging", ".", "INFO", ")", "# create a file handler", "handler", "=", "logging", ".", "FileHandler", "(", "log_filename", ")", "handler", ".", "setLevel", "(", "logging", ".", "INFO", ")", "# create a logging format", "formatter", "=", "logging", ".", "Formatter", "(", "'%(asctime)s - %(name)s - %(levelname)s - %(message)s'", ")", "handler", ".", "setFormatter", "(", "formatter", ")", "# add the handlers to the logger", "logger", ".", "addHandler", "(", "handler", ")", "return", "logger" ]
https://github.com/alexMyG/AndroPyTool/blob/e0412677c9602a8000339f119e758a360db18a80/FlowDroid/flowDroid/launchFlowDroidMod.py#L271-L290
google/clusterfuzz
f358af24f414daa17a3649b143e71ea71871ef59
src/appengine/handlers/cron/project_setup.py
python
_set_bucket_service_account
(service_account, client, bucket_name, iam_policy)
return storage.set_bucket_iam_policy(client, bucket_name, iam_policy)
Set service account for a bucket.
Set service account for a bucket.
[ "Set", "service", "account", "for", "a", "bucket", "." ]
def _set_bucket_service_account(service_account, client, bucket_name, iam_policy): """Set service account for a bucket.""" # Add service account as objectAdmin. binding = storage.get_or_create_bucket_iam_binding(iam_policy, OBJECT_ADMIN_IAM_ROLE) members = ['serviceAccount:' + service_account['email']] if members == binding['members']: # No changes required. return iam_policy binding['members'] = members return storage.set_bucket_iam_policy(client, bucket_name, iam_policy)
[ "def", "_set_bucket_service_account", "(", "service_account", ",", "client", ",", "bucket_name", ",", "iam_policy", ")", ":", "# Add service account as objectAdmin.", "binding", "=", "storage", ".", "get_or_create_bucket_iam_binding", "(", "iam_policy", ",", "OBJECT_ADMIN_IAM_ROLE", ")", "members", "=", "[", "'serviceAccount:'", "+", "service_account", "[", "'email'", "]", "]", "if", "members", "==", "binding", "[", "'members'", "]", ":", "# No changes required.", "return", "iam_policy", "binding", "[", "'members'", "]", "=", "members", "return", "storage", ".", "set_bucket_iam_policy", "(", "client", ",", "bucket_name", ",", "iam_policy", ")" ]
https://github.com/google/clusterfuzz/blob/f358af24f414daa17a3649b143e71ea71871ef59/src/appengine/handlers/cron/project_setup.py#L370-L383
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_hxb2/lib/python3.5/site-packages/wheel/decorator.py
python
reify.__get__
(self, inst, objtype=None)
return val
[]
def __get__(self, inst, objtype=None): if inst is None: return self val = self.wrapped(inst) setattr(inst, self.wrapped.__name__, val) return val
[ "def", "__get__", "(", "self", ",", "inst", ",", "objtype", "=", "None", ")", ":", "if", "inst", "is", "None", ":", "return", "self", "val", "=", "self", ".", "wrapped", "(", "inst", ")", "setattr", "(", "inst", ",", "self", ".", "wrapped", ".", "__name__", ",", "val", ")", "return", "val" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_hxb2/lib/python3.5/site-packages/wheel/decorator.py#L14-L19
timonwong/OmniMarkupPreviewer
21921ac7a99d2b5924a2219b33679a5b53621392
OmniMarkupLib/Renderers/libs/python2/docutils/utils/math/math2html.py
python
ParameterFunction.paramdefs
(self, readtemplate)
Read each param definition in the template
Read each param definition in the template
[ "Read", "each", "param", "definition", "in", "the", "template" ]
def paramdefs(self, readtemplate): "Read each param definition in the template" pos = TextPosition(readtemplate) while not pos.finished(): paramdef = ParameterDefinition().parse(pos) if paramdef: yield paramdef
[ "def", "paramdefs", "(", "self", ",", "readtemplate", ")", ":", "pos", "=", "TextPosition", "(", "readtemplate", ")", "while", "not", "pos", ".", "finished", "(", ")", ":", "paramdef", "=", "ParameterDefinition", "(", ")", ".", "parse", "(", "pos", ")", "if", "paramdef", ":", "yield", "paramdef" ]
https://github.com/timonwong/OmniMarkupPreviewer/blob/21921ac7a99d2b5924a2219b33679a5b53621392/OmniMarkupLib/Renderers/libs/python2/docutils/utils/math/math2html.py#L4780-L4786
mitogen-hq/mitogen
5b505f524a7ae170fe68613841ab92b299613d3f
ansible_mitogen/runner.py
python
NewStyleRunner._get_module_package
(self)
return pkg.encode()
Since Ansible 2.9 __package__ must be set in accordance with an approximation of the original package hierarchy, so that relative imports function correctly.
Since Ansible 2.9 __package__ must be set in accordance with an approximation of the original package hierarchy, so that relative imports function correctly.
[ "Since", "Ansible", "2", ".", "9", "__package__", "must", "be", "set", "in", "accordance", "with", "an", "approximation", "of", "the", "original", "package", "hierarchy", "so", "that", "relative", "imports", "function", "correctly", "." ]
def _get_module_package(self): """ Since Ansible 2.9 __package__ must be set in accordance with an approximation of the original package hierarchy, so that relative imports function correctly. """ pkg, sep, modname = str_rpartition(self.py_module_name, '.') if not sep: return None if mitogen.core.PY3: return pkg return pkg.encode()
[ "def", "_get_module_package", "(", "self", ")", ":", "pkg", ",", "sep", ",", "modname", "=", "str_rpartition", "(", "self", ".", "py_module_name", ",", "'.'", ")", "if", "not", "sep", ":", "return", "None", "if", "mitogen", ".", "core", ".", "PY3", ":", "return", "pkg", "return", "pkg", ".", "encode", "(", ")" ]
https://github.com/mitogen-hq/mitogen/blob/5b505f524a7ae170fe68613841ab92b299613d3f/ansible_mitogen/runner.py#L946-L957
allegroai/clearml
5953dc6eefadcdfcc2bdbb6a0da32be58823a5af
clearml/automation/controller.py
python
PipelineController._serialize_pipeline_task
(self)
return params, pipeline_dag
Serialize current pipeline state into the main Task :return: params, pipeline_dag
Serialize current pipeline state into the main Task
[ "Serialize", "current", "pipeline", "state", "into", "the", "main", "Task" ]
def _serialize_pipeline_task(self): # type: () -> (dict, dict) """ Serialize current pipeline state into the main Task :return: params, pipeline_dag """ params = { '_default_queue_': self._default_execution_queue, '_add_pipeline_tags_': self._add_pipeline_tags, '_target_project_': self._target_project, } pipeline_dag = self._serialize() # serialize pipeline state if self._task and self._auto_connect_task: if self._task.running_locally(): # noinspection PyProtectedMember self._task._set_configuration( name=self._config_section, config_type='dictionary', config_text=json.dumps(pipeline_dag, indent=2)) params.update(flatten_dictionary(self._pipeline_args)) # noinspection PyProtectedMember self._task._set_parameters( {'{}/{}'.format(self._args_section, k): v for k, v in params.items()}, __parameters_descriptions=self._pipeline_args_desc, __parameters_types=self._pipeline_args_type, __update=True, ) params['_continue_pipeline_'] = False # make sure we have a unique version number (auto bump version if needed) # only needed when manually (from code) creating pipelines self._verify_pipeline_version() # noinspection PyProtectedMember pipeline_hash = self._get_task_hash() # noinspection PyProtectedMember self._task._set_runtime_properties({ self._runtime_property_hash: "{}:{}".format(pipeline_hash, self._version), }) else: self._task.connect_configuration(pipeline_dag, name=self._config_section) self._task.connect(self._pipeline_args, name=self._args_section) self._task.connect(params, name=self._args_section) # noinspection PyProtectedMember if self._task._get_runtime_properties().get(self._runtime_property_hash): params['_continue_pipeline_'] = True else: # noinspection PyProtectedMember pipeline_hash = ClearmlJob._create_task_hash(self._task) # noinspection PyProtectedMember self._task._set_runtime_properties({ self._runtime_property_hash: "{}:{}".format(pipeline_hash, self._version), }) params['_continue_pipeline_'] = False return params, pipeline_dag
[ "def", "_serialize_pipeline_task", "(", "self", ")", ":", "# type: () -> (dict, dict)", "params", "=", "{", "'_default_queue_'", ":", "self", ".", "_default_execution_queue", ",", "'_add_pipeline_tags_'", ":", "self", ".", "_add_pipeline_tags", ",", "'_target_project_'", ":", "self", ".", "_target_project", ",", "}", "pipeline_dag", "=", "self", ".", "_serialize", "(", ")", "# serialize pipeline state", "if", "self", ".", "_task", "and", "self", ".", "_auto_connect_task", ":", "if", "self", ".", "_task", ".", "running_locally", "(", ")", ":", "# noinspection PyProtectedMember", "self", ".", "_task", ".", "_set_configuration", "(", "name", "=", "self", ".", "_config_section", ",", "config_type", "=", "'dictionary'", ",", "config_text", "=", "json", ".", "dumps", "(", "pipeline_dag", ",", "indent", "=", "2", ")", ")", "params", ".", "update", "(", "flatten_dictionary", "(", "self", ".", "_pipeline_args", ")", ")", "# noinspection PyProtectedMember", "self", ".", "_task", ".", "_set_parameters", "(", "{", "'{}/{}'", ".", "format", "(", "self", ".", "_args_section", ",", "k", ")", ":", "v", "for", "k", ",", "v", "in", "params", ".", "items", "(", ")", "}", ",", "__parameters_descriptions", "=", "self", ".", "_pipeline_args_desc", ",", "__parameters_types", "=", "self", ".", "_pipeline_args_type", ",", "__update", "=", "True", ",", ")", "params", "[", "'_continue_pipeline_'", "]", "=", "False", "# make sure we have a unique version number (auto bump version if needed)", "# only needed when manually (from code) creating pipelines", "self", ".", "_verify_pipeline_version", "(", ")", "# noinspection PyProtectedMember", "pipeline_hash", "=", "self", ".", "_get_task_hash", "(", ")", "# noinspection PyProtectedMember", "self", ".", "_task", ".", "_set_runtime_properties", "(", "{", "self", ".", "_runtime_property_hash", ":", "\"{}:{}\"", ".", "format", "(", "pipeline_hash", ",", "self", ".", "_version", ")", ",", "}", ")", "else", ":", "self", ".", "_task", ".", "connect_configuration", "(", "pipeline_dag", ",", "name", "=", "self", ".", "_config_section", ")", "self", ".", "_task", ".", "connect", "(", "self", ".", "_pipeline_args", ",", "name", "=", "self", ".", "_args_section", ")", "self", ".", "_task", ".", "connect", "(", "params", ",", "name", "=", "self", ".", "_args_section", ")", "# noinspection PyProtectedMember", "if", "self", ".", "_task", ".", "_get_runtime_properties", "(", ")", ".", "get", "(", "self", ".", "_runtime_property_hash", ")", ":", "params", "[", "'_continue_pipeline_'", "]", "=", "True", "else", ":", "# noinspection PyProtectedMember", "pipeline_hash", "=", "ClearmlJob", ".", "_create_task_hash", "(", "self", ".", "_task", ")", "# noinspection PyProtectedMember", "self", ".", "_task", ".", "_set_runtime_properties", "(", "{", "self", ".", "_runtime_property_hash", ":", "\"{}:{}\"", ".", "format", "(", "pipeline_hash", ",", "self", ".", "_version", ")", ",", "}", ")", "params", "[", "'_continue_pipeline_'", "]", "=", "False", "return", "params", ",", "pipeline_dag" ]
https://github.com/allegroai/clearml/blob/5953dc6eefadcdfcc2bdbb6a0da32be58823a5af/clearml/automation/controller.py#L1131-L1189
datalad/datalad
d8c8383d878a207bb586415314219a60c345f732
datalad/support/archives.py
python
_get_random_id
(size=6, chars=string.ascii_uppercase + string.digits)
return ''.join(random.choice(chars) for _ in range(size))
Return a random ID composed from digits and uppercase letters upper-case so we are tolerant to unlikely collisions on dummy FSs
Return a random ID composed from digits and uppercase letters
[ "Return", "a", "random", "ID", "composed", "from", "digits", "and", "uppercase", "letters" ]
def _get_random_id(size=6, chars=string.ascii_uppercase + string.digits): """Return a random ID composed from digits and uppercase letters upper-case so we are tolerant to unlikely collisions on dummy FSs """ return ''.join(random.choice(chars) for _ in range(size))
[ "def", "_get_random_id", "(", "size", "=", "6", ",", "chars", "=", "string", ".", "ascii_uppercase", "+", "string", ".", "digits", ")", ":", "return", "''", ".", "join", "(", "random", ".", "choice", "(", "chars", ")", "for", "_", "in", "range", "(", "size", ")", ")" ]
https://github.com/datalad/datalad/blob/d8c8383d878a207bb586415314219a60c345f732/datalad/support/archives.py#L114-L119
elastic/elasticsearch-py
6ef1adfa3c840a84afda7369cd8e43ae7dc45cdb
elasticsearch/_async/client/__init__.py
python
AsyncElasticsearch.close
(self)
Closes the Transport and all internal connections
Closes the Transport and all internal connections
[ "Closes", "the", "Transport", "and", "all", "internal", "connections" ]
async def close(self) -> None: """Closes the Transport and all internal connections""" await self.transport.close()
[ "async", "def", "close", "(", "self", ")", "->", "None", ":", "await", "self", ".", "transport", ".", "close", "(", ")" ]
https://github.com/elastic/elasticsearch-py/blob/6ef1adfa3c840a84afda7369cd8e43ae7dc45cdb/elasticsearch/_async/client/__init__.py#L515-L517
saltstack/salt
fae5bc757ad0f1716483ce7ae180b451545c2058
salt/modules/k8s.py
python
create_namespace
(name, apiserver_url=None)
return ret
.. versionadded:: 2016.3.0 Create kubernetes namespace from the name, similar to the functionality added to kubectl since v.1.2.0: .. code-block:: bash kubectl create namespaces namespace-name CLI Example: .. code-block:: bash salt '*' k8s.create_namespace namespace_name salt '*' k8s.create_namespace namespace_name http://kube-master.cluster.local
.. versionadded:: 2016.3.0
[ "..", "versionadded", "::", "2016", ".", "3", ".", "0" ]
def create_namespace(name, apiserver_url=None): """ .. versionadded:: 2016.3.0 Create kubernetes namespace from the name, similar to the functionality added to kubectl since v.1.2.0: .. code-block:: bash kubectl create namespaces namespace-name CLI Example: .. code-block:: bash salt '*' k8s.create_namespace namespace_name salt '*' k8s.create_namespace namespace_name http://kube-master.cluster.local """ ret = {"name": name, "result": True, "comment": "", "changes": {}} # Try to get kubernetes master apiserver_url = _guess_apiserver(apiserver_url) if apiserver_url is None: return False if not _get_namespaces(apiserver_url, name): # This is a new namespace _create_namespace(name, apiserver_url) ret["changes"] = name ret["comment"] = "Namespace {} created".format(name) else: ret["comment"] = "Namespace {} already present".format(name) return ret
[ "def", "create_namespace", "(", "name", ",", "apiserver_url", "=", "None", ")", ":", "ret", "=", "{", "\"name\"", ":", "name", ",", "\"result\"", ":", "True", ",", "\"comment\"", ":", "\"\"", ",", "\"changes\"", ":", "{", "}", "}", "# Try to get kubernetes master", "apiserver_url", "=", "_guess_apiserver", "(", "apiserver_url", ")", "if", "apiserver_url", "is", "None", ":", "return", "False", "if", "not", "_get_namespaces", "(", "apiserver_url", ",", "name", ")", ":", "# This is a new namespace", "_create_namespace", "(", "name", ",", "apiserver_url", ")", "ret", "[", "\"changes\"", "]", "=", "name", "ret", "[", "\"comment\"", "]", "=", "\"Namespace {} created\"", ".", "format", "(", "name", ")", "else", ":", "ret", "[", "\"comment\"", "]", "=", "\"Namespace {} already present\"", ".", "format", "(", "name", ")", "return", "ret" ]
https://github.com/saltstack/salt/blob/fae5bc757ad0f1716483ce7ae180b451545c2058/salt/modules/k8s.py#L412-L444
rushter/MLAlgorithms
3c8e16b8de3baf131395ae57edd479e59566a7c6
mla/ensemble/random_forest.py
python
RandomForestClassifier._predict
(self, X=None)
return predictions
[]
def _predict(self, X=None): y_shape = np.unique(self.y).shape[0] predictions = np.zeros((X.shape[0], y_shape)) for i in range(X.shape[0]): row_pred = np.zeros(y_shape) for tree in self.trees: row_pred += tree.predict_row(X[i, :]) row_pred /= self.n_estimators predictions[i, :] = row_pred return predictions
[ "def", "_predict", "(", "self", ",", "X", "=", "None", ")", ":", "y_shape", "=", "np", ".", "unique", "(", "self", ".", "y", ")", ".", "shape", "[", "0", "]", "predictions", "=", "np", ".", "zeros", "(", "(", "X", ".", "shape", "[", "0", "]", ",", "y_shape", ")", ")", "for", "i", "in", "range", "(", "X", ".", "shape", "[", "0", "]", ")", ":", "row_pred", "=", "np", ".", "zeros", "(", "y_shape", ")", "for", "tree", "in", "self", ".", "trees", ":", "row_pred", "+=", "tree", ".", "predict_row", "(", "X", "[", "i", ",", ":", "]", ")", "row_pred", "/=", "self", ".", "n_estimators", "predictions", "[", "i", ",", ":", "]", "=", "row_pred", "return", "predictions" ]
https://github.com/rushter/MLAlgorithms/blob/3c8e16b8de3baf131395ae57edd479e59566a7c6/mla/ensemble/random_forest.py#L73-L84
tensorflow/addons
37a368adfea1d0ec4cb85998946f458e9d565818
tensorflow_addons/image/distort_image_ops.py
python
random_hsv_in_yiq
( image: TensorLike, max_delta_hue: Number = 0, lower_saturation: Number = 1, upper_saturation: Number = 1, lower_value: Number = 1, upper_value: Number = 1, seed: Optional[int] = None, name: Optional[str] = None, )
Adjust hue, saturation, value of an RGB image randomly in YIQ color space. Equivalent to `adjust_yiq_hsv()` but uses a `delta_h` randomly picked in the interval `[-max_delta_hue, max_delta_hue]`, a `scale_saturation` randomly picked in the interval `[lower_saturation, upper_saturation]`, and a `scale_value` randomly picked in the interval `[lower_saturation, upper_saturation]`. Args: image: RGB image or images. Size of the last dimension must be 3. max_delta_hue: `float`. Maximum value for the random delta_hue. Passing 0 disables adjusting hue. lower_saturation: `float`. Lower bound for the random scale_saturation. upper_saturation: `float`. Upper bound for the random scale_saturation. lower_value: `float`. Lower bound for the random scale_value. upper_value: `float`. Upper bound for the random scale_value. seed: An operation-specific seed. It will be used in conjunction with the graph-level seed to determine the real seeds that will be used in this operation. Please see the documentation of set_random_seed for its interaction with the graph-level random seed. name: A name for this operation (optional). Returns: 3-D float `Tensor` of shape `[height, width, channels]`. Raises: ValueError: if `max_delta`, `lower_saturation`, `upper_saturation`, `lower_value`, or `upper_value` is invalid.
Adjust hue, saturation, value of an RGB image randomly in YIQ color space.
[ "Adjust", "hue", "saturation", "value", "of", "an", "RGB", "image", "randomly", "in", "YIQ", "color", "space", "." ]
def random_hsv_in_yiq( image: TensorLike, max_delta_hue: Number = 0, lower_saturation: Number = 1, upper_saturation: Number = 1, lower_value: Number = 1, upper_value: Number = 1, seed: Optional[int] = None, name: Optional[str] = None, ) -> tf.Tensor: """Adjust hue, saturation, value of an RGB image randomly in YIQ color space. Equivalent to `adjust_yiq_hsv()` but uses a `delta_h` randomly picked in the interval `[-max_delta_hue, max_delta_hue]`, a `scale_saturation` randomly picked in the interval `[lower_saturation, upper_saturation]`, and a `scale_value` randomly picked in the interval `[lower_saturation, upper_saturation]`. Args: image: RGB image or images. Size of the last dimension must be 3. max_delta_hue: `float`. Maximum value for the random delta_hue. Passing 0 disables adjusting hue. lower_saturation: `float`. Lower bound for the random scale_saturation. upper_saturation: `float`. Upper bound for the random scale_saturation. lower_value: `float`. Lower bound for the random scale_value. upper_value: `float`. Upper bound for the random scale_value. seed: An operation-specific seed. It will be used in conjunction with the graph-level seed to determine the real seeds that will be used in this operation. Please see the documentation of set_random_seed for its interaction with the graph-level random seed. name: A name for this operation (optional). Returns: 3-D float `Tensor` of shape `[height, width, channels]`. Raises: ValueError: if `max_delta`, `lower_saturation`, `upper_saturation`, `lower_value`, or `upper_value` is invalid. """ if max_delta_hue < 0: raise ValueError("max_delta must be non-negative.") if lower_saturation < 0: raise ValueError("lower_saturation must be non-negative.") if lower_value < 0: raise ValueError("lower_value must be non-negative.") if lower_saturation > upper_saturation: raise ValueError( "lower_saturation must be not greater than " "upper_saturation." ) if lower_value > upper_value: raise ValueError("lower_value must be not greater than upper_value.") with tf.name_scope(name or "random_hsv_in_yiq") as scope: if max_delta_hue == 0: delta_hue = 0 else: delta_hue = tf.random.uniform([], -max_delta_hue, max_delta_hue, seed=seed) if lower_saturation == upper_saturation: scale_saturation = lower_saturation else: scale_saturation = tf.random.uniform( [], lower_saturation, upper_saturation, seed=seed ) if lower_value == upper_value: scale_value = lower_value else: scale_value = tf.random.uniform([], lower_value, upper_value, seed=seed) return adjust_hsv_in_yiq( image, delta_hue, scale_saturation, scale_value, name=scope )
[ "def", "random_hsv_in_yiq", "(", "image", ":", "TensorLike", ",", "max_delta_hue", ":", "Number", "=", "0", ",", "lower_saturation", ":", "Number", "=", "1", ",", "upper_saturation", ":", "Number", "=", "1", ",", "lower_value", ":", "Number", "=", "1", ",", "upper_value", ":", "Number", "=", "1", ",", "seed", ":", "Optional", "[", "int", "]", "=", "None", ",", "name", ":", "Optional", "[", "str", "]", "=", "None", ",", ")", "->", "tf", ".", "Tensor", ":", "if", "max_delta_hue", "<", "0", ":", "raise", "ValueError", "(", "\"max_delta must be non-negative.\"", ")", "if", "lower_saturation", "<", "0", ":", "raise", "ValueError", "(", "\"lower_saturation must be non-negative.\"", ")", "if", "lower_value", "<", "0", ":", "raise", "ValueError", "(", "\"lower_value must be non-negative.\"", ")", "if", "lower_saturation", ">", "upper_saturation", ":", "raise", "ValueError", "(", "\"lower_saturation must be not greater than \"", "\"upper_saturation.\"", ")", "if", "lower_value", ">", "upper_value", ":", "raise", "ValueError", "(", "\"lower_value must be not greater than upper_value.\"", ")", "with", "tf", ".", "name_scope", "(", "name", "or", "\"random_hsv_in_yiq\"", ")", "as", "scope", ":", "if", "max_delta_hue", "==", "0", ":", "delta_hue", "=", "0", "else", ":", "delta_hue", "=", "tf", ".", "random", ".", "uniform", "(", "[", "]", ",", "-", "max_delta_hue", ",", "max_delta_hue", ",", "seed", "=", "seed", ")", "if", "lower_saturation", "==", "upper_saturation", ":", "scale_saturation", "=", "lower_saturation", "else", ":", "scale_saturation", "=", "tf", ".", "random", ".", "uniform", "(", "[", "]", ",", "lower_saturation", ",", "upper_saturation", ",", "seed", "=", "seed", ")", "if", "lower_value", "==", "upper_value", ":", "scale_value", "=", "lower_value", "else", ":", "scale_value", "=", "tf", ".", "random", ".", "uniform", "(", "[", "]", ",", "lower_value", ",", "upper_value", ",", "seed", "=", "seed", ")", "return", "adjust_hsv_in_yiq", "(", "image", ",", "delta_hue", ",", "scale_saturation", ",", "scale_value", ",", "name", "=", "scope", ")" ]
https://github.com/tensorflow/addons/blob/37a368adfea1d0ec4cb85998946f458e9d565818/tensorflow_addons/image/distort_image_ops.py#L29-L102
AutodeskRoboticsLab/Mimic
85447f0d346be66988303a6a054473d92f1ed6f4
mimic/scripts/mimic_external_axes.py
python
_enable_external_axis_limits
(external_axis_CTRL, driving_attribute_trunc, driving_axis, enable=True)
Enables/Disables external axis' limit attributes :param external_axis_CTRL: str, name of external axis control :param driving_attribute_trunc: str, truncated name of driving attribute (e.g. Trans, Rot) :param driving_axis: str, 'X', 'Y', or 'Z' :param enable: bool, default True
Enables/Disables external axis' limit attributes :param external_axis_CTRL: str, name of external axis control :param driving_attribute_trunc: str, truncated name of driving attribute (e.g. Trans, Rot) :param driving_axis: str, 'X', 'Y', or 'Z' :param enable: bool, default True
[ "Enables", "/", "Disables", "external", "axis", "limit", "attributes", ":", "param", "external_axis_CTRL", ":", "str", "name", "of", "external", "axis", "control", ":", "param", "driving_attribute_trunc", ":", "str", "truncated", "name", "of", "driving", "attribute", "(", "e", ".", "g", ".", "Trans", "Rot", ")", ":", "param", "driving_axis", ":", "str", "X", "Y", "or", "Z", ":", "param", "enable", ":", "bool", "default", "True" ]
def _enable_external_axis_limits(external_axis_CTRL, driving_attribute_trunc, driving_axis, enable=True): """ Enables/Disables external axis' limit attributes :param external_axis_CTRL: str, name of external axis control :param driving_attribute_trunc: str, truncated name of driving attribute (e.g. Trans, Rot) :param driving_axis: str, 'X', 'Y', or 'Z' :param enable: bool, default True """ pm.setAttr('{}.min{}{}LimitEnable'.format(external_axis_CTRL, driving_attribute_trunc, driving_axis), enable) pm.setAttr('{}.max{}{}LimitEnable'.format(external_axis_CTRL, driving_attribute_trunc, driving_axis), enable)
[ "def", "_enable_external_axis_limits", "(", "external_axis_CTRL", ",", "driving_attribute_trunc", ",", "driving_axis", ",", "enable", "=", "True", ")", ":", "pm", ".", "setAttr", "(", "'{}.min{}{}LimitEnable'", ".", "format", "(", "external_axis_CTRL", ",", "driving_attribute_trunc", ",", "driving_axis", ")", ",", "enable", ")", "pm", ".", "setAttr", "(", "'{}.max{}{}LimitEnable'", ".", "format", "(", "external_axis_CTRL", ",", "driving_attribute_trunc", ",", "driving_axis", ")", ",", "enable", ")" ]
https://github.com/AutodeskRoboticsLab/Mimic/blob/85447f0d346be66988303a6a054473d92f1ed6f4/mimic/scripts/mimic_external_axes.py#L457-L475
ibis-project/ibis
e1ef8b6870ac53de9d1fe5c52851fa41872109c4
ibis/expr/datatypes.py
python
infer_dtype_default
(value: typing.Any)
Default implementation of :func:`~ibis.expr.datatypes.infer`.
Default implementation of :func:`~ibis.expr.datatypes.infer`.
[ "Default", "implementation", "of", ":", "func", ":", "~ibis", ".", "expr", ".", "datatypes", ".", "infer", "." ]
def infer_dtype_default(value: typing.Any) -> DataType: """Default implementation of :func:`~ibis.expr.datatypes.infer`.""" raise com.InputTypeError(value)
[ "def", "infer_dtype_default", "(", "value", ":", "typing", ".", "Any", ")", "->", "DataType", ":", "raise", "com", ".", "InputTypeError", "(", "value", ")" ]
https://github.com/ibis-project/ibis/blob/e1ef8b6870ac53de9d1fe5c52851fa41872109c4/ibis/expr/datatypes.py#L1161-L1163
openstack/barbican
a9d2b133c8dc3307974f119f9a2b23a4ba82e8ce
barbican/plugin/crypto/p11_crypto.py
python
P11CryptoPlugin.supports
(self, type_enum, algorithm=None, bit_length=None, mode=None)
[]
def supports(self, type_enum, algorithm=None, bit_length=None, mode=None): if type_enum == plugin.PluginSupportTypes.ENCRYPT_DECRYPT: return True elif type_enum == plugin.PluginSupportTypes.SYMMETRIC_KEY_GENERATION: return True elif type_enum == plugin.PluginSupportTypes.ASYMMETRIC_KEY_GENERATION: return False else: return False
[ "def", "supports", "(", "self", ",", "type_enum", ",", "algorithm", "=", "None", ",", "bit_length", "=", "None", ",", "mode", "=", "None", ")", ":", "if", "type_enum", "==", "plugin", ".", "PluginSupportTypes", ".", "ENCRYPT_DECRYPT", ":", "return", "True", "elif", "type_enum", "==", "plugin", ".", "PluginSupportTypes", ".", "SYMMETRIC_KEY_GENERATION", ":", "return", "True", "elif", "type_enum", "==", "plugin", ".", "PluginSupportTypes", ".", "ASYMMETRIC_KEY_GENERATION", ":", "return", "False", "else", ":", "return", "False" ]
https://github.com/openstack/barbican/blob/a9d2b133c8dc3307974f119f9a2b23a4ba82e8ce/barbican/plugin/crypto/p11_crypto.py#L196-L204
spyder-ide/spyder
55da47c032dfcf519600f67f8b30eab467f965e7
spyder/plugins/shortcuts/widgets/table.py
python
ShortcutsModel.flags
(self, index)
return Qt.ItemFlags(int(QAbstractTableModel.flags(self, index)))
Qt Override.
Qt Override.
[ "Qt", "Override", "." ]
def flags(self, index): """Qt Override.""" if not index.isValid(): return Qt.ItemIsEnabled return Qt.ItemFlags(int(QAbstractTableModel.flags(self, index)))
[ "def", "flags", "(", "self", ",", "index", ")", ":", "if", "not", "index", ".", "isValid", "(", ")", ":", "return", "Qt", ".", "ItemIsEnabled", "return", "Qt", ".", "ItemFlags", "(", "int", "(", "QAbstractTableModel", ".", "flags", "(", "self", ",", "index", ")", ")", ")" ]
https://github.com/spyder-ide/spyder/blob/55da47c032dfcf519600f67f8b30eab467f965e7/spyder/plugins/shortcuts/widgets/table.py#L531-L535
qubvel/segmentation_models.pytorch
06fdd31a6fadf659f9c90648e876dbe097e0e399
segmentation_models_pytorch/base/model.py
python
SegmentationModel.forward
(self, x)
return masks
Sequentially pass `x` trough model`s encoder, decoder and heads
Sequentially pass `x` trough model`s encoder, decoder and heads
[ "Sequentially", "pass", "x", "trough", "model", "s", "encoder", "decoder", "and", "heads" ]
def forward(self, x): """Sequentially pass `x` trough model`s encoder, decoder and heads""" features = self.encoder(x) decoder_output = self.decoder(*features) masks = self.segmentation_head(decoder_output) if self.classification_head is not None: labels = self.classification_head(features[-1]) return masks, labels return masks
[ "def", "forward", "(", "self", ",", "x", ")", ":", "features", "=", "self", ".", "encoder", "(", "x", ")", "decoder_output", "=", "self", ".", "decoder", "(", "*", "features", ")", "masks", "=", "self", ".", "segmentation_head", "(", "decoder_output", ")", "if", "self", ".", "classification_head", "is", "not", "None", ":", "labels", "=", "self", ".", "classification_head", "(", "features", "[", "-", "1", "]", ")", "return", "masks", ",", "labels", "return", "masks" ]
https://github.com/qubvel/segmentation_models.pytorch/blob/06fdd31a6fadf659f9c90648e876dbe097e0e399/segmentation_models_pytorch/base/model.py#L12-L23
canonical/cloud-init
dc1aabfca851e520693c05322f724bd102c76364
setup.py
python
render_tmpl
(template, mode=None)
return os.path.join(os.path.basename(tmpd), bname)
render template into a tmpdir under same dir as setup.py This is rendered to a temporary directory under the top level directory with the name 'cloud.cfg'. The reason for not just rendering to config/cloud.cfg is for a.) don't want to write over contents in that file if user had something there. b.) debuild will complain that files are different outside of the debian directory.
render template into a tmpdir under same dir as setup.py
[ "render", "template", "into", "a", "tmpdir", "under", "same", "dir", "as", "setup", ".", "py" ]
def render_tmpl(template, mode=None): """render template into a tmpdir under same dir as setup.py This is rendered to a temporary directory under the top level directory with the name 'cloud.cfg'. The reason for not just rendering to config/cloud.cfg is for a.) don't want to write over contents in that file if user had something there. b.) debuild will complain that files are different outside of the debian directory.""" # older versions of tox use bdist (xenial), and then install from there. # newer versions just use install. if not (sys.argv[1] == "install" or sys.argv[1].startswith("bdist*")): return template tmpl_ext = ".tmpl" # we may get passed a non-template file, just pass it back if not template.endswith(tmpl_ext): return template topdir = os.path.dirname(sys.argv[0]) tmpd = tempfile.mkdtemp(dir=topdir, prefix=RENDERED_TMPD_PREFIX) atexit.register(shutil.rmtree, tmpd) bname = os.path.basename(template).rstrip(tmpl_ext) fpath = os.path.join(tmpd, bname) if VARIANT: subprocess.run( [ sys.executable, "./tools/render-cloudcfg", "--variant", VARIANT, template, fpath, ] ) else: subprocess.run( [sys.executable, "./tools/render-cloudcfg", template, fpath] ) if mode: os.chmod(fpath, mode) # return path relative to setup.py return os.path.join(os.path.basename(tmpd), bname)
[ "def", "render_tmpl", "(", "template", ",", "mode", "=", "None", ")", ":", "# older versions of tox use bdist (xenial), and then install from there.", "# newer versions just use install.", "if", "not", "(", "sys", ".", "argv", "[", "1", "]", "==", "\"install\"", "or", "sys", ".", "argv", "[", "1", "]", ".", "startswith", "(", "\"bdist*\"", ")", ")", ":", "return", "template", "tmpl_ext", "=", "\".tmpl\"", "# we may get passed a non-template file, just pass it back", "if", "not", "template", ".", "endswith", "(", "tmpl_ext", ")", ":", "return", "template", "topdir", "=", "os", ".", "path", ".", "dirname", "(", "sys", ".", "argv", "[", "0", "]", ")", "tmpd", "=", "tempfile", ".", "mkdtemp", "(", "dir", "=", "topdir", ",", "prefix", "=", "RENDERED_TMPD_PREFIX", ")", "atexit", ".", "register", "(", "shutil", ".", "rmtree", ",", "tmpd", ")", "bname", "=", "os", ".", "path", ".", "basename", "(", "template", ")", ".", "rstrip", "(", "tmpl_ext", ")", "fpath", "=", "os", ".", "path", ".", "join", "(", "tmpd", ",", "bname", ")", "if", "VARIANT", ":", "subprocess", ".", "run", "(", "[", "sys", ".", "executable", ",", "\"./tools/render-cloudcfg\"", ",", "\"--variant\"", ",", "VARIANT", ",", "template", ",", "fpath", ",", "]", ")", "else", ":", "subprocess", ".", "run", "(", "[", "sys", ".", "executable", ",", "\"./tools/render-cloudcfg\"", ",", "template", ",", "fpath", "]", ")", "if", "mode", ":", "os", ".", "chmod", "(", "fpath", ",", "mode", ")", "# return path relative to setup.py", "return", "os", ".", "path", ".", "join", "(", "os", ".", "path", ".", "basename", "(", "tmpd", ")", ",", "bname", ")" ]
https://github.com/canonical/cloud-init/blob/dc1aabfca851e520693c05322f724bd102c76364/setup.py#L79-L121
tp4a/teleport
1fafd34f1f775d2cf80ea4af6e44468d8e0b24ad
server/www/packages/packages-darwin/x64/pymysql/util.py
python
int2byte
(i)
return struct.pack("!B", i)
[]
def int2byte(i): return struct.pack("!B", i)
[ "def", "int2byte", "(", "i", ")", ":", "return", "struct", ".", "pack", "(", "\"!B\"", ",", "i", ")" ]
https://github.com/tp4a/teleport/blob/1fafd34f1f775d2cf80ea4af6e44468d8e0b24ad/server/www/packages/packages-darwin/x64/pymysql/util.py#L11-L12
open-cogsci/OpenSesame
c4a3641b097a80a76937edbd8c365f036bcc9705
libqtopensesame/items/keyboard_response.py
python
keyboard_response.__init__
(self, name, experiment, string=None)
Constructor Arguments: name -- item name experiment -- experiment instance Keywords arguments: string -- a definition string (default=None)
Constructor
[ "Constructor" ]
def __init__(self, name, experiment, string=None): """ Constructor Arguments: name -- item name experiment -- experiment instance Keywords arguments: string -- a definition string (default=None) """ keyboard_response_runtime.__init__(self, name, experiment, string) qtplugin.__init__(self)
[ "def", "__init__", "(", "self", ",", "name", ",", "experiment", ",", "string", "=", "None", ")", ":", "keyboard_response_runtime", ".", "__init__", "(", "self", ",", "name", ",", "experiment", ",", "string", ")", "qtplugin", ".", "__init__", "(", "self", ")" ]
https://github.com/open-cogsci/OpenSesame/blob/c4a3641b097a80a76937edbd8c365f036bcc9705/libqtopensesame/items/keyboard_response.py#L39-L53
dimagi/commcare-hq
d67ff1d3b4c51fa050c19e60c3253a79d3452a39
corehq/ex-submodules/dimagi/utils/couch/migration.py
python
SyncSQLToCouchMixin._migration_get_couch_object
(self)
[]
def _migration_get_couch_object(self): if not self._migration_couch_id: return None cls = self._migration_get_couch_model_class() try: return cls.get(str(self._migration_couch_id)) except ResourceNotFound: return None
[ "def", "_migration_get_couch_object", "(", "self", ")", ":", "if", "not", "self", ".", "_migration_couch_id", ":", "return", "None", "cls", "=", "self", ".", "_migration_get_couch_model_class", "(", ")", "try", ":", "return", "cls", ".", "get", "(", "str", "(", "self", ".", "_migration_couch_id", ")", ")", "except", "ResourceNotFound", ":", "return", "None" ]
https://github.com/dimagi/commcare-hq/blob/d67ff1d3b4c51fa050c19e60c3253a79d3452a39/corehq/ex-submodules/dimagi/utils/couch/migration.py#L243-L250
netzob/netzob
49ee3e5e7d6dce67496afd5a75827a78be0c9f70
netzob/src/netzob/Model/Vocabulary/Messages/L4NetworkMessage.py
python
L4NetworkMessage.l4Protocol
(self)
return self.__l4Protocol
The protocol of the fourth layer :type: str
The protocol of the fourth layer
[ "The", "protocol", "of", "the", "fourth", "layer" ]
def l4Protocol(self): """The protocol of the fourth layer :type: str """ return self.__l4Protocol
[ "def", "l4Protocol", "(", "self", ")", ":", "return", "self", ".", "__l4Protocol" ]
https://github.com/netzob/netzob/blob/49ee3e5e7d6dce67496afd5a75827a78be0c9f70/netzob/src/netzob/Model/Vocabulary/Messages/L4NetworkMessage.py#L77-L82
JetBrains/python-skeletons
95ad24b666e475998e5d1cc02ed53a2188036167
numpy/core/__init__.py
python
int8.__or__
(self, *args, **kwargs)
Return self|value.
Return self|value.
[ "Return", "self|value", "." ]
def __or__(self, *args, **kwargs): # real signature unknown """ Return self|value. """ pass
[ "def", "__or__", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "# real signature unknown", "pass" ]
https://github.com/JetBrains/python-skeletons/blob/95ad24b666e475998e5d1cc02ed53a2188036167/numpy/core/__init__.py#L1205-L1207
sreyafrancis/PFNN
61a50342b693826ca0f07d0c0eaa6366ed4851f6
motion/Quaternions.py
python
Quaternions.__div__
(self, other)
When a Quaternion type is supplied, division is defined as multiplication by the inverse of that Quaternion. When a scalar or vector is supplied it is defined as multiplicaion of one over the supplied value. Essentially a scaling.
When a Quaternion type is supplied, division is defined as multiplication by the inverse of that Quaternion. When a scalar or vector is supplied it is defined as multiplicaion of one over the supplied value. Essentially a scaling.
[ "When", "a", "Quaternion", "type", "is", "supplied", "division", "is", "defined", "as", "multiplication", "by", "the", "inverse", "of", "that", "Quaternion", ".", "When", "a", "scalar", "or", "vector", "is", "supplied", "it", "is", "defined", "as", "multiplicaion", "of", "one", "over", "the", "supplied", "value", ".", "Essentially", "a", "scaling", "." ]
def __div__(self, other): """ When a Quaternion type is supplied, division is defined as multiplication by the inverse of that Quaternion. When a scalar or vector is supplied it is defined as multiplicaion of one over the supplied value. Essentially a scaling. """ if isinstance(other, Quaternions): return self * (-other) if isinstance(other, np.ndarray): return self * (1.0 / other) if isinstance(other, float): return self * (1.0 / other) raise TypeError('Cannot divide/subtract Quaternions with type %s' + str(type(other)))
[ "def", "__div__", "(", "self", ",", "other", ")", ":", "if", "isinstance", "(", "other", ",", "Quaternions", ")", ":", "return", "self", "*", "(", "-", "other", ")", "if", "isinstance", "(", "other", ",", "np", ".", "ndarray", ")", ":", "return", "self", "*", "(", "1.0", "/", "other", ")", "if", "isinstance", "(", "other", ",", "float", ")", ":", "return", "self", "*", "(", "1.0", "/", "other", ")", "raise", "TypeError", "(", "'Cannot divide/subtract Quaternions with type %s'", "+", "str", "(", "type", "(", "other", ")", ")", ")" ]
https://github.com/sreyafrancis/PFNN/blob/61a50342b693826ca0f07d0c0eaa6366ed4851f6/motion/Quaternions.py#L120-L133
AppScale/gts
46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9
AppServer/lib/django-1.2/django/contrib/auth/models.py
python
User.is_anonymous
(self)
return False
Always returns False. This is a way of comparing User objects to anonymous users.
Always returns False. This is a way of comparing User objects to anonymous users.
[ "Always", "returns", "False", ".", "This", "is", "a", "way", "of", "comparing", "User", "objects", "to", "anonymous", "users", "." ]
def is_anonymous(self): """ Always returns False. This is a way of comparing User objects to anonymous users. """ return False
[ "def", "is_anonymous", "(", "self", ")", ":", "return", "False" ]
https://github.com/AppScale/gts/blob/46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9/AppServer/lib/django-1.2/django/contrib/auth/models.py#L217-L222
peterdsharpe/AeroSandbox
ded68b0465f2bfdcaf4bc90abd8c91be0addcaba
aerosandbox/modeling/surrogate_model.py
python
SurrogateModel.__call__
(self, x: Union[int, float, np.ndarray, Dict[str, np.ndarray]] )
Evaluates the surrogate model at some given input x. The input `x` is of the type: * in the general N-dimensional case, a dictionary where keys are variable names and values are float/array. * in the case of a 1-dimensional input (R^1 -> R^2), a float/array.
Evaluates the surrogate model at some given input x.
[ "Evaluates", "the", "surrogate", "model", "at", "some", "given", "input", "x", "." ]
def __call__(self, x: Union[int, float, np.ndarray, Dict[str, np.ndarray]] ) -> Union[float, np.ndarray]: """ Evaluates the surrogate model at some given input x. The input `x` is of the type: * in the general N-dimensional case, a dictionary where keys are variable names and values are float/array. * in the case of a 1-dimensional input (R^1 -> R^2), a float/array. """ ### Perform basic type checking on x, if x_data exists as a reference. try: x_data_is_dict = isinstance(self.x_data, dict) input_is_dict = isinstance(x, dict) if x_data_is_dict and not input_is_dict: raise TypeError( f"The input to this model should be a dict with: keys {self.input_names()}, values as float or array.") if input_is_dict and not x_data_is_dict: raise TypeError("The input to this model should be a float or array.") except NameError: # If x_data does not exist pass
[ "def", "__call__", "(", "self", ",", "x", ":", "Union", "[", "int", ",", "float", ",", "np", ".", "ndarray", ",", "Dict", "[", "str", ",", "np", ".", "ndarray", "]", "]", ")", "->", "Union", "[", "float", ",", "np", ".", "ndarray", "]", ":", "### Perform basic type checking on x, if x_data exists as a reference.", "try", ":", "x_data_is_dict", "=", "isinstance", "(", "self", ".", "x_data", ",", "dict", ")", "input_is_dict", "=", "isinstance", "(", "x", ",", "dict", ")", "if", "x_data_is_dict", "and", "not", "input_is_dict", ":", "raise", "TypeError", "(", "f\"The input to this model should be a dict with: keys {self.input_names()}, values as float or array.\"", ")", "if", "input_is_dict", "and", "not", "x_data_is_dict", ":", "raise", "TypeError", "(", "\"The input to this model should be a float or array.\"", ")", "except", "NameError", ":", "# If x_data does not exist", "pass" ]
https://github.com/peterdsharpe/AeroSandbox/blob/ded68b0465f2bfdcaf4bc90abd8c91be0addcaba/aerosandbox/modeling/surrogate_model.py#L36-L59
demisto/content
5c664a65b992ac8ca90ac3f11b1b2cdf11ee9b07
Packs/QRadar/Integrations/QRadar_v2/QRadar_v2.py
python
enrich_offense_res_with_domain_names
(client, domain_ids, response)
Add domain_name to the offense and assets results
Add domain_name to the offense and assets results
[ "Add", "domain_name", "to", "the", "offense", "and", "assets", "results" ]
def enrich_offense_res_with_domain_names(client, domain_ids, response): """ Add domain_name to the offense and assets results """ domain_filter = 'id=' + 'or id='.join(str(domain_ids).replace(' ', '').split(','))[1:-1] domains = client.get_devices(_filter=domain_filter) domain_names = {d['id']: d['name'] for d in domains} for offense in response: if 'domain_id' in offense: offense['domain_name'] = domain_names.get(offense['domain_id'], '') if 'assets' in offense: for asset in offense['assets']: if 'domain_id' in asset: asset['domain_name'] = domain_names.get(asset['domain_id'], '')
[ "def", "enrich_offense_res_with_domain_names", "(", "client", ",", "domain_ids", ",", "response", ")", ":", "domain_filter", "=", "'id='", "+", "'or id='", ".", "join", "(", "str", "(", "domain_ids", ")", ".", "replace", "(", "' '", ",", "''", ")", ".", "split", "(", "','", ")", ")", "[", "1", ":", "-", "1", "]", "domains", "=", "client", ".", "get_devices", "(", "_filter", "=", "domain_filter", ")", "domain_names", "=", "{", "d", "[", "'id'", "]", ":", "d", "[", "'name'", "]", "for", "d", "in", "domains", "}", "for", "offense", "in", "response", ":", "if", "'domain_id'", "in", "offense", ":", "offense", "[", "'domain_name'", "]", "=", "domain_names", ".", "get", "(", "offense", "[", "'domain_id'", "]", ",", "''", ")", "if", "'assets'", "in", "offense", ":", "for", "asset", "in", "offense", "[", "'assets'", "]", ":", "if", "'domain_id'", "in", "asset", ":", "asset", "[", "'domain_name'", "]", "=", "domain_names", ".", "get", "(", "asset", "[", "'domain_id'", "]", ",", "''", ")" ]
https://github.com/demisto/content/blob/5c664a65b992ac8ca90ac3f11b1b2cdf11ee9b07/Packs/QRadar/Integrations/QRadar_v2/QRadar_v2.py#L1193-L1206
OpenZWave/python-openzwave
8be4c070294348f3fc268bc1d7ad2c535f352f5a
src-manager/pyozwman/ozwsh_widgets.py
python
ValuesTree.cd
(self, directory)
return None
Change to directory and return the widget to display
Change to directory and return the widget to display
[ "Change", "to", "directory", "and", "return", "the", "widget", "to", "display" ]
def cd(self, directory): """ Change to directory and return the widget to display """ if self.exist(directory) : if directory == '..': self.node_id = None return self.parent.widget_box if directory in self.childrens: self.window.log.info("cd %s" %directory) return self.childrens[directory]['widget_box'] return None
[ "def", "cd", "(", "self", ",", "directory", ")", ":", "if", "self", ".", "exist", "(", "directory", ")", ":", "if", "directory", "==", "'..'", ":", "self", ".", "node_id", "=", "None", "return", "self", ".", "parent", ".", "widget_box", "if", "directory", "in", "self", ".", "childrens", ":", "self", ".", "window", ".", "log", ".", "info", "(", "\"cd %s\"", "%", "directory", ")", "return", "self", ".", "childrens", "[", "directory", "]", "[", "'widget_box'", "]", "return", "None" ]
https://github.com/OpenZWave/python-openzwave/blob/8be4c070294348f3fc268bc1d7ad2c535f352f5a/src-manager/pyozwman/ozwsh_widgets.py#L1300-L1311
Azure/azure-devops-cli-extension
11334cd55806bef0b99c3bee5a438eed71e44037
azure-devops/azext_devops/devops_sdk/v6_0/gallery/gallery_client.py
python
GalleryClient.query_publishers
(self, publisher_query)
return self._deserialize('PublisherQueryResult', response)
QueryPublishers. [Preview API] :param :class:`<PublisherQuery> <azure.devops.v6_0.gallery.models.PublisherQuery>` publisher_query: :rtype: :class:`<PublisherQueryResult> <azure.devops.v6_0.gallery.models.PublisherQueryResult>`
QueryPublishers. [Preview API] :param :class:`<PublisherQuery> <azure.devops.v6_0.gallery.models.PublisherQuery>` publisher_query: :rtype: :class:`<PublisherQueryResult> <azure.devops.v6_0.gallery.models.PublisherQueryResult>`
[ "QueryPublishers", ".", "[", "Preview", "API", "]", ":", "param", ":", "class", ":", "<PublisherQuery", ">", "<azure", ".", "devops", ".", "v6_0", ".", "gallery", ".", "models", ".", "PublisherQuery", ">", "publisher_query", ":", ":", "rtype", ":", ":", "class", ":", "<PublisherQueryResult", ">", "<azure", ".", "devops", ".", "v6_0", ".", "gallery", ".", "models", ".", "PublisherQueryResult", ">" ]
def query_publishers(self, publisher_query): """QueryPublishers. [Preview API] :param :class:`<PublisherQuery> <azure.devops.v6_0.gallery.models.PublisherQuery>` publisher_query: :rtype: :class:`<PublisherQueryResult> <azure.devops.v6_0.gallery.models.PublisherQueryResult>` """ content = self._serialize.body(publisher_query, 'PublisherQuery') response = self._send(http_method='POST', location_id='2ad6ee0a-b53f-4034-9d1d-d009fda1212e', version='6.0-preview.1', content=content) return self._deserialize('PublisherQueryResult', response)
[ "def", "query_publishers", "(", "self", ",", "publisher_query", ")", ":", "content", "=", "self", ".", "_serialize", ".", "body", "(", "publisher_query", ",", "'PublisherQuery'", ")", "response", "=", "self", ".", "_send", "(", "http_method", "=", "'POST'", ",", "location_id", "=", "'2ad6ee0a-b53f-4034-9d1d-d009fda1212e'", ",", "version", "=", "'6.0-preview.1'", ",", "content", "=", "content", ")", "return", "self", ".", "_deserialize", "(", "'PublisherQueryResult'", ",", "response", ")" ]
https://github.com/Azure/azure-devops-cli-extension/blob/11334cd55806bef0b99c3bee5a438eed71e44037/azure-devops/azext_devops/devops_sdk/v6_0/gallery/gallery_client.py#L1221-L1232
plotly/plotly.py
cfad7862594b35965c0e000813bd7805e8494a5b
packages/python/plotly/plotly/graph_objs/bar/marker/_colorbar.py
python
ColorBar.len
(self)
return self["len"]
Sets the length of the color bar This measure excludes the padding of both ends. That is, the color bar length is this length minus the padding on both ends. The 'len' property is a number and may be specified as: - An int or float in the interval [0, inf] Returns ------- int|float
Sets the length of the color bar This measure excludes the padding of both ends. That is, the color bar length is this length minus the padding on both ends. The 'len' property is a number and may be specified as: - An int or float in the interval [0, inf]
[ "Sets", "the", "length", "of", "the", "color", "bar", "This", "measure", "excludes", "the", "padding", "of", "both", "ends", ".", "That", "is", "the", "color", "bar", "length", "is", "this", "length", "minus", "the", "padding", "on", "both", "ends", ".", "The", "len", "property", "is", "a", "number", "and", "may", "be", "specified", "as", ":", "-", "An", "int", "or", "float", "in", "the", "interval", "[", "0", "inf", "]" ]
def len(self): """ Sets the length of the color bar This measure excludes the padding of both ends. That is, the color bar length is this length minus the padding on both ends. The 'len' property is a number and may be specified as: - An int or float in the interval [0, inf] Returns ------- int|float """ return self["len"]
[ "def", "len", "(", "self", ")", ":", "return", "self", "[", "\"len\"", "]" ]
https://github.com/plotly/plotly.py/blob/cfad7862594b35965c0e000813bd7805e8494a5b/packages/python/plotly/plotly/graph_objs/bar/marker/_colorbar.py#L265-L278
thenetcircle/dino
1047c3458e91a1b4189e9f48f1393b3a68a935b3
dino/db/__init__.py
python
IDatabase.get_online_admins
(self)
get uuids of all admins that are online :return: list of uuids
get uuids of all admins that are online
[ "get", "uuids", "of", "all", "admins", "that", "are", "online" ]
def get_online_admins(self) -> list: """ get uuids of all admins that are online :return: list of uuids """
[ "def", "get_online_admins", "(", "self", ")", "->", "list", ":" ]
https://github.com/thenetcircle/dino/blob/1047c3458e91a1b4189e9f48f1393b3a68a935b3/dino/db/__init__.py#L434-L439
pytorchbearer/torchbearer
9d97c60ec4deb37a0627311ddecb9c6f1429cd82
torchbearer/metrics/aggregators.py
python
Std.__init__
(self, name, unbiased=True, dim=None)
[]
def __init__(self, name, unbiased=True, dim=None): super(Std, self).__init__(name, unbiased=unbiased, dim=dim)
[ "def", "__init__", "(", "self", ",", "name", ",", "unbiased", "=", "True", ",", "dim", "=", "None", ")", ":", "super", "(", "Std", ",", "self", ")", ".", "__init__", "(", "name", ",", "unbiased", "=", "unbiased", ",", "dim", "=", "dim", ")" ]
https://github.com/pytorchbearer/torchbearer/blob/9d97c60ec4deb37a0627311ddecb9c6f1429cd82/torchbearer/metrics/aggregators.py#L180-L181
jbjorne/TEES
caf19a4a1352ac59f5dc13a8684cc42ce4342d9d
ExampleBuilders/ExampleStats.py
python
ExampleStats.addExample
(self, className, filteredBy=[])
[]
def addExample(self, className, filteredBy=[]): self.beginExample(className) for filter in filteredBy: self.filter(filter) self.endExample()
[ "def", "addExample", "(", "self", ",", "className", ",", "filteredBy", "=", "[", "]", ")", ":", "self", ".", "beginExample", "(", "className", ")", "for", "filter", "in", "filteredBy", ":", "self", ".", "filter", "(", "filter", ")", "self", ".", "endExample", "(", ")" ]
https://github.com/jbjorne/TEES/blob/caf19a4a1352ac59f5dc13a8684cc42ce4342d9d/ExampleBuilders/ExampleStats.py#L24-L28
lektor/lektor
d5a7f22343572a991f2316c086f24005d0cbf0f8
lektor/db.py
python
Query.count
(self)
return rv
Counts all matched objects.
Counts all matched objects.
[ "Counts", "all", "matched", "objects", "." ]
def count(self): """Counts all matched objects.""" rv = 0 for _ in self: rv += 1 return rv
[ "def", "count", "(", "self", ")", ":", "rv", "=", "0", "for", "_", "in", "self", ":", "rv", "+=", "1", "return", "rv" ]
https://github.com/lektor/lektor/blob/d5a7f22343572a991f2316c086f24005d0cbf0f8/lektor/db.py#L1142-L1147
wildfoundry/dataplicity-lomond
2e3235fb64f4c630ceb9a141f4d44977e89e7322
lomond/frame.py
python
Frame.build
(cls, opcode, payload=b'', fin=1, rsv1=0, rsv2=0, rsv3=0, mask=True, masking_key=None)
return frame_bytes
Build a WS frame.
Build a WS frame.
[ "Build", "a", "WS", "frame", "." ]
def build(cls, opcode, payload=b'', fin=1, rsv1=0, rsv2=0, rsv3=0, mask=True, masking_key=None): """Build a WS frame.""" # https://tools.ietf.org/html/rfc6455#section-5.2 payload = bytearray(payload) if isinstance(payload, bytes) else payload mask_bit = 1 << 7 if mask else 0 byte0 = fin << 7 | rsv1 << 6 | rsv2 << 5 | rsv3 << 4 | opcode length = len(payload) if length < 126: header_bytes = cls._pack8(byte0, mask_bit | length) elif length < (1 << 16): header_bytes = cls._pack16(byte0, mask_bit | 126, length) elif length < (1 << 63): header_bytes = cls._pack64(byte0, mask_bit | 127, length) else: # pragma: no cover # Can't send a payload > 2**63 bytes raise errors.FrameBuildError( 'payload is too large for a single frame' ) if mask: masking_key = ( make_masking_key() if masking_key is None else masking_key ) mask_payload(masking_key, payload) frame_bytes = b''.join(( header_bytes, cls._pack_mask(masking_key), bytes(payload) )) else: frame_bytes = header_bytes + bytes(payload) return frame_bytes
[ "def", "build", "(", "cls", ",", "opcode", ",", "payload", "=", "b''", ",", "fin", "=", "1", ",", "rsv1", "=", "0", ",", "rsv2", "=", "0", ",", "rsv3", "=", "0", ",", "mask", "=", "True", ",", "masking_key", "=", "None", ")", ":", "# https://tools.ietf.org/html/rfc6455#section-5.2", "payload", "=", "bytearray", "(", "payload", ")", "if", "isinstance", "(", "payload", ",", "bytes", ")", "else", "payload", "mask_bit", "=", "1", "<<", "7", "if", "mask", "else", "0", "byte0", "=", "fin", "<<", "7", "|", "rsv1", "<<", "6", "|", "rsv2", "<<", "5", "|", "rsv3", "<<", "4", "|", "opcode", "length", "=", "len", "(", "payload", ")", "if", "length", "<", "126", ":", "header_bytes", "=", "cls", ".", "_pack8", "(", "byte0", ",", "mask_bit", "|", "length", ")", "elif", "length", "<", "(", "1", "<<", "16", ")", ":", "header_bytes", "=", "cls", ".", "_pack16", "(", "byte0", ",", "mask_bit", "|", "126", ",", "length", ")", "elif", "length", "<", "(", "1", "<<", "63", ")", ":", "header_bytes", "=", "cls", ".", "_pack64", "(", "byte0", ",", "mask_bit", "|", "127", ",", "length", ")", "else", ":", "# pragma: no cover", "# Can't send a payload > 2**63 bytes", "raise", "errors", ".", "FrameBuildError", "(", "'payload is too large for a single frame'", ")", "if", "mask", ":", "masking_key", "=", "(", "make_masking_key", "(", ")", "if", "masking_key", "is", "None", "else", "masking_key", ")", "mask_payload", "(", "masking_key", ",", "payload", ")", "frame_bytes", "=", "b''", ".", "join", "(", "(", "header_bytes", ",", "cls", ".", "_pack_mask", "(", "masking_key", ")", ",", "bytes", "(", "payload", ")", ")", ")", "else", ":", "frame_bytes", "=", "header_bytes", "+", "bytes", "(", "payload", ")", "return", "frame_bytes" ]
https://github.com/wildfoundry/dataplicity-lomond/blob/2e3235fb64f4c630ceb9a141f4d44977e89e7322/lomond/frame.py#L65-L99
tensorflow/agents
1407001d242f7f77fb9407f9b1ac78bcd8f73a09
tf_agents/benchmark/utils.py
python
get_initial_values
(agent, check_values)
return [get_variable_value(agent, var_name) for var_name in check_values]
Returns the initial values.
Returns the initial values.
[ "Returns", "the", "initial", "values", "." ]
def get_initial_values(agent, check_values): """Returns the initial values.""" return [get_variable_value(agent, var_name) for var_name in check_values]
[ "def", "get_initial_values", "(", "agent", ",", "check_values", ")", ":", "return", "[", "get_variable_value", "(", "agent", ",", "var_name", ")", "for", "var_name", "in", "check_values", "]" ]
https://github.com/tensorflow/agents/blob/1407001d242f7f77fb9407f9b1ac78bcd8f73a09/tf_agents/benchmark/utils.py#L194-L196
pypyjs/pypyjs
4532320849881093635075db929240052300a844
tools/module_bundler.py
python
ModuleBundle._copy_py_file
(self, srcpath, dstpath)
Copy a python source file into the bundle. This method copes the contents of a python source file into the bundle. Since browsers usually expect strings in utf-8 format, it will try to detect source files in other encodings and transparently convert them to utf-8.
Copy a python source file into the bundle.
[ "Copy", "a", "python", "source", "file", "into", "the", "bundle", "." ]
def _copy_py_file(self, srcpath, dstpath): """Copy a python source file into the bundle. This method copes the contents of a python source file into the bundle. Since browsers usually expect strings in utf-8 format, it will try to detect source files in other encodings and transparently convert them to utf-8. """ # XXX TODO: copy in chunks, like shutil would do? with open(srcpath, "rb") as f_src: data = f_src.read() # Look for the encoding marker in the first two lines of the file. lines = data.split(b"\n", 2) encoding = None for i in range(2): if i >= len(lines): break if lines[i].startswith(b"#"): match = re.search(b"coding[:=]\\s*([-\\w.]+)", lines[i]) if match is not None: encoding = match.group(1) encodingName = encoding.decode("ascii") try: codecs.lookup(encodingName) except LookupError: encoding = None break # Write normalized data to output file. with open(dstpath, "wb") as f_dst: if encoding is None: f_dst.write(data) else: for j in range(i): f_dst.write(lines[j]) f_dst.write(b"\n") f_dst.write(lines[i].replace(encoding, b"utf-8")) f_dst.write(b"\n") for j in range(i + 1, len(lines)): f_dst.write(lines[j].decode(encodingName).encode("utf8")) if j < len(lines) - 1: f_dst.write(b"\n")
[ "def", "_copy_py_file", "(", "self", ",", "srcpath", ",", "dstpath", ")", ":", "# XXX TODO: copy in chunks, like shutil would do?", "with", "open", "(", "srcpath", ",", "\"rb\"", ")", "as", "f_src", ":", "data", "=", "f_src", ".", "read", "(", ")", "# Look for the encoding marker in the first two lines of the file.", "lines", "=", "data", ".", "split", "(", "b\"\\n\"", ",", "2", ")", "encoding", "=", "None", "for", "i", "in", "range", "(", "2", ")", ":", "if", "i", ">=", "len", "(", "lines", ")", ":", "break", "if", "lines", "[", "i", "]", ".", "startswith", "(", "b\"#\"", ")", ":", "match", "=", "re", ".", "search", "(", "b\"coding[:=]\\\\s*([-\\\\w.]+)\"", ",", "lines", "[", "i", "]", ")", "if", "match", "is", "not", "None", ":", "encoding", "=", "match", ".", "group", "(", "1", ")", "encodingName", "=", "encoding", ".", "decode", "(", "\"ascii\"", ")", "try", ":", "codecs", ".", "lookup", "(", "encodingName", ")", "except", "LookupError", ":", "encoding", "=", "None", "break", "# Write normalized data to output file.", "with", "open", "(", "dstpath", ",", "\"wb\"", ")", "as", "f_dst", ":", "if", "encoding", "is", "None", ":", "f_dst", ".", "write", "(", "data", ")", "else", ":", "for", "j", "in", "range", "(", "i", ")", ":", "f_dst", ".", "write", "(", "lines", "[", "j", "]", ")", "f_dst", ".", "write", "(", "b\"\\n\"", ")", "f_dst", ".", "write", "(", "lines", "[", "i", "]", ".", "replace", "(", "encoding", ",", "b\"utf-8\"", ")", ")", "f_dst", ".", "write", "(", "b\"\\n\"", ")", "for", "j", "in", "range", "(", "i", "+", "1", ",", "len", "(", "lines", ")", ")", ":", "f_dst", ".", "write", "(", "lines", "[", "j", "]", ".", "decode", "(", "encodingName", ")", ".", "encode", "(", "\"utf8\"", ")", ")", "if", "j", "<", "len", "(", "lines", ")", "-", "1", ":", "f_dst", ".", "write", "(", "b\"\\n\"", ")" ]
https://github.com/pypyjs/pypyjs/blob/4532320849881093635075db929240052300a844/tools/module_bundler.py#L525-L565
bcbio/bcbio-nextgen
c80f9b6b1be3267d1f981b7035e3b72441d258f2
bcbio/variation/cortex.py
python
_run_cortex_on_region
(region, align_bam, ref_file, work_dir, out_file_base, config)
return [region[0], int(region[1]), int(region[2]), out_file]
Run cortex on a specified chromosome start/end region.
Run cortex on a specified chromosome start/end region.
[ "Run", "cortex", "on", "a", "specified", "chromosome", "start", "/", "end", "region", "." ]
def _run_cortex_on_region(region, align_bam, ref_file, work_dir, out_file_base, config): """Run cortex on a specified chromosome start/end region. """ kmers = [31, 51, 71] min_reads = 1750 cortex_dir = config_utils.get_program("cortex", config, "dir") stampy_dir = config_utils.get_program("stampy", config, "dir") vcftools_dir = config_utils.get_program("vcftools", config, "dir") if cortex_dir is None or stampy_dir is None: raise ValueError("cortex_var requires path to pre-built cortex and stampy") region_str = "{0}-{1}-{2}".format(*region) base_dir = safe_makedir(os.path.join(work_dir, region_str)) try: out_vcf_base = os.path.join(base_dir, "{0}-{1}".format( os.path.splitext(os.path.basename(out_file_base))[0], region_str)) out_file = os.path.join(work_dir, os.path.basename("{0}.vcf".format(out_vcf_base))) if not file_exists(out_file): fastq = _get_fastq_in_region(region, align_bam, out_vcf_base) if _count_fastq_reads(fastq, min_reads) < min_reads: vcfutils.write_empty_vcf(out_file) else: local_ref, genome_size = _get_local_ref(region, ref_file, out_vcf_base) indexes = _index_local_ref(local_ref, cortex_dir, stampy_dir, kmers) cortex_out = _run_cortex(fastq, indexes, {"kmers": kmers, "genome_size": genome_size, "sample": get_sample_name(align_bam)}, out_vcf_base, {"cortex": cortex_dir, "stampy": stampy_dir, "vcftools": vcftools_dir}, config) if cortex_out: _remap_cortex_out(cortex_out, region, out_file) else: vcfutils.write_empty_vcf(out_file) finally: if os.path.exists(base_dir): shutil.rmtree(base_dir) return [region[0], int(region[1]), int(region[2]), out_file]
[ "def", "_run_cortex_on_region", "(", "region", ",", "align_bam", ",", "ref_file", ",", "work_dir", ",", "out_file_base", ",", "config", ")", ":", "kmers", "=", "[", "31", ",", "51", ",", "71", "]", "min_reads", "=", "1750", "cortex_dir", "=", "config_utils", ".", "get_program", "(", "\"cortex\"", ",", "config", ",", "\"dir\"", ")", "stampy_dir", "=", "config_utils", ".", "get_program", "(", "\"stampy\"", ",", "config", ",", "\"dir\"", ")", "vcftools_dir", "=", "config_utils", ".", "get_program", "(", "\"vcftools\"", ",", "config", ",", "\"dir\"", ")", "if", "cortex_dir", "is", "None", "or", "stampy_dir", "is", "None", ":", "raise", "ValueError", "(", "\"cortex_var requires path to pre-built cortex and stampy\"", ")", "region_str", "=", "\"{0}-{1}-{2}\"", ".", "format", "(", "*", "region", ")", "base_dir", "=", "safe_makedir", "(", "os", ".", "path", ".", "join", "(", "work_dir", ",", "region_str", ")", ")", "try", ":", "out_vcf_base", "=", "os", ".", "path", ".", "join", "(", "base_dir", ",", "\"{0}-{1}\"", ".", "format", "(", "os", ".", "path", ".", "splitext", "(", "os", ".", "path", ".", "basename", "(", "out_file_base", ")", ")", "[", "0", "]", ",", "region_str", ")", ")", "out_file", "=", "os", ".", "path", ".", "join", "(", "work_dir", ",", "os", ".", "path", ".", "basename", "(", "\"{0}.vcf\"", ".", "format", "(", "out_vcf_base", ")", ")", ")", "if", "not", "file_exists", "(", "out_file", ")", ":", "fastq", "=", "_get_fastq_in_region", "(", "region", ",", "align_bam", ",", "out_vcf_base", ")", "if", "_count_fastq_reads", "(", "fastq", ",", "min_reads", ")", "<", "min_reads", ":", "vcfutils", ".", "write_empty_vcf", "(", "out_file", ")", "else", ":", "local_ref", ",", "genome_size", "=", "_get_local_ref", "(", "region", ",", "ref_file", ",", "out_vcf_base", ")", "indexes", "=", "_index_local_ref", "(", "local_ref", ",", "cortex_dir", ",", "stampy_dir", ",", "kmers", ")", "cortex_out", "=", "_run_cortex", "(", "fastq", ",", "indexes", ",", "{", "\"kmers\"", ":", "kmers", ",", "\"genome_size\"", ":", "genome_size", ",", "\"sample\"", ":", "get_sample_name", "(", "align_bam", ")", "}", ",", "out_vcf_base", ",", "{", "\"cortex\"", ":", "cortex_dir", ",", "\"stampy\"", ":", "stampy_dir", ",", "\"vcftools\"", ":", "vcftools_dir", "}", ",", "config", ")", "if", "cortex_out", ":", "_remap_cortex_out", "(", "cortex_out", ",", "region", ",", "out_file", ")", "else", ":", "vcfutils", ".", "write_empty_vcf", "(", "out_file", ")", "finally", ":", "if", "os", ".", "path", ".", "exists", "(", "base_dir", ")", ":", "shutil", ".", "rmtree", "(", "base_dir", ")", "return", "[", "region", "[", "0", "]", ",", "int", "(", "region", "[", "1", "]", ")", ",", "int", "(", "region", "[", "2", "]", ")", ",", "out_file", "]" ]
https://github.com/bcbio/bcbio-nextgen/blob/c80f9b6b1be3267d1f981b7035e3b72441d258f2/bcbio/variation/cortex.py#L122-L157
jamesyonan/brenda
3fdcf6d55baf3138ddfa4812c2527441be341267
brenda/aws.py
python
format_s3_url
(bucktup, s3name)
return "s3://%s/%s%s" % (bucktup[1][0], bucktup[1][1], s3name)
bucktup is the return tuple of get_s3_output_bucket_name
bucktup is the return tuple of get_s3_output_bucket_name
[ "bucktup", "is", "the", "return", "tuple", "of", "get_s3_output_bucket_name" ]
def format_s3_url(bucktup, s3name): """ bucktup is the return tuple of get_s3_output_bucket_name """ return "s3://%s/%s%s" % (bucktup[1][0], bucktup[1][1], s3name)
[ "def", "format_s3_url", "(", "bucktup", ",", "s3name", ")", ":", "return", "\"s3://%s/%s%s\"", "%", "(", "bucktup", "[", "1", "]", "[", "0", "]", ",", "bucktup", "[", "1", "]", "[", "1", "]", ",", "s3name", ")" ]
https://github.com/jamesyonan/brenda/blob/3fdcf6d55baf3138ddfa4812c2527441be341267/brenda/aws.py#L103-L107
tperol/ConvNetQuake
9d8bb6d41e5e3185edf3a3fc716539b910e17cfe
bin/viz/misclassified_loc.py
python
fetch_streams_list
(datadir)
return fnames
Get the list of streams to analyze
Get the list of streams to analyze
[ "Get", "the", "list", "of", "streams", "to", "analyze" ]
def fetch_streams_list(datadir): """Get the list of streams to analyze""" fnames = [] for root, dirs, files in os.walk(datadir): for f in files: if f.endswith(".mseed"): fnames.append(os.path.join(root, f)) return fnames
[ "def", "fetch_streams_list", "(", "datadir", ")", ":", "fnames", "=", "[", "]", "for", "root", ",", "dirs", ",", "files", "in", "os", ".", "walk", "(", "datadir", ")", ":", "for", "f", "in", "files", ":", "if", "f", ".", "endswith", "(", "\".mseed\"", ")", ":", "fnames", ".", "append", "(", "os", ".", "path", ".", "join", "(", "root", ",", "f", ")", ")", "return", "fnames" ]
https://github.com/tperol/ConvNetQuake/blob/9d8bb6d41e5e3185edf3a3fc716539b910e17cfe/bin/viz/misclassified_loc.py#L76-L83
rogerbinns/apsw
00a7eb5138f2f00976f0c76cb51906afecbe298f
tools/apswtrace.py
python
APSWTracer.longestrunningindividual
(self, howmany)
return res
[]
def longestrunningindividual(self, howmany): res=[] for k,v in self.timings.items(): for t in v: res.append( (t, k) ) res.sort() res.reverse() res=res[:howmany] return res
[ "def", "longestrunningindividual", "(", "self", ",", "howmany", ")", ":", "res", "=", "[", "]", "for", "k", ",", "v", "in", "self", ".", "timings", ".", "items", "(", ")", ":", "for", "t", "in", "v", ":", "res", ".", "append", "(", "(", "t", ",", "k", ")", ")", "res", ".", "sort", "(", ")", "res", ".", "reverse", "(", ")", "res", "=", "res", "[", ":", "howmany", "]", "return", "res" ]
https://github.com/rogerbinns/apsw/blob/00a7eb5138f2f00976f0c76cb51906afecbe298f/tools/apswtrace.py#L228-L236
theotherp/nzbhydra
4b03d7f769384b97dfc60dade4806c0fc987514e
libs/sndhdr.py
python
whathdr
(filename)
return None
Recognize sound headers
Recognize sound headers
[ "Recognize", "sound", "headers" ]
def whathdr(filename): """Recognize sound headers""" f = open(filename, 'rb') h = f.read(512) for tf in tests: res = tf(h, f) if res: return res return None
[ "def", "whathdr", "(", "filename", ")", ":", "f", "=", "open", "(", "filename", ",", "'rb'", ")", "h", "=", "f", ".", "read", "(", "512", ")", "for", "tf", "in", "tests", ":", "res", "=", "tf", "(", "h", ",", "f", ")", "if", "res", ":", "return", "res", "return", "None" ]
https://github.com/theotherp/nzbhydra/blob/4b03d7f769384b97dfc60dade4806c0fc987514e/libs/sndhdr.py#L41-L49
mu-editor/mu
5a5d7723405db588f67718a63a0ec0ecabebae33
utils/flask_api.py
python
BottleSpider.parse
(self, response)
Scrapes the list of modules associated with Bottle. Causes scrapy to follow the links to the module docs and uses a different parser to extract the API information contained therein.
Scrapes the list of modules associated with Bottle. Causes scrapy to follow the links to the module docs and uses a different parser to extract the API information contained therein.
[ "Scrapes", "the", "list", "of", "modules", "associated", "with", "Bottle", ".", "Causes", "scrapy", "to", "follow", "the", "links", "to", "the", "module", "docs", "and", "uses", "a", "different", "parser", "to", "extract", "the", "API", "information", "contained", "therein", "." ]
def parse(self, response): """ Scrapes the list of modules associated with Bottle. Causes scrapy to follow the links to the module docs and uses a different parser to extract the API information contained therein. """ # Find all the function definitions on the page: for func in response.css("dl.function"): # Class details are always first items in dl. func_spec = func.css("dt")[0] func_doc = func.css("dd")[0] # Function name is always first dt func_name = BeautifulSoup( func_spec.css("code.descname").extract()[0], "html.parser" ).text # Args into function args = [] for ems in func_spec.css("em"): args.append( ems.extract().replace("<em>", "").replace("</em>", "") ) # Function description. soup = BeautifulSoup(func_doc.extract(), "html.parser") d = self.to_dict(func_name, args, soup.text) if d: yield d # Find all the class definitions on the page: for classes in response.css("dl.class"): # Class details are always first items in dl. class_spec = classes.css("dt")[0] class_doc = classes.css("dd")[0] # Class name is always first dt class_name = BeautifulSoup( class_spec.css("code.descname").extract()[0], "html.parser" ).text # Args into __init__ init_args = [] for ems in class_spec.css("em"): props = "property" in ems.css("::attr(class)").extract() if not props: init_args.append( ems.extract().replace("<em>", "").replace("</em>", "") ) # Class description. Everything up to and including the field-list. soup = BeautifulSoup(class_doc.extract(), "html.parser") contents = soup.contents[0].contents description = "" for child in contents: if child.name == "p": description += child.text + "\n\n" if child.name == "table": raw = child.text rows = [r.strip() for r in raw.split("/n") if r.strip()] description += "\n" description += "\n".join(rows) break if child.name == "dl": break d = self.to_dict(class_name, init_args, description) if d: yield d # Remaining dt are methods or attributes for methods in classes.css("dl.method"): # Parse and yield methods. method_name = BeautifulSoup( methods.css("code.descname").extract()[0], "html.parser" ).text if method_name.startswith("__"): break method_name = class_name + "." + method_name method_args = [] for ems in methods.css("em"): method_args.append( ems.extract().replace("<em>", "").replace("</em>", "") ) description = BeautifulSoup( methods.css("dd")[0].extract(), "html.parser" ).text d = self.to_dict(method_name, method_args, description) if d: yield d for data in classes.css("dl.attribute"): name = BeautifulSoup( data.css("code.descname").extract()[0], "html.parser" ).text name = class_name + "." + name description = BeautifulSoup( data.css("dd")[0].extract(), "html.parser" ).text d = self.to_dict(name, None, description) if d: yield d for data in classes.css("dl.data"): name = BeautifulSoup( data.css("code.descname").extract()[0], "html.parser" ).text name = class_name + "." + name description = BeautifulSoup( data.css("dd")[0].extract(), "html.parser" ).text d = self.to_dict(name, None, description) if d: yield d
[ "def", "parse", "(", "self", ",", "response", ")", ":", "# Find all the function definitions on the page:", "for", "func", "in", "response", ".", "css", "(", "\"dl.function\"", ")", ":", "# Class details are always first items in dl.", "func_spec", "=", "func", ".", "css", "(", "\"dt\"", ")", "[", "0", "]", "func_doc", "=", "func", ".", "css", "(", "\"dd\"", ")", "[", "0", "]", "# Function name is always first dt", "func_name", "=", "BeautifulSoup", "(", "func_spec", ".", "css", "(", "\"code.descname\"", ")", ".", "extract", "(", ")", "[", "0", "]", ",", "\"html.parser\"", ")", ".", "text", "# Args into function", "args", "=", "[", "]", "for", "ems", "in", "func_spec", ".", "css", "(", "\"em\"", ")", ":", "args", ".", "append", "(", "ems", ".", "extract", "(", ")", ".", "replace", "(", "\"<em>\"", ",", "\"\"", ")", ".", "replace", "(", "\"</em>\"", ",", "\"\"", ")", ")", "# Function description.", "soup", "=", "BeautifulSoup", "(", "func_doc", ".", "extract", "(", ")", ",", "\"html.parser\"", ")", "d", "=", "self", ".", "to_dict", "(", "func_name", ",", "args", ",", "soup", ".", "text", ")", "if", "d", ":", "yield", "d", "# Find all the class definitions on the page:", "for", "classes", "in", "response", ".", "css", "(", "\"dl.class\"", ")", ":", "# Class details are always first items in dl.", "class_spec", "=", "classes", ".", "css", "(", "\"dt\"", ")", "[", "0", "]", "class_doc", "=", "classes", ".", "css", "(", "\"dd\"", ")", "[", "0", "]", "# Class name is always first dt", "class_name", "=", "BeautifulSoup", "(", "class_spec", ".", "css", "(", "\"code.descname\"", ")", ".", "extract", "(", ")", "[", "0", "]", ",", "\"html.parser\"", ")", ".", "text", "# Args into __init__", "init_args", "=", "[", "]", "for", "ems", "in", "class_spec", ".", "css", "(", "\"em\"", ")", ":", "props", "=", "\"property\"", "in", "ems", ".", "css", "(", "\"::attr(class)\"", ")", ".", "extract", "(", ")", "if", "not", "props", ":", "init_args", ".", "append", "(", "ems", ".", "extract", "(", ")", ".", "replace", "(", "\"<em>\"", ",", "\"\"", ")", ".", "replace", "(", "\"</em>\"", ",", "\"\"", ")", ")", "# Class description. Everything up to and including the field-list.", "soup", "=", "BeautifulSoup", "(", "class_doc", ".", "extract", "(", ")", ",", "\"html.parser\"", ")", "contents", "=", "soup", ".", "contents", "[", "0", "]", ".", "contents", "description", "=", "\"\"", "for", "child", "in", "contents", ":", "if", "child", ".", "name", "==", "\"p\"", ":", "description", "+=", "child", ".", "text", "+", "\"\\n\\n\"", "if", "child", ".", "name", "==", "\"table\"", ":", "raw", "=", "child", ".", "text", "rows", "=", "[", "r", ".", "strip", "(", ")", "for", "r", "in", "raw", ".", "split", "(", "\"/n\"", ")", "if", "r", ".", "strip", "(", ")", "]", "description", "+=", "\"\\n\"", "description", "+=", "\"\\n\"", ".", "join", "(", "rows", ")", "break", "if", "child", ".", "name", "==", "\"dl\"", ":", "break", "d", "=", "self", ".", "to_dict", "(", "class_name", ",", "init_args", ",", "description", ")", "if", "d", ":", "yield", "d", "# Remaining dt are methods or attributes", "for", "methods", "in", "classes", ".", "css", "(", "\"dl.method\"", ")", ":", "# Parse and yield methods.", "method_name", "=", "BeautifulSoup", "(", "methods", ".", "css", "(", "\"code.descname\"", ")", ".", "extract", "(", ")", "[", "0", "]", ",", "\"html.parser\"", ")", ".", "text", "if", "method_name", ".", "startswith", "(", "\"__\"", ")", ":", "break", "method_name", "=", "class_name", "+", "\".\"", "+", "method_name", "method_args", "=", "[", "]", "for", "ems", "in", "methods", ".", "css", "(", "\"em\"", ")", ":", "method_args", ".", "append", "(", "ems", ".", "extract", "(", ")", ".", "replace", "(", "\"<em>\"", ",", "\"\"", ")", ".", "replace", "(", "\"</em>\"", ",", "\"\"", ")", ")", "description", "=", "BeautifulSoup", "(", "methods", ".", "css", "(", "\"dd\"", ")", "[", "0", "]", ".", "extract", "(", ")", ",", "\"html.parser\"", ")", ".", "text", "d", "=", "self", ".", "to_dict", "(", "method_name", ",", "method_args", ",", "description", ")", "if", "d", ":", "yield", "d", "for", "data", "in", "classes", ".", "css", "(", "\"dl.attribute\"", ")", ":", "name", "=", "BeautifulSoup", "(", "data", ".", "css", "(", "\"code.descname\"", ")", ".", "extract", "(", ")", "[", "0", "]", ",", "\"html.parser\"", ")", ".", "text", "name", "=", "class_name", "+", "\".\"", "+", "name", "description", "=", "BeautifulSoup", "(", "data", ".", "css", "(", "\"dd\"", ")", "[", "0", "]", ".", "extract", "(", ")", ",", "\"html.parser\"", ")", ".", "text", "d", "=", "self", ".", "to_dict", "(", "name", ",", "None", ",", "description", ")", "if", "d", ":", "yield", "d", "for", "data", "in", "classes", ".", "css", "(", "\"dl.data\"", ")", ":", "name", "=", "BeautifulSoup", "(", "data", ".", "css", "(", "\"code.descname\"", ")", ".", "extract", "(", ")", "[", "0", "]", ",", "\"html.parser\"", ")", ".", "text", "name", "=", "class_name", "+", "\".\"", "+", "name", "description", "=", "BeautifulSoup", "(", "data", ".", "css", "(", "\"dd\"", ")", "[", "0", "]", ".", "extract", "(", ")", ",", "\"html.parser\"", ")", ".", "text", "d", "=", "self", ".", "to_dict", "(", "name", ",", "None", ",", "description", ")", "if", "d", ":", "yield", "d" ]
https://github.com/mu-editor/mu/blob/5a5d7723405db588f67718a63a0ec0ecabebae33/utils/flask_api.py#L20-L122
tenpy/tenpy
bbdd3dbbdb511948eb0e6ba7ff619ac6ca657fff
tenpy/algorithms/exact_diag.py
python
ExactDiag.exp_H
(self, dt)
return npc.tensordot(self.V.scale_axis(np.exp(-1.j * dt * self.E), 'ps*'), self.V.conj(), axes=['ps*', 'ps'])
Return ``U(dt) := exp(-i H dt)``.
Return ``U(dt) := exp(-i H dt)``.
[ "Return", "U", "(", "dt", ")", ":", "=", "exp", "(", "-", "i", "H", "dt", ")", "." ]
def exp_H(self, dt): """Return ``U(dt) := exp(-i H dt)``.""" if self.E is None or self.V is None: raise ValueError("You need to call `full_diagonalization` first!") return npc.tensordot(self.V.scale_axis(np.exp(-1.j * dt * self.E), 'ps*'), self.V.conj(), axes=['ps*', 'ps'])
[ "def", "exp_H", "(", "self", ",", "dt", ")", ":", "if", "self", ".", "E", "is", "None", "or", "self", ".", "V", "is", "None", ":", "raise", "ValueError", "(", "\"You need to call `full_diagonalization` first!\"", ")", "return", "npc", ".", "tensordot", "(", "self", ".", "V", ".", "scale_axis", "(", "np", ".", "exp", "(", "-", "1.j", "*", "dt", "*", "self", ".", "E", ")", ",", "'ps*'", ")", ",", "self", ".", "V", ".", "conj", "(", ")", ",", "axes", "=", "[", "'ps*'", ",", "'ps'", "]", ")" ]
https://github.com/tenpy/tenpy/blob/bbdd3dbbdb511948eb0e6ba7ff619ac6ca657fff/tenpy/algorithms/exact_diag.py#L221-L227
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/interfaces/mupad.py
python
Mupad.__init__
(self, maxread=None, script_subdirectory=None, server=None, server_tmpdir=None, logfile=None)
Create an instance of the MuPAD interpreter. EXAMPLES:: sage: mupad == loads(dumps(mupad)) # optional - mupad True
Create an instance of the MuPAD interpreter.
[ "Create", "an", "instance", "of", "the", "MuPAD", "interpreter", "." ]
def __init__(self, maxread=None, script_subdirectory=None, server=None, server_tmpdir=None, logfile=None): """ Create an instance of the MuPAD interpreter. EXAMPLES:: sage: mupad == loads(dumps(mupad)) # optional - mupad True """ Expect.__init__(self, name = 'MuPAD', prompt = PROMPT, # the -U SAGE=TRUE allows for MuPAD programs to test whether they are run from Sage command = "mupkern -P e -U SAGE=TRUE", script_subdirectory = script_subdirectory, server = server, server_tmpdir = server_tmpdir, restart_on_ctrlc = False, verbose_start = False, logfile = None)
[ "def", "__init__", "(", "self", ",", "maxread", "=", "None", ",", "script_subdirectory", "=", "None", ",", "server", "=", "None", ",", "server_tmpdir", "=", "None", ",", "logfile", "=", "None", ")", ":", "Expect", ".", "__init__", "(", "self", ",", "name", "=", "'MuPAD'", ",", "prompt", "=", "PROMPT", ",", "# the -U SAGE=TRUE allows for MuPAD programs to test whether they are run from Sage", "command", "=", "\"mupkern -P e -U SAGE=TRUE\"", ",", "script_subdirectory", "=", "script_subdirectory", ",", "server", "=", "server", ",", "server_tmpdir", "=", "server_tmpdir", ",", "restart_on_ctrlc", "=", "False", ",", "verbose_start", "=", "False", ",", "logfile", "=", "None", ")" ]
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/interfaces/mupad.py#L111-L130
dgilland/pydash
24ad0e43b51b367d00447c45baa68c9c03ad1a52
src/pydash/utilities.py
python
base_range
(*args, **kwargs)
return gen()
Yield range values.
Yield range values.
[ "Yield", "range", "values", "." ]
def base_range(*args, **kwargs): """Yield range values.""" from_right = kwargs.get("from_right", False) if len(args) >= 3: args = args[:3] elif len(args) == 2: args = (args[0], args[1], None) elif len(args) == 1: args = (0, args[0], None) if args and args[2] is None: check_args = args[:2] else: check_args = args for arg in check_args: if not isinstance(arg, int): # pragma: no cover raise TypeError(f"range cannot interpret {type(arg).__name__!r} object as an integer") def gen(): if not args: return start, stop, step = args if step is None: step = 1 if start < stop else -1 length = int(max([math.ceil((stop - start) / (step or 1)), 0])) if from_right: start += (step * length) - step step *= -1 while length: yield start start += step length -= 1 return gen()
[ "def", "base_range", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "from_right", "=", "kwargs", ".", "get", "(", "\"from_right\"", ",", "False", ")", "if", "len", "(", "args", ")", ">=", "3", ":", "args", "=", "args", "[", ":", "3", "]", "elif", "len", "(", "args", ")", "==", "2", ":", "args", "=", "(", "args", "[", "0", "]", ",", "args", "[", "1", "]", ",", "None", ")", "elif", "len", "(", "args", ")", "==", "1", ":", "args", "=", "(", "0", ",", "args", "[", "0", "]", ",", "None", ")", "if", "args", "and", "args", "[", "2", "]", "is", "None", ":", "check_args", "=", "args", "[", ":", "2", "]", "else", ":", "check_args", "=", "args", "for", "arg", "in", "check_args", ":", "if", "not", "isinstance", "(", "arg", ",", "int", ")", ":", "# pragma: no cover", "raise", "TypeError", "(", "f\"range cannot interpret {type(arg).__name__!r} object as an integer\"", ")", "def", "gen", "(", ")", ":", "if", "not", "args", ":", "return", "start", ",", "stop", ",", "step", "=", "args", "if", "step", "is", "None", ":", "step", "=", "1", "if", "start", "<", "stop", "else", "-", "1", "length", "=", "int", "(", "max", "(", "[", "math", ".", "ceil", "(", "(", "stop", "-", "start", ")", "/", "(", "step", "or", "1", ")", ")", ",", "0", "]", ")", ")", "if", "from_right", ":", "start", "+=", "(", "step", "*", "length", ")", "-", "step", "step", "*=", "-", "1", "while", "length", ":", "yield", "start", "start", "+=", "step", "length", "-=", "1", "return", "gen", "(", ")" ]
https://github.com/dgilland/pydash/blob/24ad0e43b51b367d00447c45baa68c9c03ad1a52/src/pydash/utilities.py#L1294-L1335
pantsbuild/pex
473c6ac732ed4bc338b4b20a9ec930d1d722c9b4
pex/vendor/_vendored/pip/pip/_vendor/pkg_resources/__init__.py
python
Distribution.__repr__
(self)
[]
def __repr__(self): if self.location: return "%s (%s)" % (self, self.location) else: return str(self)
[ "def", "__repr__", "(", "self", ")", ":", "if", "self", ".", "location", ":", "return", "\"%s (%s)\"", "%", "(", "self", ",", "self", ".", "location", ")", "else", ":", "return", "str", "(", "self", ")" ]
https://github.com/pantsbuild/pex/blob/473c6ac732ed4bc338b4b20a9ec930d1d722c9b4/pex/vendor/_vendored/pip/pip/_vendor/pkg_resources/__init__.py#L2798-L2802
IdentityPython/pysaml2
6badb32d212257bd83ffcc816f9b625f68281b47
src/saml2/authn_context/ippword.py
python
activation_pin_type__from_string
(xml_string)
return saml2.create_class_from_xml_string(ActivationPinType_, xml_string)
[]
def activation_pin_type__from_string(xml_string): return saml2.create_class_from_xml_string(ActivationPinType_, xml_string)
[ "def", "activation_pin_type__from_string", "(", "xml_string", ")", ":", "return", "saml2", ".", "create_class_from_xml_string", "(", "ActivationPinType_", ",", "xml_string", ")" ]
https://github.com/IdentityPython/pysaml2/blob/6badb32d212257bd83ffcc816f9b625f68281b47/src/saml2/authn_context/ippword.py#L1619-L1620
JetBrains/python-skeletons
95ad24b666e475998e5d1cc02ed53a2188036167
builtins.py
python
bytes.isalnum
(self)
return False
Return true if all characters in the string are alphanumeric and there is at least one character, false otherwise. :rtype: bool
Return true if all characters in the string are alphanumeric and there is at least one character, false otherwise.
[ "Return", "true", "if", "all", "characters", "in", "the", "string", "are", "alphanumeric", "and", "there", "is", "at", "least", "one", "character", "false", "otherwise", "." ]
def isalnum(self): """Return true if all characters in the string are alphanumeric and there is at least one character, false otherwise. :rtype: bool """ return False
[ "def", "isalnum", "(", "self", ")", ":", "return", "False" ]
https://github.com/JetBrains/python-skeletons/blob/95ad24b666e475998e5d1cc02ed53a2188036167/builtins.py#L1108-L1114
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_hxb2/lib/python3.5/site-packages/pip/exceptions.py
python
HashErrors.__nonzero__
(self)
return bool(self.errors)
[]
def __nonzero__(self): return bool(self.errors)
[ "def", "__nonzero__", "(", "self", ")", ":", "return", "bool", "(", "self", ".", "errors", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_hxb2/lib/python3.5/site-packages/pip/exceptions.py#L72-L73
dBeker/Faster-RCNN-TensorFlow-Python3
027e5603551b3b9053042a113b4c7be9579dbb4a
data/coco/PythonAPI/pycocotools/cocoeval.py
python
COCOeval.evaluate
(self)
Run per image evaluation on given images and store results (a list of dict) in self.evalImgs :return: None
Run per image evaluation on given images and store results (a list of dict) in self.evalImgs :return: None
[ "Run", "per", "image", "evaluation", "on", "given", "images", "and", "store", "results", "(", "a", "list", "of", "dict", ")", "in", "self", ".", "evalImgs", ":", "return", ":", "None" ]
def evaluate(self): ''' Run per image evaluation on given images and store results (a list of dict) in self.evalImgs :return: None ''' tic = time.time() print('Running per image evaluation...') p = self.params # add backward compatibility if useSegm is specified in params if not p.useSegm is None: p.iouType = 'segm' if p.useSegm == 1 else 'bbox' print('useSegm (deprecated) is not None. Running {} evaluation'.format(p.iouType)) print('Evaluate annotation type *{}*'.format(p.iouType)) p.imgIds = list(np.unique(p.imgIds)) if p.useCats: p.catIds = list(np.unique(p.catIds)) p.maxDets = sorted(p.maxDets) self.params=p self._prepare() # loop through images, area range, max detection number catIds = p.catIds if p.useCats else [-1] if p.iouType == 'segm' or p.iouType == 'bbox': computeIoU = self.computeIoU elif p.iouType == 'keypoints': computeIoU = self.computeOks self.ious = {(imgId, catId): computeIoU(imgId, catId) \ for imgId in p.imgIds for catId in catIds} evaluateImg = self.evaluateImg maxDet = p.maxDets[-1] self.evalImgs = [evaluateImg(imgId, catId, areaRng, maxDet) for catId in catIds for areaRng in p.areaRng for imgId in p.imgIds ] self._paramsEval = copy.deepcopy(self.params) toc = time.time() print('DONE (t={:0.2f}s).'.format(toc-tic))
[ "def", "evaluate", "(", "self", ")", ":", "tic", "=", "time", ".", "time", "(", ")", "print", "(", "'Running per image evaluation...'", ")", "p", "=", "self", ".", "params", "# add backward compatibility if useSegm is specified in params", "if", "not", "p", ".", "useSegm", "is", "None", ":", "p", ".", "iouType", "=", "'segm'", "if", "p", ".", "useSegm", "==", "1", "else", "'bbox'", "print", "(", "'useSegm (deprecated) is not None. Running {} evaluation'", ".", "format", "(", "p", ".", "iouType", ")", ")", "print", "(", "'Evaluate annotation type *{}*'", ".", "format", "(", "p", ".", "iouType", ")", ")", "p", ".", "imgIds", "=", "list", "(", "np", ".", "unique", "(", "p", ".", "imgIds", ")", ")", "if", "p", ".", "useCats", ":", "p", ".", "catIds", "=", "list", "(", "np", ".", "unique", "(", "p", ".", "catIds", ")", ")", "p", ".", "maxDets", "=", "sorted", "(", "p", ".", "maxDets", ")", "self", ".", "params", "=", "p", "self", ".", "_prepare", "(", ")", "# loop through images, area range, max detection number", "catIds", "=", "p", ".", "catIds", "if", "p", ".", "useCats", "else", "[", "-", "1", "]", "if", "p", ".", "iouType", "==", "'segm'", "or", "p", ".", "iouType", "==", "'bbox'", ":", "computeIoU", "=", "self", ".", "computeIoU", "elif", "p", ".", "iouType", "==", "'keypoints'", ":", "computeIoU", "=", "self", ".", "computeOks", "self", ".", "ious", "=", "{", "(", "imgId", ",", "catId", ")", ":", "computeIoU", "(", "imgId", ",", "catId", ")", "for", "imgId", "in", "p", ".", "imgIds", "for", "catId", "in", "catIds", "}", "evaluateImg", "=", "self", ".", "evaluateImg", "maxDet", "=", "p", ".", "maxDets", "[", "-", "1", "]", "self", ".", "evalImgs", "=", "[", "evaluateImg", "(", "imgId", ",", "catId", ",", "areaRng", ",", "maxDet", ")", "for", "catId", "in", "catIds", "for", "areaRng", "in", "p", ".", "areaRng", "for", "imgId", "in", "p", ".", "imgIds", "]", "self", ".", "_paramsEval", "=", "copy", ".", "deepcopy", "(", "self", ".", "params", ")", "toc", "=", "time", ".", "time", "(", ")", "print", "(", "'DONE (t={:0.2f}s).'", ".", "format", "(", "toc", "-", "tic", ")", ")" ]
https://github.com/dBeker/Faster-RCNN-TensorFlow-Python3/blob/027e5603551b3b9053042a113b4c7be9579dbb4a/data/coco/PythonAPI/pycocotools/cocoeval.py#L122-L162
openshift/openshift-tools
1188778e728a6e4781acf728123e5b356380fe6f
scripts/monitoring/cron-send-url-check.py
python
UrlCheck.run
(self)
Main function to run the check
Main function to run the check
[ "Main", "function", "to", "run", "the", "check" ]
def run(self): """Main function to run the check""" logging.info('Starting url checker...') try: with open(self.args.configfile, 'r') as configfile: self.config = yaml.load(configfile) logging.debug('Loaded config file: %s', self.config) except IOError: logging.error('There was a problem opening the config file. Exiting.') sys.exit(1) return_data = {} self.metrics = MetricSender(verbose=self.args.verbose, debug=self.args.debug) for itemtocheck in self.config['urls_to_check']: if self.check_url(itemtocheck['url']): return_data[itemtocheck['zab_key']] = 1 else: return_data[itemtocheck['zab_key']] = 0 logger.debug('return_data before adding to sender: %s', return_data) self.metrics.add_metric(return_data) logger.info('self metrics before sending to zabbix %s', self.metrics.active_senders[0].unique_metrics) if self.args.dry_run: self.metrics.print_unique_metrics() else: self.metrics.send_metrics()
[ "def", "run", "(", "self", ")", ":", "logging", ".", "info", "(", "'Starting url checker...'", ")", "try", ":", "with", "open", "(", "self", ".", "args", ".", "configfile", ",", "'r'", ")", "as", "configfile", ":", "self", ".", "config", "=", "yaml", ".", "load", "(", "configfile", ")", "logging", ".", "debug", "(", "'Loaded config file: %s'", ",", "self", ".", "config", ")", "except", "IOError", ":", "logging", ".", "error", "(", "'There was a problem opening the config file. Exiting.'", ")", "sys", ".", "exit", "(", "1", ")", "return_data", "=", "{", "}", "self", ".", "metrics", "=", "MetricSender", "(", "verbose", "=", "self", ".", "args", ".", "verbose", ",", "debug", "=", "self", ".", "args", ".", "debug", ")", "for", "itemtocheck", "in", "self", ".", "config", "[", "'urls_to_check'", "]", ":", "if", "self", ".", "check_url", "(", "itemtocheck", "[", "'url'", "]", ")", ":", "return_data", "[", "itemtocheck", "[", "'zab_key'", "]", "]", "=", "1", "else", ":", "return_data", "[", "itemtocheck", "[", "'zab_key'", "]", "]", "=", "0", "logger", ".", "debug", "(", "'return_data before adding to sender: %s'", ",", "return_data", ")", "self", ".", "metrics", ".", "add_metric", "(", "return_data", ")", "logger", ".", "info", "(", "'self metrics before sending to zabbix %s'", ",", "self", ".", "metrics", ".", "active_senders", "[", "0", "]", ".", "unique_metrics", ")", "if", "self", ".", "args", ".", "dry_run", ":", "self", ".", "metrics", ".", "print_unique_metrics", "(", ")", "else", ":", "self", ".", "metrics", ".", "send_metrics", "(", ")" ]
https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/scripts/monitoring/cron-send-url-check.py#L89-L118
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_hxb2/lib/python3.5/site-packages/wagtail/wagtailadmin/rich_text.py
python
HalloRichTextArea.value_from_datadict
(self, data, files, name)
return DbWhitelister.clean(original_value)
[]
def value_from_datadict(self, data, files, name): original_value = super(HalloRichTextArea, self).value_from_datadict(data, files, name) if original_value is None: return None return DbWhitelister.clean(original_value)
[ "def", "value_from_datadict", "(", "self", ",", "data", ",", "files", ",", "name", ")", ":", "original_value", "=", "super", "(", "HalloRichTextArea", ",", "self", ")", ".", "value_from_datadict", "(", "data", ",", "files", ",", "name", ")", "if", "original_value", "is", "None", ":", "return", "None", "return", "DbWhitelister", ".", "clean", "(", "original_value", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_hxb2/lib/python3.5/site-packages/wagtail/wagtailadmin/rich_text.py#L136-L140
truenas/middleware
b11ec47d6340324f5a32287ffb4012e5d709b934
src/middlewared/middlewared/plugins/gluster_linux/peer.py
python
GlusterPeerService.do_create
(self, job, data)
return await self.middleware.call('gluster.peer.query', [('hostname', '=', data['hostname'])])
Add peer to the Trusted Storage Pool. `hostname` String representing an IP(v4/v6) address or DNS name
Add peer to the Trusted Storage Pool.
[ "Add", "peer", "to", "the", "Trusted", "Storage", "Pool", "." ]
async def do_create(self, job, data): """ Add peer to the Trusted Storage Pool. `hostname` String representing an IP(v4/v6) address or DNS name """ await self.middleware.call('gluster.peer.common_validation', 'gluster.peer.create') # we need to verify that we can resolve the hostname to an IP address # or clustering, in general, is going to fail in spectacular ways await self.middleware.call('cluster.utils.resolve_hostnames', [data['hostname']]) await self.middleware.call('gluster.method.run', peer.attach, {'args': (data['hostname'],)}) return await self.middleware.call('gluster.peer.query', [('hostname', '=', data['hostname'])])
[ "async", "def", "do_create", "(", "self", ",", "job", ",", "data", ")", ":", "await", "self", ".", "middleware", ".", "call", "(", "'gluster.peer.common_validation'", ",", "'gluster.peer.create'", ")", "# we need to verify that we can resolve the hostname to an IP address", "# or clustering, in general, is going to fail in spectacular ways", "await", "self", ".", "middleware", ".", "call", "(", "'cluster.utils.resolve_hostnames'", ",", "[", "data", "[", "'hostname'", "]", "]", ")", "await", "self", ".", "middleware", ".", "call", "(", "'gluster.method.run'", ",", "peer", ".", "attach", ",", "{", "'args'", ":", "(", "data", "[", "'hostname'", "]", ",", ")", "}", ")", "return", "await", "self", ".", "middleware", ".", "call", "(", "'gluster.peer.query'", ",", "[", "(", "'hostname'", ",", "'='", ",", "data", "[", "'hostname'", "]", ")", "]", ")" ]
https://github.com/truenas/middleware/blob/b11ec47d6340324f5a32287ffb4012e5d709b934/src/middlewared/middlewared/plugins/gluster_linux/peer.py#L78-L91
securesystemslab/zippy
ff0e84ac99442c2c55fe1d285332cfd4e185e089
zippy/lib-python/3/plat-sunos5/IN.py
python
FTFLW_HASH
(h)
return (((unsigned)(h))%ftflw_hash_sz)
[]
def FTFLW_HASH(h): return (((unsigned)(h))%ftflw_hash_sz)
[ "def", "FTFLW_HASH", "(", "h", ")", ":", "return", "(", "(", "(", "unsigned", ")", "(", "h", ")", ")", "%", "ftflw_hash_sz", ")" ]
https://github.com/securesystemslab/zippy/blob/ff0e84ac99442c2c55fe1d285332cfd4e185e089/zippy/lib-python/3/plat-sunos5/IN.py#L1102-L1102
gpodder/mygpo
7a028ad621d05d4ca0d58fd22fb92656c8835e43
mygpo/api/advanced/auth.py
python
logout
(request, username)
return HttpResponse()
logs out the user. does nothing if he wasn't logged in
logs out the user. does nothing if he wasn't logged in
[ "logs", "out", "the", "user", ".", "does", "nothing", "if", "he", "wasn", "t", "logged", "in" ]
def logout(request, username): """ logs out the user. does nothing if he wasn't logged in """ auth.logout(request) return HttpResponse()
[ "def", "logout", "(", "request", ",", "username", ")", ":", "auth", ".", "logout", "(", "request", ")", "return", "HttpResponse", "(", ")" ]
https://github.com/gpodder/mygpo/blob/7a028ad621d05d4ca0d58fd22fb92656c8835e43/mygpo/api/advanced/auth.py#L32-L38
nucypher/nucypher
f420caeb1c974f511f689fd1e5a9c6bbdf97f2d7
nucypher/blockchain/eth/agents.py
python
StakingEscrowAgent.set_restaking
(self, transacting_power: TransactingPower, value: bool)
return receipt
Enable automatic restaking for a fixed duration of lock periods. If set to True, then all staking rewards will be automatically added to locked stake.
Enable automatic restaking for a fixed duration of lock periods. If set to True, then all staking rewards will be automatically added to locked stake.
[ "Enable", "automatic", "restaking", "for", "a", "fixed", "duration", "of", "lock", "periods", ".", "If", "set", "to", "True", "then", "all", "staking", "rewards", "will", "be", "automatically", "added", "to", "locked", "stake", "." ]
def set_restaking(self, transacting_power: TransactingPower, value: bool) -> TxReceipt: """ Enable automatic restaking for a fixed duration of lock periods. If set to True, then all staking rewards will be automatically added to locked stake. """ contract_function: ContractFunction = self.contract.functions.setReStake(value) receipt: TxReceipt = self.blockchain.send_transaction(contract_function=contract_function, transacting_power=transacting_power) # TODO: Handle ReStakeSet event (see #1193) return receipt
[ "def", "set_restaking", "(", "self", ",", "transacting_power", ":", "TransactingPower", ",", "value", ":", "bool", ")", "->", "TxReceipt", ":", "contract_function", ":", "ContractFunction", "=", "self", ".", "contract", ".", "functions", ".", "setReStake", "(", "value", ")", "receipt", ":", "TxReceipt", "=", "self", ".", "blockchain", ".", "send_transaction", "(", "contract_function", "=", "contract_function", ",", "transacting_power", "=", "transacting_power", ")", "# TODO: Handle ReStakeSet event (see #1193)", "return", "receipt" ]
https://github.com/nucypher/nucypher/blob/f420caeb1c974f511f689fd1e5a9c6bbdf97f2d7/nucypher/blockchain/eth/agents.py#L651-L660
pyparallel/pyparallel
11e8c6072d48c8f13641925d17b147bf36ee0ba3
Lib/site-packages/pandas-0.17.0-py3.3-win-amd64.egg/pandas/compat/chainmap_impl.py
python
recursive_repr
(fillvalue='...')
return decorating_function
Decorator to make a repr function return fillvalue for a recursive call
Decorator to make a repr function return fillvalue for a recursive call
[ "Decorator", "to", "make", "a", "repr", "function", "return", "fillvalue", "for", "a", "recursive", "call" ]
def recursive_repr(fillvalue='...'): 'Decorator to make a repr function return fillvalue for a recursive call' def decorating_function(user_function): repr_running = set() def wrapper(self): key = id(self), get_ident() if key in repr_running: return fillvalue repr_running.add(key) try: result = user_function(self) finally: repr_running.discard(key) return result # Can't use functools.wraps() here because of bootstrap issues wrapper.__module__ = getattr(user_function, '__module__') wrapper.__doc__ = getattr(user_function, '__doc__') wrapper.__name__ = getattr(user_function, '__name__') return wrapper return decorating_function
[ "def", "recursive_repr", "(", "fillvalue", "=", "'...'", ")", ":", "def", "decorating_function", "(", "user_function", ")", ":", "repr_running", "=", "set", "(", ")", "def", "wrapper", "(", "self", ")", ":", "key", "=", "id", "(", "self", ")", ",", "get_ident", "(", ")", "if", "key", "in", "repr_running", ":", "return", "fillvalue", "repr_running", ".", "add", "(", "key", ")", "try", ":", "result", "=", "user_function", "(", "self", ")", "finally", ":", "repr_running", ".", "discard", "(", "key", ")", "return", "result", "# Can't use functools.wraps() here because of bootstrap issues", "wrapper", ".", "__module__", "=", "getattr", "(", "user_function", ",", "'__module__'", ")", "wrapper", ".", "__doc__", "=", "getattr", "(", "user_function", ",", "'__doc__'", ")", "wrapper", ".", "__name__", "=", "getattr", "(", "user_function", ",", "'__name__'", ")", "return", "wrapper", "return", "decorating_function" ]
https://github.com/pyparallel/pyparallel/blob/11e8c6072d48c8f13641925d17b147bf36ee0ba3/Lib/site-packages/pandas-0.17.0-py3.3-win-amd64.egg/pandas/compat/chainmap_impl.py#L9-L32
IJDykeman/wangTiles
7c1ee2095ebdf7f72bce07d94c6484915d5cae8b
experimental_code/tiles_3d/venv_mac_py3/lib/python2.7/site-packages/pip/_vendor/pkg_resources/__init__.py
python
DistInfoDistribution._parsed_pkg_info
(self)
Parse and cache metadata
Parse and cache metadata
[ "Parse", "and", "cache", "metadata" ]
def _parsed_pkg_info(self): """Parse and cache metadata""" try: return self._pkg_info except AttributeError: metadata = self.get_metadata(self.PKG_INFO) self._pkg_info = email.parser.Parser().parsestr(metadata) return self._pkg_info
[ "def", "_parsed_pkg_info", "(", "self", ")", ":", "try", ":", "return", "self", ".", "_pkg_info", "except", "AttributeError", ":", "metadata", "=", "self", ".", "get_metadata", "(", "self", ".", "PKG_INFO", ")", "self", ".", "_pkg_info", "=", "email", ".", "parser", ".", "Parser", "(", ")", ".", "parsestr", "(", "metadata", ")", "return", "self", ".", "_pkg_info" ]
https://github.com/IJDykeman/wangTiles/blob/7c1ee2095ebdf7f72bce07d94c6484915d5cae8b/experimental_code/tiles_3d/venv_mac_py3/lib/python2.7/site-packages/pip/_vendor/pkg_resources/__init__.py#L2857-L2864
Zehaos/MobileNet
bb02b10fbd211d717f7a207245feac229f6bb23e
datasets/pascalvoc_to_tfrecords.py
python
_get_output_filename
(output_dir, name, idx)
return '%s/%s_%03d.tfrecord' % (output_dir, name, idx)
[]
def _get_output_filename(output_dir, name, idx): return '%s/%s_%03d.tfrecord' % (output_dir, name, idx)
[ "def", "_get_output_filename", "(", "output_dir", ",", "name", ",", "idx", ")", ":", "return", "'%s/%s_%03d.tfrecord'", "%", "(", "output_dir", ",", "name", ",", "idx", ")" ]
https://github.com/Zehaos/MobileNet/blob/bb02b10fbd211d717f7a207245feac229f6bb23e/datasets/pascalvoc_to_tfrecords.py#L183-L184
khanhnamle1994/natural-language-processing
01d450d5ac002b0156ef4cf93a07cb508c1bcdc5
assignment1/.env/lib/python2.7/site-packages/IPython/parallel/apps/launcher.py
python
LocalControllerLauncher.start
(self)
return super(LocalControllerLauncher, self).start()
Start the controller by profile_dir.
Start the controller by profile_dir.
[ "Start", "the", "controller", "by", "profile_dir", "." ]
def start(self): """Start the controller by profile_dir.""" return super(LocalControllerLauncher, self).start()
[ "def", "start", "(", "self", ")", ":", "return", "super", "(", "LocalControllerLauncher", ",", "self", ")", ".", "start", "(", ")" ]
https://github.com/khanhnamle1994/natural-language-processing/blob/01d450d5ac002b0156ef4cf93a07cb508c1bcdc5/assignment1/.env/lib/python2.7/site-packages/IPython/parallel/apps/launcher.py#L354-L356
pexpect/pexpect
2be6c4d1aa2b9b522636342c2fd54b73c058060d
pexpect/screen.py
python
screen.erase_down
(self)
Erases the screen from the current line down to the bottom of the screen.
Erases the screen from the current line down to the bottom of the screen.
[ "Erases", "the", "screen", "from", "the", "current", "line", "down", "to", "the", "bottom", "of", "the", "screen", "." ]
def erase_down (self): # <ESC>[0J -or- <ESC>[J '''Erases the screen from the current line down to the bottom of the screen.''' self.erase_end_of_line () self.fill_region (self.cur_r + 1, 1, self.rows, self.cols)
[ "def", "erase_down", "(", "self", ")", ":", "# <ESC>[0J -or- <ESC>[J", "self", ".", "erase_end_of_line", "(", ")", "self", ".", "fill_region", "(", "self", ".", "cur_r", "+", "1", ",", "1", ",", "self", ".", "rows", ",", "self", ".", "cols", ")" ]
https://github.com/pexpect/pexpect/blob/2be6c4d1aa2b9b522636342c2fd54b73c058060d/pexpect/screen.py#L393-L398
sethmlarson/virtualbox-python
984a6e2cb0e8996f4df40f4444c1528849f1c70d
virtualbox/library.py
python
IVirtualBoxErrorInfo.result_code
(self)
return ret
Get int value for 'resultCode' Result code of the error. Usually, it will be the same as the result code returned by the method that provided this error information, but not always. For example, on Win32, CoCreateInstance() will most likely return E_NOINTERFACE upon unsuccessful component instantiation attempt, but not the value the component factory returned. Value is typed 'long', not 'result', to make interface usable from scripting languages. In MS COM, there is no equivalent. In XPCOM, it is the same as nsIException::result.
Get int value for 'resultCode' Result code of the error. Usually, it will be the same as the result code returned by the method that provided this error information, but not always. For example, on Win32, CoCreateInstance() will most likely return E_NOINTERFACE upon unsuccessful component instantiation attempt, but not the value the component factory returned. Value is typed 'long', not 'result', to make interface usable from scripting languages.
[ "Get", "int", "value", "for", "resultCode", "Result", "code", "of", "the", "error", ".", "Usually", "it", "will", "be", "the", "same", "as", "the", "result", "code", "returned", "by", "the", "method", "that", "provided", "this", "error", "information", "but", "not", "always", ".", "For", "example", "on", "Win32", "CoCreateInstance", "()", "will", "most", "likely", "return", "E_NOINTERFACE", "upon", "unsuccessful", "component", "instantiation", "attempt", "but", "not", "the", "value", "the", "component", "factory", "returned", ".", "Value", "is", "typed", "long", "not", "result", "to", "make", "interface", "usable", "from", "scripting", "languages", "." ]
def result_code(self): """Get int value for 'resultCode' Result code of the error. Usually, it will be the same as the result code returned by the method that provided this error information, but not always. For example, on Win32, CoCreateInstance() will most likely return E_NOINTERFACE upon unsuccessful component instantiation attempt, but not the value the component factory returned. Value is typed 'long', not 'result', to make interface usable from scripting languages. In MS COM, there is no equivalent. In XPCOM, it is the same as nsIException::result. """ ret = self._get_attr("resultCode") return ret
[ "def", "result_code", "(", "self", ")", ":", "ret", "=", "self", ".", "_get_attr", "(", "\"resultCode\"", ")", "return", "ret" ]
https://github.com/sethmlarson/virtualbox-python/blob/984a6e2cb0e8996f4df40f4444c1528849f1c70d/virtualbox/library.py#L8979-L8994
TengXiaoDai/DistributedCrawling
f5c2439e6ce68dd9b49bde084d76473ff9ed4963
Lib/site-packages/pip/_vendor/distlib/_backport/tarfile.py
python
TarFile.addfile
(self, tarinfo, fileobj=None)
Add the TarInfo object `tarinfo' to the archive. If `fileobj' is given, tarinfo.size bytes are read from it and added to the archive. You can create TarInfo objects using gettarinfo(). On Windows platforms, `fileobj' should always be opened with mode 'rb' to avoid irritation about the file size.
Add the TarInfo object `tarinfo' to the archive. If `fileobj' is given, tarinfo.size bytes are read from it and added to the archive. You can create TarInfo objects using gettarinfo(). On Windows platforms, `fileobj' should always be opened with mode 'rb' to avoid irritation about the file size.
[ "Add", "the", "TarInfo", "object", "tarinfo", "to", "the", "archive", ".", "If", "fileobj", "is", "given", "tarinfo", ".", "size", "bytes", "are", "read", "from", "it", "and", "added", "to", "the", "archive", ".", "You", "can", "create", "TarInfo", "objects", "using", "gettarinfo", "()", ".", "On", "Windows", "platforms", "fileobj", "should", "always", "be", "opened", "with", "mode", "rb", "to", "avoid", "irritation", "about", "the", "file", "size", "." ]
def addfile(self, tarinfo, fileobj=None): """Add the TarInfo object `tarinfo' to the archive. If `fileobj' is given, tarinfo.size bytes are read from it and added to the archive. You can create TarInfo objects using gettarinfo(). On Windows platforms, `fileobj' should always be opened with mode 'rb' to avoid irritation about the file size. """ self._check("aw") tarinfo = copy.copy(tarinfo) buf = tarinfo.tobuf(self.format, self.encoding, self.errors) self.fileobj.write(buf) self.offset += len(buf) # If there's data to follow, append it. if fileobj is not None: copyfileobj(fileobj, self.fileobj, tarinfo.size) blocks, remainder = divmod(tarinfo.size, BLOCKSIZE) if remainder > 0: self.fileobj.write(NUL * (BLOCKSIZE - remainder)) blocks += 1 self.offset += blocks * BLOCKSIZE self.members.append(tarinfo)
[ "def", "addfile", "(", "self", ",", "tarinfo", ",", "fileobj", "=", "None", ")", ":", "self", ".", "_check", "(", "\"aw\"", ")", "tarinfo", "=", "copy", ".", "copy", "(", "tarinfo", ")", "buf", "=", "tarinfo", ".", "tobuf", "(", "self", ".", "format", ",", "self", ".", "encoding", ",", "self", ".", "errors", ")", "self", ".", "fileobj", ".", "write", "(", "buf", ")", "self", ".", "offset", "+=", "len", "(", "buf", ")", "# If there's data to follow, append it.", "if", "fileobj", "is", "not", "None", ":", "copyfileobj", "(", "fileobj", ",", "self", ".", "fileobj", ",", "tarinfo", ".", "size", ")", "blocks", ",", "remainder", "=", "divmod", "(", "tarinfo", ".", "size", ",", "BLOCKSIZE", ")", "if", "remainder", ">", "0", ":", "self", ".", "fileobj", ".", "write", "(", "NUL", "*", "(", "BLOCKSIZE", "-", "remainder", ")", ")", "blocks", "+=", "1", "self", ".", "offset", "+=", "blocks", "*", "BLOCKSIZE", "self", ".", "members", ".", "append", "(", "tarinfo", ")" ]
https://github.com/TengXiaoDai/DistributedCrawling/blob/f5c2439e6ce68dd9b49bde084d76473ff9ed4963/Lib/site-packages/pip/_vendor/distlib/_backport/tarfile.py#L2100-L2124
natashamjaques/neural_chat
ddb977bb4602a67c460d02231e7bbf7b2cb49a97
ParlAI/parlai/mturk/webapp/run_mocks/mock_turk_agent.py
python
MockTurkAgent.act
(self, timeout=None, blocking=True)
return gotten_act
Retrieve an act in the normal expected way (out of the queue), but clear the act request if we do end up getting an act.
Retrieve an act in the normal expected way (out of the queue), but clear the act request if we do end up getting an act.
[ "Retrieve", "an", "act", "in", "the", "normal", "expected", "way", "(", "out", "of", "the", "queue", ")", "but", "clear", "the", "act", "request", "if", "we", "do", "end", "up", "getting", "an", "act", "." ]
def act(self, timeout=None, blocking=True): """Retrieve an act in the normal expected way (out of the queue), but clear the act request if we do end up getting an act.""" gotten_act = super().act(timeout, blocking) if gotten_act is not None: self.wants_message = False gotten_act['episode_done'] = gotten_act.get('episode_done', False) return gotten_act
[ "def", "act", "(", "self", ",", "timeout", "=", "None", ",", "blocking", "=", "True", ")", ":", "gotten_act", "=", "super", "(", ")", ".", "act", "(", "timeout", ",", "blocking", ")", "if", "gotten_act", "is", "not", "None", ":", "self", ".", "wants_message", "=", "False", "gotten_act", "[", "'episode_done'", "]", "=", "gotten_act", ".", "get", "(", "'episode_done'", ",", "False", ")", "return", "gotten_act" ]
https://github.com/natashamjaques/neural_chat/blob/ddb977bb4602a67c460d02231e7bbf7b2cb49a97/ParlAI/parlai/mturk/webapp/run_mocks/mock_turk_agent.py#L82-L89
artefactual/archivematica
4f4605453d5a8796f6a739fa9664921bdb3418f2
src/archivematicaCommon/lib/elasticSearchFunctions.py
python
_normalize_dict_values
(data)
return data
Normalize dictionary values. Because an XML document node may include one or more children, conversion to a dict can result in the converted child being one of two types. this causes problems in an Elasticsearch index as it expects consistant types to be indexed. The below function recurses a dict and if a dict's value is another dict, it encases it in a list.
Normalize dictionary values.
[ "Normalize", "dictionary", "values", "." ]
def _normalize_dict_values(data): """Normalize dictionary values. Because an XML document node may include one or more children, conversion to a dict can result in the converted child being one of two types. this causes problems in an Elasticsearch index as it expects consistant types to be indexed. The below function recurses a dict and if a dict's value is another dict, it encases it in a list. """ for key in data: if isinstance(data[key], dict): data[key] = [_normalize_dict_values(data[key])] elif isinstance(data[key], list): data[key] = _normalize_list_dict_elements(data[key]) return data
[ "def", "_normalize_dict_values", "(", "data", ")", ":", "for", "key", "in", "data", ":", "if", "isinstance", "(", "data", "[", "key", "]", ",", "dict", ")", ":", "data", "[", "key", "]", "=", "[", "_normalize_dict_values", "(", "data", "[", "key", "]", ")", "]", "elif", "isinstance", "(", "data", "[", "key", "]", ",", "list", ")", ":", "data", "[", "key", "]", "=", "_normalize_list_dict_elements", "(", "data", "[", "key", "]", ")", "return", "data" ]
https://github.com/artefactual/archivematica/blob/4f4605453d5a8796f6a739fa9664921bdb3418f2/src/archivematicaCommon/lib/elasticSearchFunctions.py#L1082-L1097
oilshell/oil
94388e7d44a9ad879b12615f6203b38596b5a2d3
Python-2.7.13/Lib/symtable.py
python
Symbol.get_namespaces
(self)
return self.__namespaces
Return a list of namespaces bound to this name
Return a list of namespaces bound to this name
[ "Return", "a", "list", "of", "namespaces", "bound", "to", "this", "name" ]
def get_namespaces(self): """Return a list of namespaces bound to this name""" return self.__namespaces
[ "def", "get_namespaces", "(", "self", ")", ":", "return", "self", ".", "__namespaces" ]
https://github.com/oilshell/oil/blob/94388e7d44a9ad879b12615f6203b38596b5a2d3/Python-2.7.13/Lib/symtable.py#L220-L222
adamcaudill/yawast
5e9e7a37831c030530adb971925ee135e9bfcafb
yawast/scanner/cli/http.py
python
reset
()
[]
def reset(): retirejs.reset() file_search.reset() error_checker.reset() http_basic.reset()
[ "def", "reset", "(", ")", ":", "retirejs", ".", "reset", "(", ")", "file_search", ".", "reset", "(", ")", "error_checker", ".", "reset", "(", ")", "http_basic", ".", "reset", "(", ")" ]
https://github.com/adamcaudill/yawast/blob/5e9e7a37831c030530adb971925ee135e9bfcafb/yawast/scanner/cli/http.py#L213-L217
Nuitka/Nuitka
39262276993757fa4e299f497654065600453fc9
nuitka/build/inline_copy/lib/scons-2.3.2/SCons/Util.py
python
RenameFunction
(function, name)
return FunctionType(function.func_code, function.func_globals, name, function.func_defaults)
Returns a function identical to the specified function, but with the specified name.
Returns a function identical to the specified function, but with the specified name.
[ "Returns", "a", "function", "identical", "to", "the", "specified", "function", "but", "with", "the", "specified", "name", "." ]
def RenameFunction(function, name): """ Returns a function identical to the specified function, but with the specified name. """ return FunctionType(function.func_code, function.func_globals, name, function.func_defaults)
[ "def", "RenameFunction", "(", "function", ",", "name", ")", ":", "return", "FunctionType", "(", "function", ".", "func_code", ",", "function", ".", "func_globals", ",", "name", ",", "function", ".", "func_defaults", ")" ]
https://github.com/Nuitka/Nuitka/blob/39262276993757fa4e299f497654065600453fc9/nuitka/build/inline_copy/lib/scons-2.3.2/SCons/Util.py#L1374-L1382
JiangWenPL/multiperson
e8ae029cc691f3f9c3958a23f762f3d72cf65c54
mmdetection/mmdet/core/fp16/hooks.py
python
Fp16OptimizerHook.copy_grads_to_fp32
(self, fp16_net, fp32_weights)
Copy gradients from fp16 model to fp32 weight copy.
Copy gradients from fp16 model to fp32 weight copy.
[ "Copy", "gradients", "from", "fp16", "model", "to", "fp32", "weight", "copy", "." ]
def copy_grads_to_fp32(self, fp16_net, fp32_weights): """Copy gradients from fp16 model to fp32 weight copy.""" for fp32_param, fp16_param in zip(fp32_weights, fp16_net.parameters()): if fp16_param.grad is not None: if fp32_param.grad is None: fp32_param.grad = fp32_param.data.new(fp32_param.size()) fp32_param.grad.copy_(fp16_param.grad)
[ "def", "copy_grads_to_fp32", "(", "self", ",", "fp16_net", ",", "fp32_weights", ")", ":", "for", "fp32_param", ",", "fp16_param", "in", "zip", "(", "fp32_weights", ",", "fp16_net", ".", "parameters", "(", ")", ")", ":", "if", "fp16_param", ".", "grad", "is", "not", "None", ":", "if", "fp32_param", ".", "grad", "is", "None", ":", "fp32_param", ".", "grad", "=", "fp32_param", ".", "data", ".", "new", "(", "fp32_param", ".", "size", "(", ")", ")", "fp32_param", ".", "grad", ".", "copy_", "(", "fp16_param", ".", "grad", ")" ]
https://github.com/JiangWenPL/multiperson/blob/e8ae029cc691f3f9c3958a23f762f3d72cf65c54/mmdetection/mmdet/core/fp16/hooks.py#L45-L51
AlexiaJM/RelativisticGAN
2646c0b27cfd42c20fcecaf4005c3d67322fdf4a
code/pytorch_visualize.py
python
remove_vis_hooks
()
[]
def remove_vis_hooks(): for hook in hooks: hook.remove() Function.__call__ = old_function__call__
[ "def", "remove_vis_hooks", "(", ")", ":", "for", "hook", "in", "hooks", ":", "hook", ".", "remove", "(", ")", "Function", ".", "__call__", "=", "old_function__call__" ]
https://github.com/AlexiaJM/RelativisticGAN/blob/2646c0b27cfd42c20fcecaf4005c3d67322fdf4a/code/pytorch_visualize.py#L92-L96
anshumanbh/kubebot
3558ddc593c861a9805731052c1ac5e71879fdf5
utils/wfuzzbasicauthbrute/wfuzz/framework/fuzzer/base.py
python
BaseFuzzRequest.fr_method
(self)
return
Returns HTTP request method, ie. GET, POST, PUT,...
Returns HTTP request method, ie. GET, POST, PUT,...
[ "Returns", "HTTP", "request", "method", "ie", ".", "GET", "POST", "PUT", "..." ]
def fr_method(self): """ Returns HTTP request method, ie. GET, POST, PUT,... """ return
[ "def", "fr_method", "(", "self", ")", ":", "return" ]
https://github.com/anshumanbh/kubebot/blob/3558ddc593c861a9805731052c1ac5e71879fdf5/utils/wfuzzbasicauthbrute/wfuzz/framework/fuzzer/base.py#L60-L64
tushushu/imylu
33b0534981e59d81f225b246b608106a97af2a1f
imylu/cluster/kmeans.py
python
KMeans._bin_search
(self, target, nums)
return mid
Binary search a number from array-like object. The result is the minimum number greater than target in nums. Arguments: target {float} nums {list} Returns: int -- The index result in nums.
Binary search a number from array-like object. The result is the minimum number greater than target in nums.
[ "Binary", "search", "a", "number", "from", "array", "-", "like", "object", ".", "The", "result", "is", "the", "minimum", "number", "greater", "than", "target", "in", "nums", "." ]
def _bin_search(self, target, nums): """Binary search a number from array-like object. The result is the minimum number greater than target in nums. Arguments: target {float} nums {list} Returns: int -- The index result in nums. """ low = 0 high = len(nums) - 1 assert nums[low] <= target < nums[high], "Cannot find target!" while 1: mid = (low + high) // 2 if mid == 0 or target >= nums[mid]: low = mid + 1 elif target < nums[mid - 1]: high = mid - 1 else: break return mid
[ "def", "_bin_search", "(", "self", ",", "target", ",", "nums", ")", ":", "low", "=", "0", "high", "=", "len", "(", "nums", ")", "-", "1", "assert", "nums", "[", "low", "]", "<=", "target", "<", "nums", "[", "high", "]", ",", "\"Cannot find target!\"", "while", "1", ":", "mid", "=", "(", "low", "+", "high", ")", "//", "2", "if", "mid", "==", "0", "or", "target", ">=", "nums", "[", "mid", "]", ":", "low", "=", "mid", "+", "1", "elif", "target", "<", "nums", "[", "mid", "-", "1", "]", ":", "high", "=", "mid", "-", "1", "else", ":", "break", "return", "mid" ]
https://github.com/tushushu/imylu/blob/33b0534981e59d81f225b246b608106a97af2a1f/imylu/cluster/kmeans.py#L33-L56
kubeflow/pipelines
bea751c9259ff0ae85290f873170aae89284ba8e
components/google-cloud/google_cloud_pipeline_components/aiplatform/utils.py
python
resolve_annotation
(annotation: Any)
return annotation
Resolves annotation type against a MB SDK type. Use this for Optional, Union, Forward References Args: annotation: Annotation to resolve Returns: Direct annotation
Resolves annotation type against a MB SDK type.
[ "Resolves", "annotation", "type", "against", "a", "MB", "SDK", "type", "." ]
def resolve_annotation(annotation: Any) -> Any: """Resolves annotation type against a MB SDK type. Use this for Optional, Union, Forward References Args: annotation: Annotation to resolve Returns: Direct annotation """ # handle forward reference string # if this is an Ai Platform resource noun if inspect.isclass(annotation): if issubclass(annotation, aiplatform.base.VertexAiResourceNoun): return annotation # if this is a union of all typed datasets annotation if annotation is dataset_annotation: # return the catch all Dataset class return aiplatform.datasets.dataset._Dataset # handle forward references resolved_annotation = get_forward_reference(annotation) if resolved_annotation: return resolved_annotation # handle optional types if getattr(annotation, '__origin__', None) is Union: # assume optional type # TODO check for optional type resolved_annotation = get_forward_reference(annotation.__args__[0]) if resolved_annotation: return resolved_annotation else: return annotation.__args__[0] if annotation is inspect._empty: return None return annotation
[ "def", "resolve_annotation", "(", "annotation", ":", "Any", ")", "->", "Any", ":", "# handle forward reference string", "# if this is an Ai Platform resource noun", "if", "inspect", ".", "isclass", "(", "annotation", ")", ":", "if", "issubclass", "(", "annotation", ",", "aiplatform", ".", "base", ".", "VertexAiResourceNoun", ")", ":", "return", "annotation", "# if this is a union of all typed datasets annotation", "if", "annotation", "is", "dataset_annotation", ":", "# return the catch all Dataset class", "return", "aiplatform", ".", "datasets", ".", "dataset", ".", "_Dataset", "# handle forward references", "resolved_annotation", "=", "get_forward_reference", "(", "annotation", ")", "if", "resolved_annotation", ":", "return", "resolved_annotation", "# handle optional types", "if", "getattr", "(", "annotation", ",", "'__origin__'", ",", "None", ")", "is", "Union", ":", "# assume optional type", "# TODO check for optional type", "resolved_annotation", "=", "get_forward_reference", "(", "annotation", ".", "__args__", "[", "0", "]", ")", "if", "resolved_annotation", ":", "return", "resolved_annotation", "else", ":", "return", "annotation", ".", "__args__", "[", "0", "]", "if", "annotation", "is", "inspect", ".", "_empty", ":", "return", "None", "return", "annotation" ]
https://github.com/kubeflow/pipelines/blob/bea751c9259ff0ae85290f873170aae89284ba8e/components/google-cloud/google_cloud_pipeline_components/aiplatform/utils.py#L87-L128
microsoft/debugpy
be8dd607f6837244e0b565345e497aff7a0c08bf
src/debugpy/common/messaging.py
python
Response.result
(self)
Result of the request. Returns the value of response.body, unless it is an exception, in which case it is raised instead.
Result of the request. Returns the value of response.body, unless it is an exception, in which case it is raised instead.
[ "Result", "of", "the", "request", ".", "Returns", "the", "value", "of", "response", ".", "body", "unless", "it", "is", "an", "exception", "in", "which", "case", "it", "is", "raised", "instead", "." ]
def result(self): """Result of the request. Returns the value of response.body, unless it is an exception, in which case it is raised instead. """ if self.success: return self.body else: raise self.body
[ "def", "result", "(", "self", ")", ":", "if", "self", ".", "success", ":", "return", "self", ".", "body", "else", ":", "raise", "self", ".", "body" ]
https://github.com/microsoft/debugpy/blob/be8dd607f6837244e0b565345e497aff7a0c08bf/src/debugpy/common/messaging.py#L948-L955
openstack/barbican
a9d2b133c8dc3307974f119f9a2b23a4ba82e8ce
barbican/plugin/interface/secret_store.py
python
SecretDTO.__init__
(self, type, secret, key_spec, content_type, transport_key=None)
Creates a new SecretDTO. The secret is stored in the secret parameter. In the future this DTO may include compression and key wrapping information. :param type: SecretType for secret :param secret: secret, as a base64-encoded string :param key_spec: KeySpec key specifications :param content_type: Content type of the secret, one of MIME types such as 'text/plain' or 'application/octet-stream' :param transport_key: presence of this parameter indicates that the secret has been encrypted using a transport key. The transport key is a base64 encoded x509 transport certificate.
Creates a new SecretDTO.
[ "Creates", "a", "new", "SecretDTO", "." ]
def __init__(self, type, secret, key_spec, content_type, transport_key=None): """Creates a new SecretDTO. The secret is stored in the secret parameter. In the future this DTO may include compression and key wrapping information. :param type: SecretType for secret :param secret: secret, as a base64-encoded string :param key_spec: KeySpec key specifications :param content_type: Content type of the secret, one of MIME types such as 'text/plain' or 'application/octet-stream' :param transport_key: presence of this parameter indicates that the secret has been encrypted using a transport key. The transport key is a base64 encoded x509 transport certificate. """ self.type = type or SecretType.OPAQUE self.secret = secret self.key_spec = key_spec self.content_type = content_type self.transport_key = transport_key
[ "def", "__init__", "(", "self", ",", "type", ",", "secret", ",", "key_spec", ",", "content_type", ",", "transport_key", "=", "None", ")", ":", "self", ".", "type", "=", "type", "or", "SecretType", ".", "OPAQUE", "self", ".", "secret", "=", "secret", "self", ".", "key_spec", "=", "key_spec", "self", ".", "content_type", "=", "content_type", "self", ".", "transport_key", "=", "transport_key" ]
https://github.com/openstack/barbican/blob/a9d2b133c8dc3307974f119f9a2b23a4ba82e8ce/barbican/plugin/interface/secret_store.py#L348-L368
AppScale/gts
46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9
AppServer/lib/django-1.2/django/template/context.py
python
BaseContext.__delitem__
(self, key)
Delete a variable from the current context
Delete a variable from the current context
[ "Delete", "a", "variable", "from", "the", "current", "context" ]
def __delitem__(self, key): "Delete a variable from the current context" del self.dicts[-1][key]
[ "def", "__delitem__", "(", "self", ",", "key", ")", ":", "del", "self", ".", "dicts", "[", "-", "1", "]", "[", "key", "]" ]
https://github.com/AppScale/gts/blob/46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9/AppServer/lib/django-1.2/django/template/context.py#L48-L50
IronLanguages/ironpython3
7a7bb2a872eeab0d1009fc8a6e24dca43f65b693
Src/StdLib/Lib/configparser.py
python
RawConfigParser.write
(self, fp, space_around_delimiters=True)
Write an .ini-format representation of the configuration state. If `space_around_delimiters' is True (the default), delimiters between keys and values are surrounded by spaces.
Write an .ini-format representation of the configuration state.
[ "Write", "an", ".", "ini", "-", "format", "representation", "of", "the", "configuration", "state", "." ]
def write(self, fp, space_around_delimiters=True): """Write an .ini-format representation of the configuration state. If `space_around_delimiters' is True (the default), delimiters between keys and values are surrounded by spaces. """ if space_around_delimiters: d = " {} ".format(self._delimiters[0]) else: d = self._delimiters[0] if self._defaults: self._write_section(fp, self.default_section, self._defaults.items(), d) for section in self._sections: self._write_section(fp, section, self._sections[section].items(), d)
[ "def", "write", "(", "self", ",", "fp", ",", "space_around_delimiters", "=", "True", ")", ":", "if", "space_around_delimiters", ":", "d", "=", "\" {} \"", ".", "format", "(", "self", ".", "_delimiters", "[", "0", "]", ")", "else", ":", "d", "=", "self", ".", "_delimiters", "[", "0", "]", "if", "self", ".", "_defaults", ":", "self", ".", "_write_section", "(", "fp", ",", "self", ".", "default_section", ",", "self", ".", "_defaults", ".", "items", "(", ")", ",", "d", ")", "for", "section", "in", "self", ".", "_sections", ":", "self", ".", "_write_section", "(", "fp", ",", "section", ",", "self", ".", "_sections", "[", "section", "]", ".", "items", "(", ")", ",", "d", ")" ]
https://github.com/IronLanguages/ironpython3/blob/7a7bb2a872eeab0d1009fc8a6e24dca43f65b693/Src/StdLib/Lib/configparser.py#L881-L896
researchmm/tasn
5dba8ccc096cedc63913730eeea14a9647911129
tasn-mxnet/3rdparty/tvm/topi/python/topi/generic/nn.py
python
_default_schedule
(outs, auto_inline)
return s
Default schedule for llvm.
Default schedule for llvm.
[ "Default", "schedule", "for", "llvm", "." ]
def _default_schedule(outs, auto_inline): """Default schedule for llvm.""" target = tvm.target.current_target(allow_none=False) outs = [outs] if isinstance(outs, tvm.tensor.Tensor) else outs if target.target_name != "llvm": raise RuntimeError("schedule not registered for '%s'" % target) s = tvm.create_schedule([x.op for x in outs]) if auto_inline: x = outs[0] tvm.schedule.AutoInlineInjective(s) s[x].fuse(s[x].op.axis) return s
[ "def", "_default_schedule", "(", "outs", ",", "auto_inline", ")", ":", "target", "=", "tvm", ".", "target", ".", "current_target", "(", "allow_none", "=", "False", ")", "outs", "=", "[", "outs", "]", "if", "isinstance", "(", "outs", ",", "tvm", ".", "tensor", ".", "Tensor", ")", "else", "outs", "if", "target", ".", "target_name", "!=", "\"llvm\"", ":", "raise", "RuntimeError", "(", "\"schedule not registered for '%s'\"", "%", "target", ")", "s", "=", "tvm", ".", "create_schedule", "(", "[", "x", ".", "op", "for", "x", "in", "outs", "]", ")", "if", "auto_inline", ":", "x", "=", "outs", "[", "0", "]", "tvm", ".", "schedule", ".", "AutoInlineInjective", "(", "s", ")", "s", "[", "x", "]", ".", "fuse", "(", "s", "[", "x", "]", ".", "op", ".", "axis", ")", "return", "s" ]
https://github.com/researchmm/tasn/blob/5dba8ccc096cedc63913730eeea14a9647911129/tasn-mxnet/3rdparty/tvm/topi/python/topi/generic/nn.py#L7-L18
plone/guillotina
57ad54988f797a93630e424fd4b6a75fa26410af
guillotina/interfaces/security.py
python
IPrincipalRoleMap.get_principals_for_role
(role_id)
Get the principals that have been granted a role. Return the list of (principal id, setting) who have been assigned or removed from a role. If no principals have been assigned this role, then the empty list is returned.
Get the principals that have been granted a role.
[ "Get", "the", "principals", "that", "have", "been", "granted", "a", "role", "." ]
def get_principals_for_role(role_id): # noqa: N805 """Get the principals that have been granted a role. Return the list of (principal id, setting) who have been assigned or removed from a role. If no principals have been assigned this role, then the empty list is returned. """
[ "def", "get_principals_for_role", "(", "role_id", ")", ":", "# noqa: N805" ]
https://github.com/plone/guillotina/blob/57ad54988f797a93630e424fd4b6a75fa26410af/guillotina/interfaces/security.py#L98-L106