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
microsoft/debugpy
be8dd607f6837244e0b565345e497aff7a0c08bf
src/debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/process.py
python
Process.search
(self, pattern, minAddr = None, maxAddr = None)
Search for the given pattern within the process memory. @type pattern: str, compat.unicode or L{Pattern} @param pattern: Pattern to search for. It may be a byte string, a Unicode string, or an instance of L{Pattern}. The following L{Pattern} subclasses are provided by WinAppDbg: - L{BytePattern} - L{TextPattern} - L{RegExpPattern} - L{HexPattern} You can also write your own subclass of L{Pattern} for customized searches. @type minAddr: int @param minAddr: (Optional) Start the search at this memory address. @type maxAddr: int @param maxAddr: (Optional) Stop the search at this memory address. @rtype: iterator of tuple( int, int, str ) @return: An iterator of tuples. Each tuple contains the following: - The memory address where the pattern was found. - The size of the data that matches the pattern. - The data that matches the pattern. @raise WindowsError: An error occurred when querying or reading the process memory.
Search for the given pattern within the process memory.
[ "Search", "for", "the", "given", "pattern", "within", "the", "process", "memory", "." ]
def search(self, pattern, minAddr = None, maxAddr = None): """ Search for the given pattern within the process memory. @type pattern: str, compat.unicode or L{Pattern} @param pattern: Pattern to search for. It may be a byte string, a Unicode string, or an instance of L{Pattern}. The following L{Pattern} subclasses are provided by WinAppDbg: - L{BytePattern} - L{TextPattern} - L{RegExpPattern} - L{HexPattern} You can also write your own subclass of L{Pattern} for customized searches. @type minAddr: int @param minAddr: (Optional) Start the search at this memory address. @type maxAddr: int @param maxAddr: (Optional) Stop the search at this memory address. @rtype: iterator of tuple( int, int, str ) @return: An iterator of tuples. Each tuple contains the following: - The memory address where the pattern was found. - The size of the data that matches the pattern. - The data that matches the pattern. @raise WindowsError: An error occurred when querying or reading the process memory. """ if isinstance(pattern, str): return self.search_bytes(pattern, minAddr, maxAddr) if isinstance(pattern, compat.unicode): return self.search_bytes(pattern.encode("utf-16le"), minAddr, maxAddr) if isinstance(pattern, Pattern): return Search.search_process(self, pattern, minAddr, maxAddr) raise TypeError("Unknown pattern type: %r" % type(pattern))
[ "def", "search", "(", "self", ",", "pattern", ",", "minAddr", "=", "None", ",", "maxAddr", "=", "None", ")", ":", "if", "isinstance", "(", "pattern", ",", "str", ")", ":", "return", "self", ".", "search_bytes", "(", "pattern", ",", "minAddr", ",", "m...
https://github.com/microsoft/debugpy/blob/be8dd607f6837244e0b565345e497aff7a0c08bf/src/debugpy/_vendored/pydevd/pydevd_attach_to_process/winappdbg/process.py#L1355-L1395
smart-mobile-software/gitstack
d9fee8f414f202143eb6e620529e8e5539a2af56
python/Lib/lib-tk/turtle.py
python
TurtleScreen.delay
(self, delay=None)
Return or set the drawing delay in milliseconds. Optional argument: delay -- positive integer Example (for a TurtleScreen instance named screen): >>> screen.delay(15) >>> screen.delay() 15
Return or set the drawing delay in milliseconds.
[ "Return", "or", "set", "the", "drawing", "delay", "in", "milliseconds", "." ]
def delay(self, delay=None): """ Return or set the drawing delay in milliseconds. Optional argument: delay -- positive integer Example (for a TurtleScreen instance named screen): >>> screen.delay(15) >>> screen.delay() 15 """ if delay is None: return self._delayvalue self._delayvalue = int(delay)
[ "def", "delay", "(", "self", ",", "delay", "=", "None", ")", ":", "if", "delay", "is", "None", ":", "return", "self", ".", "_delayvalue", "self", ".", "_delayvalue", "=", "int", "(", "delay", ")" ]
https://github.com/smart-mobile-software/gitstack/blob/d9fee8f414f202143eb6e620529e8e5539a2af56/python/Lib/lib-tk/turtle.py#L1220-L1233
capitalone/datacompy
8418a5c55fa7648764c0bca87931cf778dc19d48
datacompy/core.py
python
Compare._dataframe_merge
(self, ignore_spaces)
Merge df1 to df2 on the join columns, to get df1 - df2, df2 - df1 and df1 & df2 If ``on_index`` is True, this will join on index values, otherwise it will join on the ``join_columns``.
Merge df1 to df2 on the join columns, to get df1 - df2, df2 - df1 and df1 & df2
[ "Merge", "df1", "to", "df2", "on", "the", "join", "columns", "to", "get", "df1", "-", "df2", "df2", "-", "df1", "and", "df1", "&", "df2" ]
def _dataframe_merge(self, ignore_spaces): """Merge df1 to df2 on the join columns, to get df1 - df2, df2 - df1 and df1 & df2 If ``on_index`` is True, this will join on index values, otherwise it will join on the ``join_columns``. """ LOG.debug("Outer joining") if self._any_dupes: LOG.debug("Duplicate rows found, deduping by order of remaining fields") # Bring index into a column if self.on_index: index_column = temp_column_name(self.df1, self.df2) self.df1[index_column] = self.df1.index self.df2[index_column] = self.df2.index temp_join_columns = [index_column] else: temp_join_columns = list(self.join_columns) # Create order column for uniqueness of match order_column = temp_column_name(self.df1, self.df2) self.df1[order_column] = generate_id_within_group( self.df1, temp_join_columns ) self.df2[order_column] = generate_id_within_group( self.df2, temp_join_columns ) temp_join_columns.append(order_column) params = {"on": temp_join_columns} elif self.on_index: params = {"left_index": True, "right_index": True} else: params = {"on": self.join_columns} if ignore_spaces: for column in self.join_columns: if self.df1[column].dtype.kind == "O": self.df1[column] = self.df1[column].str.strip() if self.df2[column].dtype.kind == "O": self.df2[column] = self.df2[column].str.strip() outer_join = self.df1.merge( self.df2, how="outer", suffixes=("_df1", "_df2"), indicator=True, **params ) # Clean up temp columns for duplicate row matching if self._any_dupes: if self.on_index: outer_join.index = outer_join[index_column] outer_join.drop(index_column, axis=1, inplace=True) self.df1.drop(index_column, axis=1, inplace=True) self.df2.drop(index_column, axis=1, inplace=True) outer_join.drop(order_column, axis=1, inplace=True) self.df1.drop(order_column, axis=1, inplace=True) self.df2.drop(order_column, axis=1, inplace=True) df1_cols = get_merged_columns(self.df1, outer_join, "_df1") df2_cols = get_merged_columns(self.df2, outer_join, "_df2") LOG.debug("Selecting df1 unique rows") self.df1_unq_rows = outer_join[outer_join["_merge"] == "left_only"][ df1_cols ].copy() self.df1_unq_rows.columns = self.df1.columns LOG.debug("Selecting df2 unique rows") self.df2_unq_rows = outer_join[outer_join["_merge"] == "right_only"][ df2_cols ].copy() self.df2_unq_rows.columns = self.df2.columns LOG.info( "Number of rows in df1 and not in df2: {}".format(len(self.df1_unq_rows)) ) LOG.info( "Number of rows in df2 and not in df1: {}".format(len(self.df2_unq_rows)) ) LOG.debug("Selecting intersecting rows") self.intersect_rows = outer_join[outer_join["_merge"] == "both"].copy() LOG.info( "Number of rows in df1 and df2 (not necessarily equal): {}".format( len(self.intersect_rows) ) )
[ "def", "_dataframe_merge", "(", "self", ",", "ignore_spaces", ")", ":", "LOG", ".", "debug", "(", "\"Outer joining\"", ")", "if", "self", ".", "_any_dupes", ":", "LOG", ".", "debug", "(", "\"Duplicate rows found, deduping by order of remaining fields\"", ")", "# Bri...
https://github.com/capitalone/datacompy/blob/8418a5c55fa7648764c0bca87931cf778dc19d48/datacompy/core.py#L234-L319
ChineseGLUE/ChineseGLUE
1591b85cf5427c2ff60f718d359ecb71d2b44879
baselines/models/albert/modeling.py
python
assert_rank
(tensor, expected_rank, name=None)
Raises an exception if the tensor rank is not of the expected rank. Args: tensor: A tf.Tensor to check the rank of. expected_rank: Python integer or list of integers, expected rank. name: Optional name of the tensor for the error message. Raises: ValueError: If the expected shape doesn't match the actual shape.
Raises an exception if the tensor rank is not of the expected rank.
[ "Raises", "an", "exception", "if", "the", "tensor", "rank", "is", "not", "of", "the", "expected", "rank", "." ]
def assert_rank(tensor, expected_rank, name=None): """Raises an exception if the tensor rank is not of the expected rank. Args: tensor: A tf.Tensor to check the rank of. expected_rank: Python integer or list of integers, expected rank. name: Optional name of the tensor for the error message. Raises: ValueError: If the expected shape doesn't match the actual shape. """ if name is None: name = tensor.name expected_rank_dict = {} if isinstance(expected_rank, six.integer_types): expected_rank_dict[expected_rank] = True else: for x in expected_rank: expected_rank_dict[x] = True actual_rank = tensor.shape.ndims if actual_rank not in expected_rank_dict: scope_name = tf.get_variable_scope().name raise ValueError( "For the tensor `%s` in scope `%s`, the actual rank " "`%d` (shape = %s) is not equal to the expected rank `%s`" % (name, scope_name, actual_rank, str(tensor.shape), str(expected_rank)))
[ "def", "assert_rank", "(", "tensor", ",", "expected_rank", ",", "name", "=", "None", ")", ":", "if", "name", "is", "None", ":", "name", "=", "tensor", ".", "name", "expected_rank_dict", "=", "{", "}", "if", "isinstance", "(", "expected_rank", ",", "six",...
https://github.com/ChineseGLUE/ChineseGLUE/blob/1591b85cf5427c2ff60f718d359ecb71d2b44879/baselines/models/albert/modeling.py#L1045-L1072
IronLanguages/main
a949455434b1fda8c783289e897e78a9a0caabb5
External.LCA_RESTRICTED/Languages/IronPython/27/Lib/threading.py
python
Semaphore
(*args, **kwargs)
return _Semaphore(*args, **kwargs)
A factory function that returns a new semaphore. Semaphores manage a counter representing the number of release() calls minus the number of acquire() calls, plus an initial value. The acquire() method blocks if necessary until it can return without making the counter negative. If not given, value defaults to 1.
A factory function that returns a new semaphore.
[ "A", "factory", "function", "that", "returns", "a", "new", "semaphore", "." ]
def Semaphore(*args, **kwargs): """A factory function that returns a new semaphore. Semaphores manage a counter representing the number of release() calls minus the number of acquire() calls, plus an initial value. The acquire() method blocks if necessary until it can return without making the counter negative. If not given, value defaults to 1. """ return _Semaphore(*args, **kwargs)
[ "def", "Semaphore", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "_Semaphore", "(", "*", "args", ",", "*", "*", "kwargs", ")" ]
https://github.com/IronLanguages/main/blob/a949455434b1fda8c783289e897e78a9a0caabb5/External.LCA_RESTRICTED/Languages/IronPython/27/Lib/threading.py#L412-L421
py2neo-org/py2neo
2e46bbf4d622f53282e796ffc521fc4bc6d0b60d
py2neo/client/__init__.py
python
ConnectionPool._connect
(self)
return cx
Open and return a new connection.
Open and return a new connection.
[ "Open", "and", "return", "a", "new", "connection", "." ]
def _connect(self): """ Open and return a new connection. """ cx = Connection.open(self.profile, user_agent=self.user_agent, on_release=lambda c: self.release(c), on_broken=lambda msg: self.__on_broken(msg)) self._server_agent = cx.server_agent return cx
[ "def", "_connect", "(", "self", ")", ":", "cx", "=", "Connection", ".", "open", "(", "self", ".", "profile", ",", "user_agent", "=", "self", ".", "user_agent", ",", "on_release", "=", "lambda", "c", ":", "self", ".", "release", "(", "c", ")", ",", ...
https://github.com/py2neo-org/py2neo/blob/2e46bbf4d622f53282e796ffc521fc4bc6d0b60d/py2neo/client/__init__.py#L761-L768
tomoncle/Python-notes
ce675486290c3d1c7c2e4890b57e3d0c8a1228cc
crawlers/spider/downloader.py
python
HtmlDownloader.download
(self, url, retry=-1)
return content if code == 200 else ''
:param url: :param retry: 失败重试 :return:
:param url: :param retry: 失败重试 :return:
[ ":", "param", "url", ":", ":", "param", "retry", ":", "失败重试", ":", "return", ":" ]
def download(self, url, retry=-1): """ :param url: :param retry: 失败重试 :return: """ code, content = self._request(url) if retry > 0 and code != 200: self.download(url, retry - 1) return content if code == 200 else ''
[ "def", "download", "(", "self", ",", "url", ",", "retry", "=", "-", "1", ")", ":", "code", ",", "content", "=", "self", ".", "_request", "(", "url", ")", "if", "retry", ">", "0", "and", "code", "!=", "200", ":", "self", ".", "download", "(", "u...
https://github.com/tomoncle/Python-notes/blob/ce675486290c3d1c7c2e4890b57e3d0c8a1228cc/crawlers/spider/downloader.py#L60-L69
oracle/graalpython
577e02da9755d916056184ec441c26e00b70145c
graalpython/lib-python/3/importlib/_bootstrap_external.py
python
_path_join
(*path_parts)
return path_sep.join([part.rstrip(path_separators) for part in path_parts if part])
Replacement for os.path.join().
Replacement for os.path.join().
[ "Replacement", "for", "os", ".", "path", ".", "join", "()", "." ]
def _path_join(*path_parts): """Replacement for os.path.join().""" return path_sep.join([part.rstrip(path_separators) for part in path_parts if part])
[ "def", "_path_join", "(", "*", "path_parts", ")", ":", "return", "path_sep", ".", "join", "(", "[", "part", ".", "rstrip", "(", "path_separators", ")", "for", "part", "in", "path_parts", "if", "part", "]", ")" ]
https://github.com/oracle/graalpython/blob/577e02da9755d916056184ec441c26e00b70145c/graalpython/lib-python/3/importlib/_bootstrap_external.py#L62-L65
Bitmessage/PyBitmessage
97612b049e0453867d6d90aa628f8e7b007b4d85
src/shared.py
python
reloadBroadcastSendersForWhichImWatching
()
Reinitialize runtime data for the broadcasts I'm subscribed to from the config file
Reinitialize runtime data for the broadcasts I'm subscribed to from the config file
[ "Reinitialize", "runtime", "data", "for", "the", "broadcasts", "I", "m", "subscribed", "to", "from", "the", "config", "file" ]
def reloadBroadcastSendersForWhichImWatching(): """ Reinitialize runtime data for the broadcasts I'm subscribed to from the config file """ broadcastSendersForWhichImWatching.clear() MyECSubscriptionCryptorObjects.clear() queryreturn = sqlQuery('SELECT address FROM subscriptions where enabled=1') logger.debug('reloading subscriptions...') for row in queryreturn: address, = row # status addressVersionNumber, streamNumber, hashobj = decodeAddress(address)[1:] if addressVersionNumber == 2: broadcastSendersForWhichImWatching[hashobj] = 0 # Now, for all addresses, even version 2 addresses, # we should create Cryptor objects in a dictionary which we will # use to attempt to decrypt encrypted broadcast messages. if addressVersionNumber <= 3: privEncryptionKey = hashlib.sha512( encodeVarint(addressVersionNumber) + encodeVarint(streamNumber) + hashobj ).digest()[:32] MyECSubscriptionCryptorObjects[hashobj] = \ highlevelcrypto.makeCryptor(hexlify(privEncryptionKey)) else: doubleHashOfAddressData = hashlib.sha512(hashlib.sha512( encodeVarint(addressVersionNumber) + encodeVarint(streamNumber) + hashobj ).digest()).digest() tag = doubleHashOfAddressData[32:] privEncryptionKey = doubleHashOfAddressData[:32] MyECSubscriptionCryptorObjects[tag] = \ highlevelcrypto.makeCryptor(hexlify(privEncryptionKey))
[ "def", "reloadBroadcastSendersForWhichImWatching", "(", ")", ":", "broadcastSendersForWhichImWatching", ".", "clear", "(", ")", "MyECSubscriptionCryptorObjects", ".", "clear", "(", ")", "queryreturn", "=", "sqlQuery", "(", "'SELECT address FROM subscriptions where enabled=1'", ...
https://github.com/Bitmessage/PyBitmessage/blob/97612b049e0453867d6d90aa628f8e7b007b4d85/src/shared.py#L150-L184
harpribot/deep-summarization
9b3bb1daae11a1db2386dbe4a71848714e6127f8
models/stacked_bidirectional.py
python
StackedBidirectional._load_optimizer
(self)
Load the SGD optimizer :return: None
Load the SGD optimizer
[ "Load", "the", "SGD", "optimizer" ]
def _load_optimizer(self): """ Load the SGD optimizer :return: None """ # loss function with tf.variable_scope("forward"): self.loss_fwd = tf.nn.seq2seq.sequence_loss(self.dec_outputs_fwd, self.labels, self.weights, self.vocab_size) # optimizer self.optimizer_fwd = tf.train.MomentumOptimizer(self.learning_rate, self.momentum) self.train_op_fwd = self.optimizer_fwd.minimize(self.loss_fwd) with tf.variable_scope("backward"): self.loss_bwd = tf.nn.seq2seq.sequence_loss(self.dec_outputs_bwd, self.labels, self.weights, self.vocab_size) # optimizer self.optimizer_bwd = tf.train.MomentumOptimizer(self.learning_rate, self.momentum) self.train_op_bwd = self.optimizer_bwd.minimize(self.loss_bwd)
[ "def", "_load_optimizer", "(", "self", ")", ":", "# loss function", "with", "tf", ".", "variable_scope", "(", "\"forward\"", ")", ":", "self", ".", "loss_fwd", "=", "tf", ".", "nn", ".", "seq2seq", ".", "sequence_loss", "(", "self", ".", "dec_outputs_fwd", ...
https://github.com/harpribot/deep-summarization/blob/9b3bb1daae11a1db2386dbe4a71848714e6127f8/models/stacked_bidirectional.py#L200-L221
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/smhi/config_flow.py
python
SmhiFlowHandler.async_step_user
( self, user_input: dict[str, Any] | None = None )
return await self._show_config_form()
Handle a flow initialized by the user.
Handle a flow initialized by the user.
[ "Handle", "a", "flow", "initialized", "by", "the", "user", "." ]
async def async_step_user( self, user_input: dict[str, Any] | None = None ) -> FlowResult: """Handle a flow initialized by the user.""" self._errors = {} if user_input is not None: is_ok = await self._check_location( user_input[CONF_LONGITUDE], user_input[CONF_LATITUDE] ) if is_ok: name = slugify(user_input[CONF_NAME]) if not self._name_in_configuration_exists(name): latitude = user_input[CONF_LATITUDE] longitude = user_input[CONF_LONGITUDE] await self.async_set_unique_id(f"{latitude}-{longitude}") self._abort_if_unique_id_configured() return self.async_create_entry( title=user_input[CONF_NAME], data=user_input ) self._errors[CONF_NAME] = "name_exists" else: self._errors["base"] = "wrong_location" # If hass config has the location set and is a valid coordinate the # default location is set as default values in the form if ( not smhi_locations(self.hass) and await self._homeassistant_location_exists() ): return await self._show_config_form( name=HOME_LOCATION_NAME, latitude=self.hass.config.latitude, longitude=self.hass.config.longitude, ) return await self._show_config_form()
[ "async", "def", "async_step_user", "(", "self", ",", "user_input", ":", "dict", "[", "str", ",", "Any", "]", "|", "None", "=", "None", ")", "->", "FlowResult", ":", "self", ".", "_errors", "=", "{", "}", "if", "user_input", "is", "not", "None", ":", ...
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/smhi/config_flow.py#L38-L75
garethdmm/gryphon
73e19fa2d0b64c3fc7dac9e0036fc92e25e5b694
gryphon/lib/analysis/legacy/volatility.py
python
get_daily_core_fv_series_in_period
(db, start_time, end_time)
return fundamental_value_series
Get the daily close-close price series in this period from our core fv datums. NOTE that we use close prices for this series, not open prices like for hourly. Getting this series for the period [Nov 1st, Nov 4th) will give you three datapoints.
Get the daily close-close price series in this period from our core fv datums. NOTE that we use close prices for this series, not open prices like for hourly. Getting this series for the period [Nov 1st, Nov 4th) will give you three datapoints.
[ "Get", "the", "daily", "close", "-", "close", "price", "series", "in", "this", "period", "from", "our", "core", "fv", "datums", ".", "NOTE", "that", "we", "use", "close", "prices", "for", "this", "series", "not", "open", "prices", "like", "for", "hourly"...
def get_daily_core_fv_series_in_period(db, start_time, end_time): """ Get the daily close-close price series in this period from our core fv datums. NOTE that we use close prices for this series, not open prices like for hourly. Getting this series for the period [Nov 1st, Nov 4th) will give you three datapoints. """ fundamental_value_series = [] # Getting the absolute last core_fv datum in a series of periods efficiently is # difficult, so this query gets the first datum in the last five minutes of # every day. fv_series = db.query( Datum.time_created, Datum.numeric_value, )\ .filter(Datum.time_created >= start_time)\ .filter(Datum.time_created < end_time)\ .filter(func.hour(Datum.time_created) == 23)\ .filter(func.minute(Datum.time_created) > 55)\ .filter(Datum.datum_type.like('%_CORE_FUNDAMENTAL_VALUE'))\ .group_by(func.date(Datum.time_created))\ .all() # Do a teeny bit of sanity checking on the data delta = end_time - start_time assert(len(fv_series) == delta.days) fundamental_value_series = convert_datum_series_to_time_series(fv_series) return fundamental_value_series
[ "def", "get_daily_core_fv_series_in_period", "(", "db", ",", "start_time", ",", "end_time", ")", ":", "fundamental_value_series", "=", "[", "]", "# Getting the absolute last core_fv datum in a series of periods efficiently is", "# difficult, so this query gets the first datum in the la...
https://github.com/garethdmm/gryphon/blob/73e19fa2d0b64c3fc7dac9e0036fc92e25e5b694/gryphon/lib/analysis/legacy/volatility.py#L223-L254
openhatch/oh-mainline
ce29352a034e1223141dcc2f317030bbc3359a51
vendor/packages/gdata/src/gdata/tlslite/integration/AsyncStateMachine.py
python
AsyncStateMachine.setServerHandshakeOp
(self, **args)
Start a handshake operation. The arguments passed to this function will be forwarded to L{tlslite.TLSConnection.TLSConnection.handshakeServerAsync}.
Start a handshake operation.
[ "Start", "a", "handshake", "operation", "." ]
def setServerHandshakeOp(self, **args): """Start a handshake operation. The arguments passed to this function will be forwarded to L{tlslite.TLSConnection.TLSConnection.handshakeServerAsync}. """ handshaker = self.tlsConnection.handshakeServerAsync(**args) self.setHandshakeOp(handshaker)
[ "def", "setServerHandshakeOp", "(", "self", ",", "*", "*", "args", ")", ":", "handshaker", "=", "self", ".", "tlsConnection", ".", "handshakeServerAsync", "(", "*", "*", "args", ")", "self", ".", "setHandshakeOp", "(", "handshaker", ")" ]
https://github.com/openhatch/oh-mainline/blob/ce29352a034e1223141dcc2f317030bbc3359a51/vendor/packages/gdata/src/gdata/tlslite/integration/AsyncStateMachine.py#L202-L209
cgre-aachen/gempy
6ad16c46fc6616c9f452fba85d31ce32decd8b10
gempy/plot/_vista.py
python
Vista.plot_surfaces
(self, fmts: Iterable[str] = None, **kwargs)
return meshes
Plot all geomodel surfaces. If given an iterable containing surface strings, it will plot all surfaces specified in it. Args: fmts (List[str], optional): Names of surfaces to plot. Defaults to None.
Plot all geomodel surfaces. If given an iterable containing surface strings, it will plot all surfaces specified in it. Args: fmts (List[str], optional): Names of surfaces to plot. Defaults to None.
[ "Plot", "all", "geomodel", "surfaces", ".", "If", "given", "an", "iterable", "containing", "surface", "strings", "it", "will", "plot", "all", "surfaces", "specified", "in", "it", ".", "Args", ":", "fmts", "(", "List", "[", "str", "]", "optional", ")", ":...
def plot_surfaces(self, fmts: Iterable[str] = None, **kwargs): """Plot all geomodel surfaces. If given an iterable containing surface strings, it will plot all surfaces specified in it. Args: fmts (List[str], optional): Names of surfaces to plot. Defaults to None. """ colors = self._get_color_lot() meshes = [] if fmts is None: fmts = self.model._surfaces.df.surface[:-1].values fmts = np.atleast_1d(fmts) for fmt in fmts: m = self.plot_surface(fmt, colors=colors, **kwargs) for mesh in m: meshes.append(mesh) return meshes
[ "def", "plot_surfaces", "(", "self", ",", "fmts", ":", "Iterable", "[", "str", "]", "=", "None", ",", "*", "*", "kwargs", ")", ":", "colors", "=", "self", ".", "_get_color_lot", "(", ")", "meshes", "=", "[", "]", "if", "fmts", "is", "None", ":", ...
https://github.com/cgre-aachen/gempy/blob/6ad16c46fc6616c9f452fba85d31ce32decd8b10/gempy/plot/_vista.py#L739-L756
amimo/dcc
114326ab5a082a42c7728a375726489e4709ca29
androguard/decompiler/dad/control_flow.py
python
derived_sequence
(graph)
return deriv_seq, deriv_interv
Compute the derived sequence of the graph G The intervals of G are collapsed into nodes, intervals of these nodes are built, and the process is repeated iteratively until we obtain a single node (if the graph is not irreducible)
Compute the derived sequence of the graph G The intervals of G are collapsed into nodes, intervals of these nodes are built, and the process is repeated iteratively until we obtain a single node (if the graph is not irreducible)
[ "Compute", "the", "derived", "sequence", "of", "the", "graph", "G", "The", "intervals", "of", "G", "are", "collapsed", "into", "nodes", "intervals", "of", "these", "nodes", "are", "built", "and", "the", "process", "is", "repeated", "iteratively", "until", "w...
def derived_sequence(graph): """ Compute the derived sequence of the graph G The intervals of G are collapsed into nodes, intervals of these nodes are built, and the process is repeated iteratively until we obtain a single node (if the graph is not irreducible) """ deriv_seq = [graph] deriv_interv = [] single_node = False while not single_node: interv_graph, interv_heads = intervals(graph) deriv_interv.append(interv_heads) single_node = len(interv_graph) == 1 if not single_node: deriv_seq.append(interv_graph) graph = interv_graph graph.compute_rpo() return deriv_seq, deriv_interv
[ "def", "derived_sequence", "(", "graph", ")", ":", "deriv_seq", "=", "[", "graph", "]", "deriv_interv", "=", "[", "]", "single_node", "=", "False", "while", "not", "single_node", ":", "interv_graph", ",", "interv_heads", "=", "intervals", "(", "graph", ")", ...
https://github.com/amimo/dcc/blob/114326ab5a082a42c7728a375726489e4709ca29/androguard/decompiler/dad/control_flow.py#L86-L109
huggingface/transformers
623b4f7c63f60cce917677ee704d6c93ee960b4b
src/transformers/onnx/convert.py
python
export
( tokenizer: PreTrainedTokenizer, model: PreTrainedModel, config: OnnxConfig, opset: int, output: Path )
return matched_inputs, onnx_outputs
Export a PyTorch backed pipeline to ONNX Intermediate Representation (IR Args: tokenizer: model: config: opset: output: Returns:
Export a PyTorch backed pipeline to ONNX Intermediate Representation (IR
[ "Export", "a", "PyTorch", "backed", "pipeline", "to", "ONNX", "Intermediate", "Representation", "(", "IR" ]
def export( tokenizer: PreTrainedTokenizer, model: PreTrainedModel, config: OnnxConfig, opset: int, output: Path ) -> Tuple[List[str], List[str]]: """ Export a PyTorch backed pipeline to ONNX Intermediate Representation (IR Args: tokenizer: model: config: opset: output: Returns: """ if not is_torch_available(): raise ImportError("Cannot convert because PyTorch is not installed. Please install torch first.") import torch from torch.onnx import export from ..file_utils import torch_version if not is_torch_onnx_dict_inputs_support_available(): raise AssertionError(f"Unsupported PyTorch version, minimum required is 1.8.0, got: {torch_version}") logger.info(f"Using framework PyTorch: {torch.__version__}") with torch.no_grad(): model.config.return_dict = True model.eval() # Check if we need to override certain configuration item if config.values_override is not None: logger.info(f"Overriding {len(config.values_override)} configuration item(s)") for override_config_key, override_config_value in config.values_override.items(): logger.info(f"\t- {override_config_key} -> {override_config_value}") setattr(model.config, override_config_key, override_config_value) # Ensure inputs match # TODO: Check when exporting QA we provide "is_pair=True" model_inputs = config.generate_dummy_inputs(tokenizer, framework=TensorType.PYTORCH) inputs_match, matched_inputs = ensure_model_and_config_inputs_match(model, model_inputs.keys()) onnx_outputs = list(config.outputs.keys()) if not inputs_match: raise ValueError("Model and config inputs doesn't match") config.patch_ops() # export can works with named args but the dict containing named args as to be last element of the args tuple export( model, (model_inputs,), f=output.as_posix(), input_names=list(config.inputs.keys()), output_names=onnx_outputs, dynamic_axes={name: axes for name, axes in chain(config.inputs.items(), config.outputs.items())}, do_constant_folding=True, use_external_data_format=config.use_external_data_format(model.num_parameters()), enable_onnx_checker=True, opset_version=opset, ) config.restore_ops() return matched_inputs, onnx_outputs
[ "def", "export", "(", "tokenizer", ":", "PreTrainedTokenizer", ",", "model", ":", "PreTrainedModel", ",", "config", ":", "OnnxConfig", ",", "opset", ":", "int", ",", "output", ":", "Path", ")", "->", "Tuple", "[", "List", "[", "str", "]", ",", "List", ...
https://github.com/huggingface/transformers/blob/623b4f7c63f60cce917677ee704d6c93ee960b4b/src/transformers/onnx/convert.py#L65-L131
openshift/openshift-tools
1188778e728a6e4781acf728123e5b356380fe6f
openshift/installer/vendored/openshift-ansible-3.10.0-0.29.0/roles/lib_openshift/library/oc_scale.py
python
Yedit.exists
(self, path, value)
return entry == value
check if value exists at path
check if value exists at path
[ "check", "if", "value", "exists", "at", "path" ]
def exists(self, path, value): ''' check if value exists at path''' try: entry = Yedit.get_entry(self.yaml_dict, path, self.separator) except KeyError: entry = None if isinstance(entry, list): if value in entry: return True return False elif isinstance(entry, dict): if isinstance(value, dict): rval = False for key, val in value.items(): if entry[key] != val: rval = False break else: rval = True return rval return value in entry return entry == value
[ "def", "exists", "(", "self", ",", "path", ",", "value", ")", ":", "try", ":", "entry", "=", "Yedit", ".", "get_entry", "(", "self", ".", "yaml_dict", ",", "path", ",", "self", ".", "separator", ")", "except", "KeyError", ":", "entry", "=", "None", ...
https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/openshift/installer/vendored/openshift-ansible-3.10.0-0.29.0/roles/lib_openshift/library/oc_scale.py#L496-L521
keiffster/program-y
8c99b56f8c32f01a7b9887b5daae9465619d0385
src/programy/clients/client.py
python
BotClient.load_trigger_manager
(self)
[]
def load_trigger_manager(self): if self._configuration.client_configuration.triggers is not None: YLogger.debug(None, "Loading Trigger Manager") self._trigger_mgr = TriggerManager.load_trigger_manager(self._configuration.client_configuration.triggers)
[ "def", "load_trigger_manager", "(", "self", ")", ":", "if", "self", ".", "_configuration", ".", "client_configuration", ".", "triggers", "is", "not", "None", ":", "YLogger", ".", "debug", "(", "None", ",", "\"Loading Trigger Manager\"", ")", "self", ".", "_tri...
https://github.com/keiffster/program-y/blob/8c99b56f8c32f01a7b9887b5daae9465619d0385/src/programy/clients/client.py#L235-L238
Textualize/rich
d39626143036188cb2c9e1619e836540f5b627f8
rich/pretty.py
python
_get_attr_fields
(obj: Any)
return _attr_module.fields(type(obj)) if _attr_module is not None else []
Get fields for an attrs object.
Get fields for an attrs object.
[ "Get", "fields", "for", "an", "attrs", "object", "." ]
def _get_attr_fields(obj: Any) -> Iterable["_attr_module.Attribute[Any]"]: """Get fields for an attrs object.""" return _attr_module.fields(type(obj)) if _attr_module is not None else []
[ "def", "_get_attr_fields", "(", "obj", ":", "Any", ")", "->", "Iterable", "[", "\"_attr_module.Attribute[Any]\"", "]", ":", "return", "_attr_module", ".", "fields", "(", "type", "(", "obj", ")", ")", "if", "_attr_module", "is", "not", "None", "else", "[", ...
https://github.com/Textualize/rich/blob/d39626143036188cb2c9e1619e836540f5b627f8/rich/pretty.py#L61-L63
sqlmapproject/sqlmap
3b07b70864624dff4c29dcaa8a61c78e7f9189f7
thirdparty/bottle/bottle.py
python
FileUpload.__init__
(self, fileobj, name, filename, headers=None)
Wrapper for file uploads.
Wrapper for file uploads.
[ "Wrapper", "for", "file", "uploads", "." ]
def __init__(self, fileobj, name, filename, headers=None): """ Wrapper for file uploads. """ #: Open file(-like) object (BytesIO buffer or temporary file) self.file = fileobj #: Name of the upload form field self.name = name #: Raw filename as sent by the client (may contain unsafe characters) self.raw_filename = filename #: A :class:`HeaderDict` with additional headers (e.g. content-type) self.headers = HeaderDict(headers) if headers else HeaderDict()
[ "def", "__init__", "(", "self", ",", "fileobj", ",", "name", ",", "filename", ",", "headers", "=", "None", ")", ":", "#: Open file(-like) object (BytesIO buffer or temporary file)", "self", ".", "file", "=", "fileobj", "#: Name of the upload form field", "self", ".", ...
https://github.com/sqlmapproject/sqlmap/blob/3b07b70864624dff4c29dcaa8a61c78e7f9189f7/thirdparty/bottle/bottle.py#L2741-L2750
ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework
cb692f527e4e819b6c228187c5702d990a180043
external/Scripting Engine/Xenotix Python Scripting Engine/Lib/mailbox.py
python
MH.unlock
(self)
Unlock the mailbox if it is locked.
Unlock the mailbox if it is locked.
[ "Unlock", "the", "mailbox", "if", "it", "is", "locked", "." ]
def unlock(self): """Unlock the mailbox if it is locked.""" if self._locked: _unlock_file(self._file) _sync_close(self._file) del self._file self._locked = False
[ "def", "unlock", "(", "self", ")", ":", "if", "self", ".", "_locked", ":", "_unlock_file", "(", "self", ".", "_file", ")", "_sync_close", "(", "self", ".", "_file", ")", "del", "self", ".", "_file", "self", ".", "_locked", "=", "False" ]
https://github.com/ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework/blob/cb692f527e4e819b6c228187c5702d990a180043/external/Scripting Engine/Xenotix Python Scripting Engine/Lib/mailbox.py#L1025-L1031
linuxscout/mishkal
4f4ae0ebc2d6acbeb3de3f0303151ec7b54d2f76
mishkal/tashkeel.py
python
TashkeelClass._ajust_vocalized_result
(self, text)
return text
Ajust the resulted text after vocalization to correct some case like 'meeting of two queiscents = ألتقاء الساكنين' @param text: vocalized text @type text: unicode @return: ajusted text. @rtype: unicode
Ajust the resulted text after vocalization to correct some case like 'meeting of two queiscents = ألتقاء الساكنين'
[ "Ajust", "the", "resulted", "text", "after", "vocalization", "to", "correct", "some", "case", "like", "meeting", "of", "two", "queiscents", "=", "ألتقاء", "الساكنين" ]
def _ajust_vocalized_result(self, text): """ Ajust the resulted text after vocalization to correct some case like 'meeting of two queiscents = ألتقاء الساكنين' @param text: vocalized text @type text: unicode @return: ajusted text. @rtype: unicode """ # min = > mina text = re.sub(u'\sمِنْ\s+ا', u' مِنَ ا', text) # man = > mani text = re.sub(u'\sمَنْ\s+ا', u' مَنِ ا', text) #An = > ani text = re.sub(u'\sعَنْ\s+ا', u' عَنِ ا', text) #sukun + alef = > kasra +alef text = re.sub(u'\s%s\s+ا'%araby.SUKUN, u' %s ا' % araby.KASRA, text) #~ text = re.sub(ur'\s%s\s+ا'%araby.SUKUN, u' %s ا' % araby.SUKUN, text) #ajust pounctuation text = re.sub(u" ([.?!, :)”—]($| ))", u"\1", text) #binu = > bin # temporary, to be analysed by syntaxical analyzer text = re.sub(u'\sبْنُ\s', u' بْن ', text) # # # اختصارات مثل حدثنا إلى ثنا وه تكثر في كتب التراث # text = re.sub(ur'\seثِنَا\s', u' ثَنَا ', text) return text
[ "def", "_ajust_vocalized_result", "(", "self", ",", "text", ")", ":", "# min = > mina", "text", "=", "re", ".", "sub", "(", "u'\\sمِنْ\\s+ا', u' ", "م", "نَ ا', text)", "", "", "", "# man = > mani", "text", "=", "re", ".", "sub", "(", "u'\\sمَنْ\\s+ا', u' ", ...
https://github.com/linuxscout/mishkal/blob/4f4ae0ebc2d6acbeb3de3f0303151ec7b54d2f76/mishkal/tashkeel.py#L510-L536
oracle/graalpython
577e02da9755d916056184ec441c26e00b70145c
graalpython/lib-python/3/importlib/_bootstrap.py
python
_ModuleLock.has_deadlock
(self)
[]
def has_deadlock(self): # Deadlock avoidance for concurrent circular imports. me = _thread.get_ident() tid = self.owner while True: lock = _blocking_on.get(tid) if lock is None: return False tid = lock.owner if tid == me: return True
[ "def", "has_deadlock", "(", "self", ")", ":", "# Deadlock avoidance for concurrent circular imports.", "me", "=", "_thread", ".", "get_ident", "(", ")", "tid", "=", "self", ".", "owner", "while", "True", ":", "lock", "=", "_blocking_on", ".", "get", "(", "tid"...
https://github.com/oracle/graalpython/blob/577e02da9755d916056184ec441c26e00b70145c/graalpython/lib-python/3/importlib/_bootstrap.py#L66-L76
OpnTec/open-event-server
a48f7e4c6002db6fb4dc06bac6508536a0dc585e
app/models/user.py
python
User.can_create_event
(self)
return True
Checks if User can create an event
Checks if User can create an event
[ "Checks", "if", "User", "can", "create", "an", "event" ]
def can_create_event(self): """Checks if User can create an event """ perm = UserPermission.query.filter_by(name='create_event').first() if not perm: return self.is_verified if self.is_verified is False: return perm.unverified_user return True
[ "def", "can_create_event", "(", "self", ")", ":", "perm", "=", "UserPermission", ".", "query", ".", "filter_by", "(", "name", "=", "'create_event'", ")", ".", "first", "(", ")", "if", "not", "perm", ":", "return", "self", ".", "is_verified", "if", "self"...
https://github.com/OpnTec/open-event-server/blob/a48f7e4c6002db6fb4dc06bac6508536a0dc585e/app/models/user.py#L128-L138
googleads/google-ads-python
2a1d6062221f6aad1992a6bcca0e7e4a93d2db86
google/ads/googleads/v8/services/services/carrier_constant_service/client.py
python
CarrierConstantServiceClient.parse_common_project_path
(path: str)
return m.groupdict() if m else {}
Parse a project path into its component segments.
Parse a project path into its component segments.
[ "Parse", "a", "project", "path", "into", "its", "component", "segments", "." ]
def parse_common_project_path(path: str) -> Dict[str, str]: """Parse a project path into its component segments.""" m = re.match(r"^projects/(?P<project>.+?)$", path) return m.groupdict() if m else {}
[ "def", "parse_common_project_path", "(", "path", ":", "str", ")", "->", "Dict", "[", "str", ",", "str", "]", ":", "m", "=", "re", ".", "match", "(", "r\"^projects/(?P<project>.+?)$\"", ",", "path", ")", "return", "m", ".", "groupdict", "(", ")", "if", ...
https://github.com/googleads/google-ads-python/blob/2a1d6062221f6aad1992a6bcca0e7e4a93d2db86/google/ads/googleads/v8/services/services/carrier_constant_service/client.py#L215-L218
nadineproject/nadine
c41c8ef7ffe18f1853029c97eecc329039b4af6c
nadine/forms.py
python
ProfileImageForm.save
(self)
[]
def save(self): raw_img_data = self.cleaned_data['cropped_image_data'] if not raw_img_data or len(raw_img_data) == 0: # Nothing to save here return img_data = base64.b64decode(raw_img_data) if self.cleaned_data['username']: user = get_object_or_404(User, username=self.cleaned_data['username']) filename = "user_photos/%s.jpg" % self.cleaned_data['username'] if user.profile.photo: user.profile.photo.delete() user.profile.photo.save(filename, ContentFile(img_data)) elif self.cleaned_data['organization']: organization = get_object_or_404(Organization, id=self.cleaned_data['organization']) filename = "org_photos/%s.jpg" % self.cleaned_data['username'] if organization.photo: organization.photo.delete() organization.photo.save(filename, ContentFile(img_data))
[ "def", "save", "(", "self", ")", ":", "raw_img_data", "=", "self", ".", "cleaned_data", "[", "'cropped_image_data'", "]", "if", "not", "raw_img_data", "or", "len", "(", "raw_img_data", ")", "==", "0", ":", "# Nothing to save here", "return", "img_data", "=", ...
https://github.com/nadineproject/nadine/blob/c41c8ef7ffe18f1853029c97eecc329039b4af6c/nadine/forms.py#L305-L325
numba/numba
bf480b9e0da858a65508c2b17759a72ee6a44c51
numba/core/tracing.py
python
TLS.__init__
(self)
[]
def __init__(self): self.tracing = False self.indent = 0
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "tracing", "=", "False", "self", ".", "indent", "=", "0" ]
https://github.com/numba/numba/blob/bf480b9e0da858a65508c2b17759a72ee6a44c51/numba/core/tracing.py#L12-L14
nshaud/DeepHyperX
176e582e53df92a6b4014b022c7f67034b489889
utils.py
python
padding_image
(image, patch_size=None, mode="symmetric", constant_values=0)
return padded_image
Padding an input image. Modified at 2020.11.16. If you find any issues, please email at mengxue_zhang@hhu.edu.cn with details. Args: image: 2D+ image with a shape of [h, w, ...], The array to pad patch_size: optional, a list include two integers, default is [1, 1] for pure spectra algorithm, The patch size of the algorithm mode: optional, str or function, default is "symmetric", Including 'constant', 'reflect', 'symmetric', more details see np.pad() constant_values: optional, sequence or scalar, default is 0, Used in 'constant'. The values to set the padded values for each axis Returns: padded_image with a shape of [h + patch_size[0] // 2 * 2, w + patch_size[1] // 2 * 2, ...]
Padding an input image. Modified at 2020.11.16. If you find any issues, please email at mengxue_zhang@hhu.edu.cn with details.
[ "Padding", "an", "input", "image", ".", "Modified", "at", "2020", ".", "11", ".", "16", ".", "If", "you", "find", "any", "issues", "please", "email", "at", "mengxue_zhang@hhu", ".", "edu", ".", "cn", "with", "details", "." ]
def padding_image(image, patch_size=None, mode="symmetric", constant_values=0): """Padding an input image. Modified at 2020.11.16. If you find any issues, please email at mengxue_zhang@hhu.edu.cn with details. Args: image: 2D+ image with a shape of [h, w, ...], The array to pad patch_size: optional, a list include two integers, default is [1, 1] for pure spectra algorithm, The patch size of the algorithm mode: optional, str or function, default is "symmetric", Including 'constant', 'reflect', 'symmetric', more details see np.pad() constant_values: optional, sequence or scalar, default is 0, Used in 'constant'. The values to set the padded values for each axis Returns: padded_image with a shape of [h + patch_size[0] // 2 * 2, w + patch_size[1] // 2 * 2, ...] """ if patch_size is None: patch_size = [1, 1] h = patch_size[0] // 2 w = patch_size[1] // 2 pad_width = [[h, h], [w, w]] [pad_width.append([0, 0]) for i in image.shape[2:]] padded_image = np.pad(image, pad_width, mode=mode, constant_values=constant_values) return padded_image
[ "def", "padding_image", "(", "image", ",", "patch_size", "=", "None", ",", "mode", "=", "\"symmetric\"", ",", "constant_values", "=", "0", ")", ":", "if", "patch_size", "is", "None", ":", "patch_size", "=", "[", "1", ",", "1", "]", "h", "=", "patch_siz...
https://github.com/nshaud/DeepHyperX/blob/176e582e53df92a6b4014b022c7f67034b489889/utils.py#L225-L249
optuna/optuna
2c44c1a405ba059efd53f4b9c8e849d20fb95c0a
optuna/trial/_frozen.py
python
FrozenTrial.suggest_discrete_uniform
(self, name: str, low: float, high: float, q: float)
return self.suggest_float(name, low, high, step=q)
[]
def suggest_discrete_uniform(self, name: str, low: float, high: float, q: float) -> float: return self.suggest_float(name, low, high, step=q)
[ "def", "suggest_discrete_uniform", "(", "self", ",", "name", ":", "str", ",", "low", ":", "float", ",", "high", ":", "float", ",", "q", ":", "float", ")", "->", "float", ":", "return", "self", ".", "suggest_float", "(", "name", ",", "low", ",", "high...
https://github.com/optuna/optuna/blob/2c44c1a405ba059efd53f4b9c8e849d20fb95c0a/optuna/trial/_frozen.py#L249-L251
PowerScript/KatanaFramework
0f6ad90a88de865d58ec26941cb4460501e75496
lib/scapy/scapy/utils6.py
python
in6_cidr2mask
(m)
return ''.join(map(lambda x: struct.pack('!I', x), t))
Return the mask (bitstring) associated with provided length value. For instance if function is called on 48, return value is '\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'.
Return the mask (bitstring) associated with provided length value. For instance if function is called on 48, return value is '\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'.
[ "Return", "the", "mask", "(", "bitstring", ")", "associated", "with", "provided", "length", "value", ".", "For", "instance", "if", "function", "is", "called", "on", "48", "return", "value", "is", "\\", "xff", "\\", "xff", "\\", "xff", "\\", "xff", "\\", ...
def in6_cidr2mask(m): """ Return the mask (bitstring) associated with provided length value. For instance if function is called on 48, return value is '\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'. """ if m > 128 or m < 0: raise Scapy_Exception("value provided to in6_cidr2mask outside [0, 128] domain (%d)" % m) t = [] for i in xrange(0, 4): t.append(max(0, 2**32 - 2**(32-min(32, m)))) m -= 32 return ''.join(map(lambda x: struct.pack('!I', x), t))
[ "def", "in6_cidr2mask", "(", "m", ")", ":", "if", "m", ">", "128", "or", "m", "<", "0", ":", "raise", "Scapy_Exception", "(", "\"value provided to in6_cidr2mask outside [0, 128] domain (%d)\"", "%", "m", ")", "t", "=", "[", "]", "for", "i", "in", "xrange", ...
https://github.com/PowerScript/KatanaFramework/blob/0f6ad90a88de865d58ec26941cb4460501e75496/lib/scapy/scapy/utils6.py#L587-L602
cleverhans-lab/cleverhans
e5d00e537ce7ad6119ed5a8db1f0e9736d1f6e1d
cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/classification_results.py
python
ResultMatrix.__getitem__
(self, key)
return self._items.get(key, self._default_value)
Returns element of the matrix indexed by given key. Args: key: tuple of (row_idx, column_idx) Returns: Element of the matrix Raises: IndexError: if key is invalid.
Returns element of the matrix indexed by given key.
[ "Returns", "element", "of", "the", "matrix", "indexed", "by", "given", "key", "." ]
def __getitem__(self, key): """Returns element of the matrix indexed by given key. Args: key: tuple of (row_idx, column_idx) Returns: Element of the matrix Raises: IndexError: if key is invalid. """ if not isinstance(key, tuple) or len(key) != 2: raise IndexError("Invalid index: {0}".format(key)) return self._items.get(key, self._default_value)
[ "def", "__getitem__", "(", "self", ",", "key", ")", ":", "if", "not", "isinstance", "(", "key", ",", "tuple", ")", "or", "len", "(", "key", ")", "!=", "2", ":", "raise", "IndexError", "(", "\"Invalid index: {0}\"", ".", "format", "(", "key", ")", ")"...
https://github.com/cleverhans-lab/cleverhans/blob/e5d00e537ce7ad6119ed5a8db1f0e9736d1f6e1d/cleverhans_v3.1.0/examples/nips17_adversarial_competition/eval_infra/code/eval_lib/classification_results.py#L167-L181
thinkle/gourmet
8af29c8ded24528030e5ae2ea3461f61c1e5a575
gourmet/Undo.py
python
MultipleUndoLists.insert
(self,*args,**kwargs)
return self.get_history().insert(*args,**kwargs)
[]
def insert (self,*args,**kwargs): return self.get_history().insert(*args,**kwargs)
[ "def", "insert", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "get_history", "(", ")", ".", "insert", "(", "*", "args", ",", "*", "*", "kwargs", ")" ]
https://github.com/thinkle/gourmet/blob/8af29c8ded24528030e5ae2ea3461f61c1e5a575/gourmet/Undo.py#L534-L534
stanfordnlp/spinn
f2f95f585328ec5cd7da071753f5e0582e7600a0
python/spinn/models/classifier.py
python
build_transition_cost
(logits, targets, num_transitions)
return cost, acc
Build a parse action prediction cost function.
Build a parse action prediction cost function.
[ "Build", "a", "parse", "action", "prediction", "cost", "function", "." ]
def build_transition_cost(logits, targets, num_transitions): """ Build a parse action prediction cost function. """ # swap seq_length dimension to front so that we can scan per timestep logits = T.swapaxes(logits, 0, 1) targets = targets.T def cost_t(logits, tgt, num_transitions): # TODO(jongauthier): Taper down xent cost as we proceed through # sequence? predicted_dist = T.nnet.softmax(logits) cost = T.nnet.categorical_crossentropy(predicted_dist, tgt) pred = T.argmax(logits, axis=1) error = T.neq(pred, tgt) return cost, error results, _ = theano.scan(cost_t, [logits, targets], non_sequences=[num_transitions]) costs, errors = results # Create a mask that selects only transitions that involve real data. unrolling_length = T.shape(costs)[0] padding = unrolling_length - num_transitions padding = T.reshape(padding, (1, -1)) rng = T.arange(unrolling_length) + 1 rng = T.reshape(rng, (-1, 1)) mask = T.gt(rng, padding) # Compute acc using the mask acc = 1.0 - (T.sum(errors * mask, dtype=theano.config.floatX) / T.sum(num_transitions, dtype=theano.config.floatX)) # Compute cost directly, since we *do* want a cost incentive to get the padding # transitions right. cost = T.mean(costs) return cost, acc
[ "def", "build_transition_cost", "(", "logits", ",", "targets", ",", "num_transitions", ")", ":", "# swap seq_length dimension to front so that we can scan per timestep", "logits", "=", "T", ".", "swapaxes", "(", "logits", ",", "0", ",", "1", ")", "targets", "=", "ta...
https://github.com/stanfordnlp/spinn/blob/f2f95f585328ec5cd7da071753f5e0582e7600a0/python/spinn/models/classifier.py#L273-L310
kubernetes-client/python
47b9da9de2d02b2b7a34fbe05afb44afd130d73a
kubernetes/client/models/v1_component_status.py
python
V1ComponentStatus.to_str
(self)
return pprint.pformat(self.to_dict())
Returns the string representation of the model
Returns the string representation of the model
[ "Returns", "the", "string", "representation", "of", "the", "model" ]
def to_str(self): """Returns the string representation of the model""" return pprint.pformat(self.to_dict())
[ "def", "to_str", "(", "self", ")", ":", "return", "pprint", ".", "pformat", "(", "self", ".", "to_dict", "(", ")", ")" ]
https://github.com/kubernetes-client/python/blob/47b9da9de2d02b2b7a34fbe05afb44afd130d73a/kubernetes/client/models/v1_component_status.py#L184-L186
pydata/patsy
5fc881104b749b720b08e393a5505d6e69d72f95
patsy/compat_ordereddict.py
python
OrderedDict.iteritems
(self)
od.iteritems -> an iterator over the (key, value) items in od
od.iteritems -> an iterator over the (key, value) items in od
[ "od", ".", "iteritems", "-", ">", "an", "iterator", "over", "the", "(", "key", "value", ")", "items", "in", "od" ]
def iteritems(self): 'od.iteritems -> an iterator over the (key, value) items in od' for k in self: yield (k, self[k])
[ "def", "iteritems", "(", "self", ")", ":", "for", "k", "in", "self", ":", "yield", "(", "k", ",", "self", "[", "k", "]", ")" ]
https://github.com/pydata/patsy/blob/5fc881104b749b720b08e393a5505d6e69d72f95/patsy/compat_ordereddict.py#L144-L147
scrapy/scrapy
b04cfa48328d5d5749dca6f50fa34e0cfc664c89
scrapy/utils/defer.py
python
maybe_deferred_to_future
(d: Deferred)
.. versionadded:: VERSION Return *d* as an object that can be awaited from a :ref:`Scrapy callable defined as a coroutine <coroutine-support>`. What you can await in Scrapy callables defined as coroutines depends on the value of :setting:`TWISTED_REACTOR`: - When not using the asyncio reactor, you can only await on :class:`~twisted.internet.defer.Deferred` objects. - When :ref:`using the asyncio reactor <install-asyncio>`, you can only await on :class:`asyncio.Future` objects. If you want to write code that uses ``Deferred`` objects but works with any reactor, use this function on all ``Deferred`` objects:: class MySpider(Spider): ... async def parse(self, response): d = treq.get('https://example.com/additional') extra_response = await maybe_deferred_to_future(d)
.. versionadded:: VERSION
[ "..", "versionadded", "::", "VERSION" ]
def maybe_deferred_to_future(d: Deferred) -> Union[Deferred, Future]: """ .. versionadded:: VERSION Return *d* as an object that can be awaited from a :ref:`Scrapy callable defined as a coroutine <coroutine-support>`. What you can await in Scrapy callables defined as coroutines depends on the value of :setting:`TWISTED_REACTOR`: - When not using the asyncio reactor, you can only await on :class:`~twisted.internet.defer.Deferred` objects. - When :ref:`using the asyncio reactor <install-asyncio>`, you can only await on :class:`asyncio.Future` objects. If you want to write code that uses ``Deferred`` objects but works with any reactor, use this function on all ``Deferred`` objects:: class MySpider(Spider): ... async def parse(self, response): d = treq.get('https://example.com/additional') extra_response = await maybe_deferred_to_future(d) """ if not is_asyncio_reactor_installed(): return d else: return deferred_to_future(d)
[ "def", "maybe_deferred_to_future", "(", "d", ":", "Deferred", ")", "->", "Union", "[", "Deferred", ",", "Future", "]", ":", "if", "not", "is_asyncio_reactor_installed", "(", ")", ":", "return", "d", "else", ":", "return", "deferred_to_future", "(", "d", ")" ...
https://github.com/scrapy/scrapy/blob/b04cfa48328d5d5749dca6f50fa34e0cfc664c89/scrapy/utils/defer.py#L204-L232
memray/seq2seq-keyphrase
9145c63ebdc4c3bc431f8091dc52547a46804012
emolga/dataset/build_dataset.py
python
deserialize_from_file_hdf5
(path)
return obj
[]
def deserialize_from_file_hdf5(path): f = open(path, 'r') obj = hickle.load(f) f.close() return obj
[ "def", "deserialize_from_file_hdf5", "(", "path", ")", ":", "f", "=", "open", "(", "path", ",", "'r'", ")", "obj", "=", "hickle", ".", "load", "(", "f", ")", "f", ".", "close", "(", ")", "return", "obj" ]
https://github.com/memray/seq2seq-keyphrase/blob/9145c63ebdc4c3bc431f8091dc52547a46804012/emolga/dataset/build_dataset.py#L58-L62
securityclippy/elasticintel
aa08d3e9f5ab1c000128e95161139ce97ff0e334
whois_lambda/ipwhois/whois.py
python
Whois.get_nets_other
(self, response)
return nets
The function for parsing network blocks from generic whois data. Args: response (:obj:`str`): The response from the whois/rwhois server. Returns: list of dict: Mapping of networks with start and end positions. :: [{ 'cidr' (str) - The network routing block 'start' (int) - The starting point of the network 'end' (int) - The endpoint point of the network }]
The function for parsing network blocks from generic whois data.
[ "The", "function", "for", "parsing", "network", "blocks", "from", "generic", "whois", "data", "." ]
def get_nets_other(self, response): """ The function for parsing network blocks from generic whois data. Args: response (:obj:`str`): The response from the whois/rwhois server. Returns: list of dict: Mapping of networks with start and end positions. :: [{ 'cidr' (str) - The network routing block 'start' (int) - The starting point of the network 'end' (int) - The endpoint point of the network }] """ nets = [] # Iterate through all of the networks found, storing the CIDR value # and the start and end positions. for match in re.finditer( r'^(inetnum|inet6num|route):[^\S\n]+((.+?)[^\S\n]-[^\S\n](.+)|' '.+)$', response, re.MULTILINE ): try: net = copy.deepcopy(BASE_NET) net_range = match.group(2).strip() try: net['range'] = net['range'] = '{0} - {1}'.format( ip_network(net_range)[0].__str__(), ip_network(net_range)[-1].__str__() ) if '/' in net_range else net_range except ValueError: # pragma: no cover net['range'] = net_range if match.group(3) and match.group(4): addrs = [] addrs.extend(summarize_address_range( ip_address(match.group(3).strip()), ip_address(match.group(4).strip()))) cidr = ', '.join( [i.__str__() for i in collapse_addresses(addrs)] ) else: cidr = ip_network(net_range).__str__() net['cidr'] = cidr net['start'] = match.start() net['end'] = match.end() nets.append(net) except (ValueError, TypeError): pass return nets
[ "def", "get_nets_other", "(", "self", ",", "response", ")", ":", "nets", "=", "[", "]", "# Iterate through all of the networks found, storing the CIDR value", "# and the start and end positions.", "for", "match", "in", "re", ".", "finditer", "(", "r'^(inetnum|inet6num|route...
https://github.com/securityclippy/elasticintel/blob/aa08d3e9f5ab1c000128e95161139ce97ff0e334/whois_lambda/ipwhois/whois.py#L508-L578
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/Python-2.7.9/Lib/idlelib/ColorDelegator.py
python
_color_delegator
(parent)
[]
def _color_delegator(parent): # htest # from Tkinter import Toplevel, Text from idlelib.Percolator import Percolator top = Toplevel(parent) top.title("Test ColorDelegator") top.geometry("200x100+%d+%d" % (parent.winfo_rootx() + 200, parent.winfo_rooty() + 150)) source = "if somename: x = 'abc' # comment\nprint\n" text = Text(top, background="white") text.pack(expand=1, fill="both") text.insert("insert", source) text.focus_set() p = Percolator(text) d = ColorDelegator() p.insertfilter(d)
[ "def", "_color_delegator", "(", "parent", ")", ":", "# htest #", "from", "Tkinter", "import", "Toplevel", ",", "Text", "from", "idlelib", ".", "Percolator", "import", "Percolator", "top", "=", "Toplevel", "(", "parent", ")", "top", ".", "title", "(", "\"Test...
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/Python-2.7.9/Lib/idlelib/ColorDelegator.py#L238-L254
gwastro/pycbc
1e1c85534b9dba8488ce42df693230317ca63dea
pycbc/waveform/ringdown.py
python
format_lmns
(lmns)
return out
Checks if the format of the parameter lmns is correct, returning the appropriate format if not, and raise an error if nmodes=0. The required format for the ringdown approximants is a list of lmn modes as a single whitespace-separated string, with n the number of overtones desired. Alternatively, a list object may be used, containing individual strings as elements for the lmn modes. For instance, lmns = '223 331' are the modes 220, 221, 222, and 330. Giving lmns = ['223', '331'] is equivalent. The ConfigParser of a workflow might convert that to a single string (case 1 below) or a list with a single string (case 2), and this function will return the appropriate list of strings. If a different format is given, raise an error.
Checks if the format of the parameter lmns is correct, returning the appropriate format if not, and raise an error if nmodes=0.
[ "Checks", "if", "the", "format", "of", "the", "parameter", "lmns", "is", "correct", "returning", "the", "appropriate", "format", "if", "not", "and", "raise", "an", "error", "if", "nmodes", "=", "0", "." ]
def format_lmns(lmns): """Checks if the format of the parameter lmns is correct, returning the appropriate format if not, and raise an error if nmodes=0. The required format for the ringdown approximants is a list of lmn modes as a single whitespace-separated string, with n the number of overtones desired. Alternatively, a list object may be used, containing individual strings as elements for the lmn modes. For instance, lmns = '223 331' are the modes 220, 221, 222, and 330. Giving lmns = ['223', '331'] is equivalent. The ConfigParser of a workflow might convert that to a single string (case 1 below) or a list with a single string (case 2), and this function will return the appropriate list of strings. If a different format is given, raise an error. """ # Catch case of lmns given as float (as int injection values are cast # to float by pycbc_create_injections), cast to int, then string if isinstance(lmns, float): lmns = str(int(lmns)) # Case 1: the lmns are given as a string, e.g. '221 331' if isinstance(lmns, str): lmns = lmns.split(' ') # Case 2: the lmns are given as strings in a list, e.g. ['221', '331'] elif isinstance(lmns, list): pass else: raise ValueError('Format of parameter lmns not recognized. See ' 'approximant documentation for more info.') out = [] # Cycle over the lmns to ensure that we get back a list of strings that # are three digits long, and that nmodes!=0 for lmn in lmns: # The following line is to be used with Python3 if the lmns are stored # as a list of strings in the HDF files and the workflow converts that # to a string # lmn = lmn.strip(" b'") # Try to convert to int and then str, to ensure the right format lmn = str(int(lmn)) if len(lmn) != 3: raise ValueError('Format of parameter lmns not recognized. See ' 'approximant documentation for more info.') elif int(lmn[2]) == 0: raise ValueError('Number of overtones (nmodes) must be greater ' 'than zero in lmn={}.'.format(lmn)) out.append(lmn) return out
[ "def", "format_lmns", "(", "lmns", ")", ":", "# Catch case of lmns given as float (as int injection values are cast", "# to float by pycbc_create_injections), cast to int, then string", "if", "isinstance", "(", "lmns", ",", "float", ")", ":", "lmns", "=", "str", "(", "int", ...
https://github.com/gwastro/pycbc/blob/1e1c85534b9dba8488ce42df693230317ca63dea/pycbc/waveform/ringdown.py#L72-L120
zetaops/ulakbus
bcc05abf17bbd6dbeec93809e4ad30885e94e83e
ulakbus/services/personel/hitap/hitap_service.py
python
ZatoHitapService.date_filter_hitap_to_ulakbus
(date_filter_fields, response_payload)
date_filter_ulakbus_to_hitap metodunun tersi icin gereklidir. Args: date_filter_fields (list): Zato servisinde bulunan ve tarih formatinda olan field isimleri listesi response_payload (dict): gonderilen kayit degerleri
date_filter_ulakbus_to_hitap metodunun tersi icin gereklidir.
[ "date_filter_ulakbus_to_hitap", "metodunun", "tersi", "icin", "gereklidir", "." ]
def date_filter_hitap_to_ulakbus(date_filter_fields, response_payload): """ date_filter_ulakbus_to_hitap metodunun tersi icin gereklidir. Args: date_filter_fields (list): Zato servisinde bulunan ve tarih formatinda olan field isimleri listesi response_payload (dict): gonderilen kayit degerleri """ from datetime import datetime for field in date_filter_fields: if response_payload[field] == "0001-01-01": response_payload[field] = '01.01.1900' else: date_format = datetime.strptime(response_payload[field], "%Y-%m-%d") response_payload[field] = date_format.strftime("%d.%m.%Y")
[ "def", "date_filter_hitap_to_ulakbus", "(", "date_filter_fields", ",", "response_payload", ")", ":", "from", "datetime", "import", "datetime", "for", "field", "in", "date_filter_fields", ":", "if", "response_payload", "[", "field", "]", "==", "\"0001-01-01\"", ":", ...
https://github.com/zetaops/ulakbus/blob/bcc05abf17bbd6dbeec93809e4ad30885e94e83e/ulakbus/services/personel/hitap/hitap_service.py#L195-L213
robotlearn/pyrobolearn
9cd7c060723fda7d2779fa255ac998c2c82b8436
pyrobolearn/priorities/tasks/task.py
python
Task.tasks
(self, tasks)
Set the stack of tasks.
Set the stack of tasks.
[ "Set", "the", "stack", "of", "tasks", "." ]
def tasks(self, tasks): """Set the stack of tasks.""" # check type if tasks is None or (isinstance(tasks, (list, tuple)) and len(tasks) == 0): tasks = [[]] if not isinstance(tasks, (list, tuple)): raise TypeError("Expecting the given 'tasks', to be a list of list of `Task`, instead got: " "{}".format(type(tasks))) # go through the stack of tasks for i, hard_task in enumerate(tasks): # if the hard task is a list of soft tasks if isinstance(hard_task, (list, tuple)): # go through each soft task in the hard task for j, soft_task in enumerate(hard_task): if not isinstance(soft_task, Task): if isinstance(soft_task, Constraint): # if constraint (must be an equality constraint), try to convert it into a task tasks[i][j] = prl.priorities.tasks.TaskFromConstraint(soft_task) else: raise TypeError("The given task positioned at ({}, {}) is not an instance of `Task`, " "but: {}".format(i, j, type(soft_task))) else: # if not, check that the hard task is an instance of Task if not isinstance(hard_task, Task): raise TypeError("Expecting the {}th hard task to be an instance of `Task` or a list of `Task`, " "instead got: {}".format(i, type(hard_task))) tasks[i] = [task] # set the stack of tasks self._tasks = tasks
[ "def", "tasks", "(", "self", ",", "tasks", ")", ":", "# check type", "if", "tasks", "is", "None", "or", "(", "isinstance", "(", "tasks", ",", "(", "list", ",", "tuple", ")", ")", "and", "len", "(", "tasks", ")", "==", "0", ")", ":", "tasks", "=",...
https://github.com/robotlearn/pyrobolearn/blob/9cd7c060723fda7d2779fa255ac998c2c82b8436/pyrobolearn/priorities/tasks/task.py#L193-L223
olist/correios
5494d7457665fa9a8dffbffa976cdbd2885c54e4
correios/models/user.py
python
AbstractTaxNumber.__eq__
(self, other)
return self.number == self._sanitize(other)
[]
def __eq__(self, other): return self.number == self._sanitize(other)
[ "def", "__eq__", "(", "self", ",", "other", ")", ":", "return", "self", ".", "number", "==", "self", ".", "_sanitize", "(", "other", ")" ]
https://github.com/olist/correios/blob/5494d7457665fa9a8dffbffa976cdbd2885c54e4/correios/models/user.py#L82-L83
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/lib/python2.7/site-packages/pip/_vendor/packaging/version.py
python
_parse_letter_version
(letter, number)
[]
def _parse_letter_version(letter, number): if letter: # We consider there to be an implicit 0 in a pre-release if there is # not a numeral associated with it. if number is None: number = 0 # We normalize any letters to their lower case form letter = letter.lower() # We consider some words to be alternate spellings of other words and # in those cases we want to normalize the spellings to our preferred # spelling. if letter == "alpha": letter = "a" elif letter == "beta": letter = "b" elif letter in ["c", "pre", "preview"]: letter = "rc" elif letter in ["rev", "r"]: letter = "post" return letter, int(number) if not letter and number: # We assume if we are given a number, but we are not given a letter # then this is using the implicit post release syntax (e.g. 1.0-1) letter = "post" return letter, int(number)
[ "def", "_parse_letter_version", "(", "letter", ",", "number", ")", ":", "if", "letter", ":", "# We consider there to be an implicit 0 in a pre-release if there is", "# not a numeral associated with it.", "if", "number", "is", "None", ":", "number", "=", "0", "# We normalize...
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/lib/python2.7/site-packages/pip/_vendor/packaging/version.py#L346-L374
freedomofpress/securedrop
f768a1a5aa37e790077dfd38d6e7a0299a4b3a0f
admin/securedrop_admin/__init__.py
python
get_logs
(args: argparse.Namespace)
return 0
Get logs for forensics and debugging purposes
Get logs for forensics and debugging purposes
[ "Get", "logs", "for", "forensics", "and", "debugging", "purposes" ]
def get_logs(args: argparse.Namespace) -> int: """Get logs for forensics and debugging purposes""" sdlog.info("Gathering logs for forensics and debugging") ansible_cmd = [ 'ansible-playbook', os.path.join(args.ansible_path, 'securedrop-logs.yml'), ] subprocess.check_call(ansible_cmd, cwd=args.ansible_path) sdlog.info("Please send the encrypted logs to securedrop@freedom.press or " "upload them to the SecureDrop support portal: " + SUPPORT_URL) return 0
[ "def", "get_logs", "(", "args", ":", "argparse", ".", "Namespace", ")", "->", "int", ":", "sdlog", ".", "info", "(", "\"Gathering logs for forensics and debugging\"", ")", "ansible_cmd", "=", "[", "'ansible-playbook'", ",", "os", ".", "path", ".", "join", "(",...
https://github.com/freedomofpress/securedrop/blob/f768a1a5aa37e790077dfd38d6e7a0299a4b3a0f/admin/securedrop_admin/__init__.py#L1003-L1013
simonw/djangopeople.net
ed04d3c79d03b9c74f3e7f82b2af944e021f8e15
lib/yadis/discover.py
python
DiscoveryResult.usedYadisLocation
(self)
return self.normalized_uri == self.xrds_uri
Was the Yadis protocol's indirection used?
Was the Yadis protocol's indirection used?
[ "Was", "the", "Yadis", "protocol", "s", "indirection", "used?" ]
def usedYadisLocation(self): """Was the Yadis protocol's indirection used?""" return self.normalized_uri == self.xrds_uri
[ "def", "usedYadisLocation", "(", "self", ")", ":", "return", "self", ".", "normalized_uri", "==", "self", ".", "xrds_uri" ]
https://github.com/simonw/djangopeople.net/blob/ed04d3c79d03b9c74f3e7f82b2af944e021f8e15/lib/yadis/discover.py#L46-L48
openstack/barbican
a9d2b133c8dc3307974f119f9a2b23a4ba82e8ce
barbican/plugin/snakeoil_ca.py
python
SnakeoilCA.pkcs7
(self, val)
[]
def pkcs7(self, val): if self.pkcs7_path: with open(self.pkcs7_path, 'wb') as pkcs7_fh: pkcs7_fh.write(val) else: self._pkcs7_val = val
[ "def", "pkcs7", "(", "self", ",", "val", ")", ":", "if", "self", ".", "pkcs7_path", ":", "with", "open", "(", "self", ".", "pkcs7_path", ",", "'wb'", ")", "as", "pkcs7_fh", ":", "pkcs7_fh", ".", "write", "(", "val", ")", "else", ":", "self", ".", ...
https://github.com/openstack/barbican/blob/a9d2b133c8dc3307974f119f9a2b23a4ba82e8ce/barbican/plugin/snakeoil_ca.py#L186-L191
edisonlz/fastor
342078a18363ac41d3c6b1ab29dbdd44fdb0b7b3
base/site-packages/requests/adapters.py
python
HTTPAdapter.close
(self)
Disposes of any internal state. Currently, this just closes the PoolManager, which closes pooled connections.
Disposes of any internal state.
[ "Disposes", "of", "any", "internal", "state", "." ]
def close(self): """Disposes of any internal state. Currently, this just closes the PoolManager, which closes pooled connections. """ self.poolmanager.clear()
[ "def", "close", "(", "self", ")", ":", "self", ".", "poolmanager", ".", "clear", "(", ")" ]
https://github.com/edisonlz/fastor/blob/342078a18363ac41d3c6b1ab29dbdd44fdb0b7b3/base/site-packages/requests/adapters.py#L264-L270
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/flux_led/light.py
python
FluxLight._async_set_mode
(self, **kwargs: Any)
Set an effect or color mode.
Set an effect or color mode.
[ "Set", "an", "effect", "or", "color", "mode", "." ]
async def _async_set_mode(self, **kwargs: Any) -> None: """Set an effect or color mode.""" brightness = self._async_brightness(**kwargs) # Handle switch to Effect Mode if effect := kwargs.get(ATTR_EFFECT): await self._async_set_effect(effect, brightness) return # Handle switch to CCT Color Mode if color_temp_mired := kwargs.get(ATTR_COLOR_TEMP): color_temp_kelvin = color_temperature_mired_to_kelvin(color_temp_mired) if ( ATTR_BRIGHTNESS not in kwargs and self.color_mode in MULTI_BRIGHTNESS_COLOR_MODES ): # When switching to color temp from RGBWW or RGB&W mode, # we do not want the overall brightness of the RGB channels brightness = max(self._device.rgb) await self._device.async_set_white_temp(color_temp_kelvin, brightness) return # Handle switch to RGB Color Mode if rgb := kwargs.get(ATTR_RGB_COLOR): if not self._device.requires_turn_on: rgb = _min_rgb_brightness(rgb) red, green, blue = rgb await self._device.async_set_levels(red, green, blue, brightness=brightness) return # Handle switch to RGBW Color Mode if rgbw := kwargs.get(ATTR_RGBW_COLOR): if ATTR_BRIGHTNESS in kwargs: rgbw = rgbw_brightness(rgbw, brightness) if not self._device.requires_turn_on: rgbw = _min_rgbw_brightness(rgbw) await self._device.async_set_levels(*rgbw) return # Handle switch to RGBWW Color Mode if rgbcw := kwargs.get(ATTR_RGBWW_COLOR): if ATTR_BRIGHTNESS in kwargs: rgbcw = rgbcw_brightness(kwargs[ATTR_RGBWW_COLOR], brightness) rgbwc = rgbcw_to_rgbwc(rgbcw) if not self._device.requires_turn_on: rgbwc = _min_rgbwc_brightness(rgbwc) await self._device.async_set_levels(*rgbwc) return if (white := kwargs.get(ATTR_WHITE)) is not None: await self._device.async_set_levels(w=white) return
[ "async", "def", "_async_set_mode", "(", "self", ",", "*", "*", "kwargs", ":", "Any", ")", "->", "None", ":", "brightness", "=", "self", ".", "_async_brightness", "(", "*", "*", "kwargs", ")", "# Handle switch to Effect Mode", "if", "effect", ":=", "kwargs", ...
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/flux_led/light.py#L295-L340
Tautulli/Tautulli
2410eb33805aaac4bd1c5dad0f71e4f15afaf742
lib/oauthlib/oauth1/rfc5849/utils.py
python
filter_oauth_params
(params)
Removes all non oauth parameters from a dict or a list of params.
Removes all non oauth parameters from a dict or a list of params.
[ "Removes", "all", "non", "oauth", "parameters", "from", "a", "dict", "or", "a", "list", "of", "params", "." ]
def filter_oauth_params(params): """Removes all non oauth parameters from a dict or a list of params.""" is_oauth = lambda kv: kv[0].startswith("oauth_") if isinstance(params, dict): return list(filter(is_oauth, list(params.items()))) else: return list(filter(is_oauth, params))
[ "def", "filter_oauth_params", "(", "params", ")", ":", "is_oauth", "=", "lambda", "kv", ":", "kv", "[", "0", "]", ".", "startswith", "(", "\"oauth_\"", ")", "if", "isinstance", "(", "params", ",", "dict", ")", ":", "return", "list", "(", "filter", "(",...
https://github.com/Tautulli/Tautulli/blob/2410eb33805aaac4bd1c5dad0f71e4f15afaf742/lib/oauthlib/oauth1/rfc5849/utils.py#L31-L37
miyakogi/pyppeteer
f5313d0e7f973c57ed31fa443cea1834e223a96c
pyppeteer/chromium_downloader.py
python
chromium_executable
()
return chromiumExecutable[current_platform()]
Get path of the chromium executable.
Get path of the chromium executable.
[ "Get", "path", "of", "the", "chromium", "executable", "." ]
def chromium_executable() -> Path: """Get path of the chromium executable.""" return chromiumExecutable[current_platform()]
[ "def", "chromium_executable", "(", ")", "->", "Path", ":", "return", "chromiumExecutable", "[", "current_platform", "(", ")", "]" ]
https://github.com/miyakogi/pyppeteer/blob/f5313d0e7f973c57ed31fa443cea1834e223a96c/pyppeteer/chromium_downloader.py#L158-L160
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/modular/hecke/module.py
python
HeckeModule_free_module._eigen_nonzero
(self)
Return the smallest integer `i` such that the `i`-th entries of the entries of a basis for the dual vector space are not all 0. EXAMPLES:: sage: M = ModularSymbols(31,2) sage: M._eigen_nonzero() 0 sage: M.dual_free_module().basis() [ (1, 0, 0, 0, 0), (0, 1, 0, 0, 0), (0, 0, 1, 0, 0), (0, 0, 0, 1, 0), (0, 0, 0, 0, 1) ] sage: M.cuspidal_submodule().minus_submodule()._eigen_nonzero() 1 sage: M.cuspidal_submodule().minus_submodule().dual_free_module().basis() [ (0, 1, 0, 0, 0), (0, 0, 1, 0, 0) ]
Return the smallest integer `i` such that the `i`-th entries of the entries of a basis for the dual vector space are not all 0.
[ "Return", "the", "smallest", "integer", "i", "such", "that", "the", "i", "-", "th", "entries", "of", "the", "entries", "of", "a", "basis", "for", "the", "dual", "vector", "space", "are", "not", "all", "0", "." ]
def _eigen_nonzero(self): """ Return the smallest integer `i` such that the `i`-th entries of the entries of a basis for the dual vector space are not all 0. EXAMPLES:: sage: M = ModularSymbols(31,2) sage: M._eigen_nonzero() 0 sage: M.dual_free_module().basis() [ (1, 0, 0, 0, 0), (0, 1, 0, 0, 0), (0, 0, 1, 0, 0), (0, 0, 0, 1, 0), (0, 0, 0, 0, 1) ] sage: M.cuspidal_submodule().minus_submodule()._eigen_nonzero() 1 sage: M.cuspidal_submodule().minus_submodule().dual_free_module().basis() [ (0, 1, 0, 0, 0), (0, 0, 1, 0, 0) ] """ try: return self.__eigen_nonzero except AttributeError: pass V = self.dual_free_module() B = V.basis() for i in range(V.degree()): for b in B: if b[i] != 0: self.__eigen_nonzero = i return i assert False, 'bug in _eigen_nonzero'
[ "def", "_eigen_nonzero", "(", "self", ")", ":", "try", ":", "return", "self", ".", "__eigen_nonzero", "except", "AttributeError", ":", "pass", "V", "=", "self", ".", "dual_free_module", "(", ")", "B", "=", "V", ".", "basis", "(", ")", "for", "i", "in",...
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/modular/hecke/module.py#L569-L606
kubeflow-kale/kale
bda9d296822e56ba8fe76b0072e656005da04905
backend/kale/common/serveutils.py
python
KFServer.__repr__
(self)
Show an interactive text in notebooks.
Show an interactive text in notebooks.
[ "Show", "an", "interactive", "text", "in", "notebooks", "." ]
def __repr__(self): """Show an interactive text in notebooks.""" if utils.is_ipython(): import IPython html = ('InferenceService <pre>%s</pre> serving requests at host' ' <pre>%s</pre><br>' 'View model <a href="/models/details/%s/%s"' ' target="_blank" >here</a>' % (self.name, get_inference_service_host(self.name), podutils.get_namespace(), self.name)) IPython.display.display(IPython.display.HTML(html)) return "" else: return super(KFServer, self).__repr__()
[ "def", "__repr__", "(", "self", ")", ":", "if", "utils", ".", "is_ipython", "(", ")", ":", "import", "IPython", "html", "=", "(", "'InferenceService <pre>%s</pre> serving requests at host'", "' <pre>%s</pre><br>'", "'View model <a href=\"/models/details/%s/%s\"'", "' target...
https://github.com/kubeflow-kale/kale/blob/bda9d296822e56ba8fe76b0072e656005da04905/backend/kale/common/serveutils.py#L117-L132
ycszen/TorchSeg
62eeb159aee77972048d9d7688a28249d3c56735
furnace/tools/benchmark/compute_flops.py
python
compute_ReLU_flops
(module, inp, out)
return active_elements_count
[]
def compute_ReLU_flops(module, inp, out): assert isinstance(module, (nn.ReLU, nn.ReLU6, nn.PReLU, nn.ELU, nn.LeakyReLU, nn.Sigmoid)) batch_size = inp.size()[0] active_elements_count = batch_size for s in inp.size()[1:]: active_elements_count *= s return active_elements_count
[ "def", "compute_ReLU_flops", "(", "module", ",", "inp", ",", "out", ")", ":", "assert", "isinstance", "(", "module", ",", "(", "nn", ".", "ReLU", ",", "nn", ".", "ReLU6", ",", "nn", ".", "PReLU", ",", "nn", ".", "ELU", ",", "nn", ".", "LeakyReLU", ...
https://github.com/ycszen/TorchSeg/blob/62eeb159aee77972048d9d7688a28249d3c56735/furnace/tools/benchmark/compute_flops.py#L64-L74
kubeflow/pipelines
bea751c9259ff0ae85290f873170aae89284ba8e
backend/api/python_http_client/kfp_server_api/api/experiment_service_api.py
python
ExperimentServiceApi.delete_experiment_with_http_info
(self, id, **kwargs)
return self.api_client.call_api( '/apis/v1beta1/experiments/{id}', 'DELETE', path_params, query_params, header_params, body=body_params, post_params=form_params, files=local_var_files, response_type='object', # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 _preload_content=local_var_params.get('_preload_content', True), _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats)
Deletes an experiment without deleting the experiment's runs and jobs. To avoid unexpected behaviors, delete an experiment's runs and jobs before deleting the experiment. # noqa: E501 This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req=True >>> thread = api.delete_experiment_with_http_info(id, async_req=True) >>> result = thread.get() :param id: The ID of the experiment to be deleted. (required) :type id: str :param async_req: Whether to execute the request asynchronously. :type async_req: bool, optional :param _return_http_data_only: response data without head status code and headers :type _return_http_data_only: bool, optional :param _preload_content: if False, the urllib3.HTTPResponse object will be returned without reading/decoding response data. Default is True. :type _preload_content: bool, optional :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of (connection, read) timeouts. :return: Returns the result object. If the method is called asynchronously, returns the request thread. :rtype: tuple(object, status_code(int), headers(HTTPHeaderDict))
Deletes an experiment without deleting the experiment's runs and jobs. To avoid unexpected behaviors, delete an experiment's runs and jobs before deleting the experiment. # noqa: E501
[ "Deletes", "an", "experiment", "without", "deleting", "the", "experiment", "s", "runs", "and", "jobs", ".", "To", "avoid", "unexpected", "behaviors", "delete", "an", "experiment", "s", "runs", "and", "jobs", "before", "deleting", "the", "experiment", ".", "#",...
def delete_experiment_with_http_info(self, id, **kwargs): # noqa: E501 """Deletes an experiment without deleting the experiment's runs and jobs. To avoid unexpected behaviors, delete an experiment's runs and jobs before deleting the experiment. # noqa: E501 This method makes a synchronous HTTP request by default. To make an asynchronous HTTP request, please pass async_req=True >>> thread = api.delete_experiment_with_http_info(id, async_req=True) >>> result = thread.get() :param id: The ID of the experiment to be deleted. (required) :type id: str :param async_req: Whether to execute the request asynchronously. :type async_req: bool, optional :param _return_http_data_only: response data without head status code and headers :type _return_http_data_only: bool, optional :param _preload_content: if False, the urllib3.HTTPResponse object will be returned without reading/decoding response data. Default is True. :type _preload_content: bool, optional :param _request_timeout: timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of (connection, read) timeouts. :return: Returns the result object. If the method is called asynchronously, returns the request thread. :rtype: tuple(object, status_code(int), headers(HTTPHeaderDict)) """ local_var_params = locals() all_params = [ 'id' ] all_params.extend( [ 'async_req', '_return_http_data_only', '_preload_content', '_request_timeout' ] ) for key, val in six.iteritems(local_var_params['kwargs']): if key not in all_params: raise ApiTypeError( "Got an unexpected keyword argument '%s'" " to method delete_experiment" % key ) local_var_params[key] = val del local_var_params['kwargs'] # verify the required parameter 'id' is set if self.api_client.client_side_validation and ('id' not in local_var_params or # noqa: E501 local_var_params['id'] is None): # noqa: E501 raise ApiValueError("Missing the required parameter `id` when calling `delete_experiment`") # noqa: E501 collection_formats = {} path_params = {} if 'id' in local_var_params: path_params['id'] = local_var_params['id'] # noqa: E501 query_params = [] header_params = {} form_params = [] local_var_files = {} body_params = None # HTTP header `Accept` header_params['Accept'] = self.api_client.select_header_accept( ['application/json']) # noqa: E501 # Authentication setting auth_settings = ['Bearer'] # noqa: E501 return self.api_client.call_api( '/apis/v1beta1/experiments/{id}', 'DELETE', path_params, query_params, header_params, body=body_params, post_params=form_params, files=local_var_files, response_type='object', # noqa: E501 auth_settings=auth_settings, async_req=local_var_params.get('async_req'), _return_http_data_only=local_var_params.get('_return_http_data_only'), # noqa: E501 _preload_content=local_var_params.get('_preload_content', True), _request_timeout=local_var_params.get('_request_timeout'), collection_formats=collection_formats)
[ "def", "delete_experiment_with_http_info", "(", "self", ",", "id", ",", "*", "*", "kwargs", ")", ":", "# noqa: E501", "local_var_params", "=", "locals", "(", ")", "all_params", "=", "[", "'id'", "]", "all_params", ".", "extend", "(", "[", "'async_req'", ",",...
https://github.com/kubeflow/pipelines/blob/bea751c9259ff0ae85290f873170aae89284ba8e/backend/api/python_http_client/kfp_server_api/api/experiment_service_api.py#L315-L407
google/clusterfuzz
f358af24f414daa17a3649b143e71ea71871ef59
src/clusterfuzz/_internal/metrics/monitor.py
python
initialize
()
Initialize if monitoring is enabled for this bot.
Initialize if monitoring is enabled for this bot.
[ "Initialize", "if", "monitoring", "is", "enabled", "for", "this", "bot", "." ]
def initialize(): """Initialize if monitoring is enabled for this bot.""" global _monitoring_v3_client global _flusher_thread if environment.get_value('LOCAL_DEVELOPMENT'): return if not local_config.ProjectConfig().get('monitoring.enabled'): return if check_module_loaded(monitoring_v3): _initialize_monitored_resource() _monitoring_v3_client = monitoring_v3.MetricServiceClient( credentials=credentials.get_default()[0]) _flusher_thread = _FlusherThread() _flusher_thread.start()
[ "def", "initialize", "(", ")", ":", "global", "_monitoring_v3_client", "global", "_flusher_thread", "if", "environment", ".", "get_value", "(", "'LOCAL_DEVELOPMENT'", ")", ":", "return", "if", "not", "local_config", ".", "ProjectConfig", "(", ")", ".", "get", "(...
https://github.com/google/clusterfuzz/blob/f358af24f414daa17a3649b143e71ea71871ef59/src/clusterfuzz/_internal/metrics/monitor.py#L519-L535
mmatl/pyrender
4a289a6205c5baa623cd0e7da1be3d898bcbc4da
pyrender/shader_program.py
python
ShaderProgram.set_uniform
(self, name, value, unsigned=False)
Set a uniform value in the current shader program. Parameters ---------- name : str Name of the uniform to set. value : int, float, or ndarray Value to set the uniform to. unsigned : bool If True, ints will be treated as unsigned values.
Set a uniform value in the current shader program.
[ "Set", "a", "uniform", "value", "in", "the", "current", "shader", "program", "." ]
def set_uniform(self, name, value, unsigned=False): """Set a uniform value in the current shader program. Parameters ---------- name : str Name of the uniform to set. value : int, float, or ndarray Value to set the uniform to. unsigned : bool If True, ints will be treated as unsigned values. """ try: # DEBUG # self._unif_map[name] = 1, (1,) loc = glGetUniformLocation(self._program_id, name) if loc == -1: raise ValueError('Invalid shader variable: {}'.format(name)) if isinstance(value, np.ndarray): # DEBUG # self._unif_map[name] = value.size, value.shape if value.ndim == 1: if (np.issubdtype(value.dtype, np.unsignedinteger) or unsigned): dtype = 'u' value = value.astype(np.uint32) elif np.issubdtype(value.dtype, np.integer): dtype = 'i' value = value.astype(np.int32) else: dtype = 'f' value = value.astype(np.float32) self._FUNC_MAP[(value.shape[0], dtype)](loc, 1, value) else: self._FUNC_MAP[(value.shape[0], value.shape[1])]( loc, 1, GL_TRUE, value ) # Call correct uniform function elif isinstance(value, float): glUniform1f(loc, value) elif isinstance(value, int): if unsigned: glUniform1ui(loc, value) else: glUniform1i(loc, value) elif isinstance(value, bool): if unsigned: glUniform1ui(loc, int(value)) else: glUniform1i(loc, int(value)) else: raise ValueError('Invalid data type') except Exception: pass
[ "def", "set_uniform", "(", "self", ",", "name", ",", "value", ",", "unsigned", "=", "False", ")", ":", "try", ":", "# DEBUG", "# self._unif_map[name] = 1, (1,)", "loc", "=", "glGetUniformLocation", "(", "self", ".", "_program_id", ",", "name", ")", "if", "lo...
https://github.com/mmatl/pyrender/blob/4a289a6205c5baa623cd0e7da1be3d898bcbc4da/pyrender/shader_program.py#L203-L259
deepset-ai/haystack
79fdda8a7cf393d774803608a4874f2a6e63cf6f
haystack/document_stores/elasticsearch.py
python
ElasticsearchDocumentStore.update_embeddings
( self, retriever, index: Optional[str] = None, filters: Optional[Dict[str, List[str]]] = None, update_existing_embeddings: bool = True, batch_size: int = 10_000, headers: Optional[Dict[str, str]] = None )
Updates the embeddings in the the document store using the encoding model specified in the retriever. This can be useful if want to add or change the embeddings for your documents (e.g. after changing the retriever config). :param retriever: Retriever to use to update the embeddings. :param index: Index name to update :param update_existing_embeddings: Whether to update existing embeddings of the documents. If set to False, only documents without embeddings are processed. This mode can be used for incremental updating of embeddings, wherein, only newly indexed documents get processed. :param filters: Optional filters to narrow down the documents for which embeddings are to be updated. Example: {"name": ["some", "more"], "category": ["only_one"]} :param batch_size: When working with large number of documents, batching can help reduce memory footprint. :param headers: Custom HTTP headers to pass to elasticsearch client (e.g. {'Authorization': 'Basic YWRtaW46cm9vdA=='}) Check out https://www.elastic.co/guide/en/elasticsearch/reference/current/http-clients.html for more information. :return: None
Updates the embeddings in the the document store using the encoding model specified in the retriever. This can be useful if want to add or change the embeddings for your documents (e.g. after changing the retriever config).
[ "Updates", "the", "embeddings", "in", "the", "the", "document", "store", "using", "the", "encoding", "model", "specified", "in", "the", "retriever", ".", "This", "can", "be", "useful", "if", "want", "to", "add", "or", "change", "the", "embeddings", "for", ...
def update_embeddings( self, retriever, index: Optional[str] = None, filters: Optional[Dict[str, List[str]]] = None, update_existing_embeddings: bool = True, batch_size: int = 10_000, headers: Optional[Dict[str, str]] = None ): """ Updates the embeddings in the the document store using the encoding model specified in the retriever. This can be useful if want to add or change the embeddings for your documents (e.g. after changing the retriever config). :param retriever: Retriever to use to update the embeddings. :param index: Index name to update :param update_existing_embeddings: Whether to update existing embeddings of the documents. If set to False, only documents without embeddings are processed. This mode can be used for incremental updating of embeddings, wherein, only newly indexed documents get processed. :param filters: Optional filters to narrow down the documents for which embeddings are to be updated. Example: {"name": ["some", "more"], "category": ["only_one"]} :param batch_size: When working with large number of documents, batching can help reduce memory footprint. :param headers: Custom HTTP headers to pass to elasticsearch client (e.g. {'Authorization': 'Basic YWRtaW46cm9vdA=='}) Check out https://www.elastic.co/guide/en/elasticsearch/reference/current/http-clients.html for more information. :return: None """ if index is None: index = self.index if self.refresh_type == 'false': self.client.indices.refresh(index=index, headers=headers) if not self.embedding_field: raise RuntimeError("Specify the arg `embedding_field` when initializing ElasticsearchDocumentStore()") if update_existing_embeddings: document_count = self.get_document_count(index=index, headers=headers) logger.info(f"Updating embeddings for all {document_count} docs ...") else: document_count = self.get_document_count(index=index, filters=filters, only_documents_without_embedding=True, headers=headers) logger.info(f"Updating embeddings for {document_count} docs without embeddings ...") result = self._get_all_documents_in_index( index=index, filters=filters, batch_size=batch_size, only_documents_without_embedding=not update_existing_embeddings, headers=headers ) logging.getLogger("elasticsearch").setLevel(logging.CRITICAL) with tqdm(total=document_count, position=0, unit=" Docs", desc="Updating embeddings") as progress_bar: for result_batch in get_batches_from_generator(result, batch_size): document_batch = [self._convert_es_hit_to_document(hit, return_embedding=False) for hit in result_batch] embeddings = retriever.embed_documents(document_batch) # type: ignore assert len(document_batch) == len(embeddings) if embeddings[0].shape[0] != self.embedding_dim: raise RuntimeError(f"Embedding dim. of model ({embeddings[0].shape[0]})" f" doesn't match embedding dim. in DocumentStore ({self.embedding_dim})." "Specify the arg `embedding_dim` when initializing ElasticsearchDocumentStore()") doc_updates = [] for doc, emb in zip(document_batch, embeddings): update = {"_op_type": "update", "_index": index, "_id": doc.id, "doc": {self.embedding_field: emb.tolist()}, } doc_updates.append(update) bulk(self.client, doc_updates, request_timeout=300, refresh=self.refresh_type, headers=headers) progress_bar.update(batch_size)
[ "def", "update_embeddings", "(", "self", ",", "retriever", ",", "index", ":", "Optional", "[", "str", "]", "=", "None", ",", "filters", ":", "Optional", "[", "Dict", "[", "str", ",", "List", "[", "str", "]", "]", "]", "=", "None", ",", "update_existi...
https://github.com/deepset-ai/haystack/blob/79fdda8a7cf393d774803608a4874f2a6e63cf6f/haystack/document_stores/elasticsearch.py#L1009-L1082
lmb-freiburg/netdef_models
7d3311579cf712b31d05ec29f3dc63df067aa07b
FlowNet3/CSSR-ft-sd/net.py
python
get_env
()
return env
[]
def get_env(): env = FlowNet2f_Environment(net) return env
[ "def", "get_env", "(", ")", ":", "env", "=", "FlowNet2f_Environment", "(", "net", ")", "return", "env" ]
https://github.com/lmb-freiburg/netdef_models/blob/7d3311579cf712b31d05ec29f3dc63df067aa07b/FlowNet3/CSSR-ft-sd/net.py#L144-L146
aianaconda/TensorFlow_Engineering_Implementation
cb787e359da9ac5a08d00cd2458fecb4cb5a3a31
tf2code/Chapter4/code4-10/code4-10-TF2 - 副本.py
python
load_sample
(sample_dir,shuffleflag = True)
递归读取文件。只支持一级。返回文件名、数值标签、数值对应的标签名
递归读取文件。只支持一级。返回文件名、数值标签、数值对应的标签名
[ "递归读取文件。只支持一级。返回文件名、数值标签、数值对应的标签名" ]
def load_sample(sample_dir,shuffleflag = True): '''递归读取文件。只支持一级。返回文件名、数值标签、数值对应的标签名''' print ('loading sample dataset..') lfilenames = [] labelsnames = [] for (dirpath, dirnames, filenames) in os.walk(sample_dir):#递归遍历文件夹 for filename in filenames: #遍历所有文件名 #print(dirnames) filename_path = os.sep.join([dirpath, filename]) lfilenames.append(filename_path) #添加文件名 labelsnames.append( dirpath.split('\\')[-1] )#添加文件名对应的标签 lab= list(sorted(set(labelsnames))) #生成标签名称列表 labdict=dict( zip( lab ,list(range(len(lab))) )) #生成字典 labels = [labdict[i] for i in labelsnames] if shuffleflag == True: return shuffle(np.asarray( lfilenames),np.asarray( labels)),np.asarray(lab) else: return (np.asarray( lfilenames),np.asarray( labels)),np.asarray(lab)
[ "def", "load_sample", "(", "sample_dir", ",", "shuffleflag", "=", "True", ")", ":", "print", "(", "'loading sample dataset..'", ")", "lfilenames", "=", "[", "]", "labelsnames", "=", "[", "]", "for", "(", "dirpath", ",", "dirnames", ",", "filenames", ")", ...
https://github.com/aianaconda/TensorFlow_Engineering_Implementation/blob/cb787e359da9ac5a08d00cd2458fecb4cb5a3a31/tf2code/Chapter4/code4-10/code4-10-TF2 - 副本.py#L14-L33
ninuxorg/nodeshot
2466f0a55f522b2696026f196436ce7ba3f1e5c6
nodeshot/core/websockets/registrars/nodes.py
python
reconnect
()
reconnect signals
reconnect signals
[ "reconnect", "signals" ]
def reconnect(): """ reconnect signals """ post_save.connect(node_created_handler, sender=Node) node_status_changed.connect(node_status_changed_handler) pre_delete.connect(node_deleted_handler, sender=Node)
[ "def", "reconnect", "(", ")", ":", "post_save", ".", "connect", "(", "node_created_handler", ",", "sender", "=", "Node", ")", "node_status_changed", ".", "connect", "(", "node_status_changed_handler", ")", "pre_delete", ".", "connect", "(", "node_deleted_handler", ...
https://github.com/ninuxorg/nodeshot/blob/2466f0a55f522b2696026f196436ce7ba3f1e5c6/nodeshot/core/websockets/registrars/nodes.py#L49-L53
joaoventura/pylibui
2e74db787bfea533f3ae465670963daedcaec344
pylibui/libui/tab.py
python
uiTabDelete
(tab, index)
Deletes a control from the tab. :param tab: uiTab :param index: int :return: None
Deletes a control from the tab.
[ "Deletes", "a", "control", "from", "the", "tab", "." ]
def uiTabDelete(tab, index): """ Deletes a control from the tab. :param tab: uiTab :param index: int :return: None """ clibui.uiTabDelete(tab, index)
[ "def", "uiTabDelete", "(", "tab", ",", "index", ")", ":", "clibui", ".", "uiTabDelete", "(", "tab", ",", "index", ")" ]
https://github.com/joaoventura/pylibui/blob/2e74db787bfea533f3ae465670963daedcaec344/pylibui/libui/tab.py#L57-L66
jbuehl/solaredge
e1c199160488c30dc8e4ba3a839afece3c0d7e25
se/data.py
python
parseOffsetLength
(data)
return {"offset": offset, "length": length, "data": data[8:]}
[]
def parseOffsetLength(data): (offset, length) = struct.unpack("<LL", data[0:8]) logger.data("offset: %08x", offset) logger.data("length: %08x", length) return {"offset": offset, "length": length, "data": data[8:]}
[ "def", "parseOffsetLength", "(", "data", ")", ":", "(", "offset", ",", "length", ")", "=", "struct", ".", "unpack", "(", "\"<LL\"", ",", "data", "[", "0", ":", "8", "]", ")", "logger", ".", "data", "(", "\"offset: %08x\"", ",", "offset", ")", "logg...
https://github.com/jbuehl/solaredge/blob/e1c199160488c30dc8e4ba3a839afece3c0d7e25/se/data.py#L80-L84
MoyuScript/bilibili-api
a40d743089b70a0d0c73207690eb33a38cf28804
bilibili_api/dynamic.py
python
Dynamic.__init__
(self, dynamic_id: int, credential: Credential = None)
Args: dynamic_id (int): 动态 ID credential (Credential, optional): [description]. Defaults to None.
Args: dynamic_id (int): 动态 ID credential (Credential, optional): [description]. Defaults to None.
[ "Args", ":", "dynamic_id", "(", "int", ")", ":", "动态", "ID", "credential", "(", "Credential", "optional", ")", ":", "[", "description", "]", ".", "Defaults", "to", "None", "." ]
def __init__(self, dynamic_id: int, credential: Credential = None): """ Args: dynamic_id (int): 动态 ID credential (Credential, optional): [description]. Defaults to None. """ self.dynamic_id = dynamic_id self.credential = credential if credential is not None else Credential()
[ "def", "__init__", "(", "self", ",", "dynamic_id", ":", "int", ",", "credential", ":", "Credential", "=", "None", ")", ":", "self", ".", "dynamic_id", "=", "dynamic_id", "self", ".", "credential", "=", "credential", "if", "credential", "is", "not", "None",...
https://github.com/MoyuScript/bilibili-api/blob/a40d743089b70a0d0c73207690eb33a38cf28804/bilibili_api/dynamic.py#L291-L298
mongomock/mongomock
9772f5d7e02ae96b08506abb4004a45a5f388bdf
mongomock/filtering.py
python
iter_key_candidates
(key, doc)
return iter_key_candidates(sub_key, sub_doc)
Get possible subdocuments or lists that are referred to by the key in question Returns the appropriate nested value if the key includes dot notation.
Get possible subdocuments or lists that are referred to by the key in question
[ "Get", "possible", "subdocuments", "or", "lists", "that", "are", "referred", "to", "by", "the", "key", "in", "question" ]
def iter_key_candidates(key, doc): """Get possible subdocuments or lists that are referred to by the key in question Returns the appropriate nested value if the key includes dot notation. """ if doc is None: return () if not key: return [doc] if isinstance(doc, list): return _iter_key_candidates_sublist(key, doc) if not isinstance(doc, dict): return () key_parts = key.split('.') if len(key_parts) == 1: return [doc.get(key, NOTHING)] sub_key = '.'.join(key_parts[1:]) sub_doc = doc.get(key_parts[0], {}) return iter_key_candidates(sub_key, sub_doc)
[ "def", "iter_key_candidates", "(", "key", ",", "doc", ")", ":", "if", "doc", "is", "None", ":", "return", "(", ")", "if", "not", "key", ":", "return", "[", "doc", "]", "if", "isinstance", "(", "doc", ",", "list", ")", ":", "return", "_iter_key_candid...
https://github.com/mongomock/mongomock/blob/9772f5d7e02ae96b08506abb4004a45a5f388bdf/mongomock/filtering.py#L203-L226
disqus/gutter
d686fa3cd0551cacfc5630c8e7b5fa75e6dcfdf5
gutter/client/arguments/variables.py
python
Base.to_python
(value)
return value
[]
def to_python(value): return value
[ "def", "to_python", "(", "value", ")", ":", "return", "value" ]
https://github.com/disqus/gutter/blob/d686fa3cd0551cacfc5630c8e7b5fa75e6dcfdf5/gutter/client/arguments/variables.py#L24-L25
ralphm/wokkel
76edbf80f0d314e314e2d4d1510c6e5438a538f7
wokkel/iwokkel.py
python
IPubSubService.create
(requestor, service, nodeIdentifier)
Called when a node creation request has been received. @param requestor: The entity the request originated from. @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>} @param service: The entity the request was addressed to. @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} @param nodeIdentifier: The suggestion for the identifier of the node to be created. If the request did not include a suggestion for the node identifier, the value is C{None}. @type nodeIdentifier: C{unicode} or C{NoneType} @return: A deferred that fires with a C{unicode} that represents the identifier of the new node. @rtype: L{Deferred<twisted.internet.defer.Deferred>}
Called when a node creation request has been received.
[ "Called", "when", "a", "node", "creation", "request", "has", "been", "received", "." ]
def create(requestor, service, nodeIdentifier): """ Called when a node creation request has been received. @param requestor: The entity the request originated from. @type requestor: L{JID<twisted.words.protocols.jabber.jid.JID>} @param service: The entity the request was addressed to. @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} @param nodeIdentifier: The suggestion for the identifier of the node to be created. If the request did not include a suggestion for the node identifier, the value is C{None}. @type nodeIdentifier: C{unicode} or C{NoneType} @return: A deferred that fires with a C{unicode} that represents the identifier of the new node. @rtype: L{Deferred<twisted.internet.defer.Deferred>} """
[ "def", "create", "(", "requestor", ",", "service", ",", "nodeIdentifier", ")", ":" ]
https://github.com/ralphm/wokkel/blob/76edbf80f0d314e314e2d4d1510c6e5438a538f7/wokkel/iwokkel.py#L300-L315
PacktPublishing/Artificial-Intelligence-with-Python
03e0f39e3c0949ee219ec91e0145fdabe8ed7810
Chapter 09/code/easyAI/AI/TT.py
python
TT.lookup
(self, game)
return self.d.get(game.ttentry(), None)
Requests the entry in the table. Returns None if the entry has not been previously stored in the table.
Requests the entry in the table. Returns None if the entry has not been previously stored in the table.
[ "Requests", "the", "entry", "in", "the", "table", ".", "Returns", "None", "if", "the", "entry", "has", "not", "been", "previously", "stored", "in", "the", "table", "." ]
def lookup(self, game): """ Requests the entry in the table. Returns None if the entry has not been previously stored in the table. """ return self.d.get(game.ttentry(), None)
[ "def", "lookup", "(", "self", ",", "game", ")", ":", "return", "self", ".", "d", ".", "get", "(", "game", ".", "ttentry", "(", ")", ",", "None", ")" ]
https://github.com/PacktPublishing/Artificial-Intelligence-with-Python/blob/03e0f39e3c0949ee219ec91e0145fdabe8ed7810/Chapter 09/code/easyAI/AI/TT.py#L35-L38
joxeankoret/diaphora
dcb5a25ac9fe23a285b657e5389cf770de7ac928
diaphora_ida.py
python
CIDABinDiff.import_selected
(self, items, selected, only_auto)
[]
def import_selected(self, items, selected, only_auto): # Import all the type libraries from the diff database self.import_til() # Import all the struct and enum definitions self.import_definitions() new_items = [] for index in selected: item = items[index] name1 = item[2] if not only_auto or name1.startswith("sub_"): new_items.append(item) self.import_items(new_items)
[ "def", "import_selected", "(", "self", ",", "items", ",", "selected", ",", "only_auto", ")", ":", "# Import all the type libraries from the diff database", "self", ".", "import_til", "(", ")", "# Import all the struct and enum definitions", "self", ".", "import_definitions"...
https://github.com/joxeankoret/diaphora/blob/dcb5a25ac9fe23a285b657e5389cf770de7ac928/diaphora_ida.py#L1454-L1466
kubernetes-client/python
47b9da9de2d02b2b7a34fbe05afb44afd130d73a
kubernetes/client/models/v1_api_service_spec.py
python
V1APIServiceSpec.group_priority_minimum
(self, group_priority_minimum)
Sets the group_priority_minimum of this V1APIServiceSpec. GroupPriorityMininum is the priority this group should have at least. Higher priority means that the group is preferred by clients over lower priority ones. Note that other versions of this group might specify even higher GroupPriorityMininum values such that the whole group gets a higher priority. The primary sort is based on GroupPriorityMinimum, ordered highest number to lowest (20 before 10). The secondary sort is based on the alphabetical comparison of the name of the object. (v1.bar before v1.foo) We'd recommend something like: *.k8s.io (except extensions) at 18000 and PaaSes (OpenShift, Deis) are recommended to be in the 2000s # noqa: E501 :param group_priority_minimum: The group_priority_minimum of this V1APIServiceSpec. # noqa: E501 :type: int
Sets the group_priority_minimum of this V1APIServiceSpec.
[ "Sets", "the", "group_priority_minimum", "of", "this", "V1APIServiceSpec", "." ]
def group_priority_minimum(self, group_priority_minimum): """Sets the group_priority_minimum of this V1APIServiceSpec. GroupPriorityMininum is the priority this group should have at least. Higher priority means that the group is preferred by clients over lower priority ones. Note that other versions of this group might specify even higher GroupPriorityMininum values such that the whole group gets a higher priority. The primary sort is based on GroupPriorityMinimum, ordered highest number to lowest (20 before 10). The secondary sort is based on the alphabetical comparison of the name of the object. (v1.bar before v1.foo) We'd recommend something like: *.k8s.io (except extensions) at 18000 and PaaSes (OpenShift, Deis) are recommended to be in the 2000s # noqa: E501 :param group_priority_minimum: The group_priority_minimum of this V1APIServiceSpec. # noqa: E501 :type: int """ if self.local_vars_configuration.client_side_validation and group_priority_minimum is None: # noqa: E501 raise ValueError("Invalid value for `group_priority_minimum`, must not be `None`") # noqa: E501 self._group_priority_minimum = group_priority_minimum
[ "def", "group_priority_minimum", "(", "self", ",", "group_priority_minimum", ")", ":", "if", "self", ".", "local_vars_configuration", ".", "client_side_validation", "and", "group_priority_minimum", "is", "None", ":", "# noqa: E501", "raise", "ValueError", "(", "\"Invali...
https://github.com/kubernetes-client/python/blob/47b9da9de2d02b2b7a34fbe05afb44afd130d73a/kubernetes/client/models/v1_api_service_spec.py#L144-L155
s-leger/archipack
5a6243bf1edf08a6b429661ce291dacb551e5f8a
pygeos/algorithms.py
python
Angle.normalizePositive
(angle: float)
return angle
* Computes the normalized value of an angle, which is the * equivalent angle in the range ( -Pi, Pi ]. * @param angle the angle to normalize * @return an equivalent angle in the range (-Pi, Pi]
* Computes the normalized value of an angle, which is the * equivalent angle in the range ( -Pi, Pi ]. *
[ "*", "Computes", "the", "normalized", "value", "of", "an", "angle", "which", "is", "the", "*", "equivalent", "angle", "in", "the", "range", "(", "-", "Pi", "Pi", "]", ".", "*" ]
def normalizePositive(angle: float) -> float: """ * Computes the normalized value of an angle, which is the * equivalent angle in the range ( -Pi, Pi ]. * @param angle the angle to normalize * @return an equivalent angle in the range (-Pi, Pi] """ if angle < 0.0: while angle < 0.0: angle += Angle.PI_TIMES_2 if angle >= Angle.PI_TIMES_2: angle = 0.0 else: while angle >= Angle.PI_TIMES_2: angle -= Angle.PI_TIMES_2 if angle < 0.0: angle = 0.0 return angle
[ "def", "normalizePositive", "(", "angle", ":", "float", ")", "->", "float", ":", "if", "angle", "<", "0.0", ":", "while", "angle", "<", "0.0", ":", "angle", "+=", "Angle", ".", "PI_TIMES_2", "if", "angle", ">=", "Angle", ".", "PI_TIMES_2", ":", "angle"...
https://github.com/s-leger/archipack/blob/5a6243bf1edf08a6b429661ce291dacb551e5f8a/pygeos/algorithms.py#L605-L625
TarrySingh/Artificial-Intelligence-Deep-Learning-Machine-Learning-Tutorials
5bb97d7e3ffd913abddb4cfa7d78a1b4c868890e
deep-learning/udacity-deeplearning/face_generation/helper.py
python
get_image
(image_path, width, height, mode)
return np.array(image.convert(mode))
Read image from image_path :param image_path: Path of image :param width: Width of image :param height: Height of image :param mode: Mode of image :return: Image data
Read image from image_path :param image_path: Path of image :param width: Width of image :param height: Height of image :param mode: Mode of image :return: Image data
[ "Read", "image", "from", "image_path", ":", "param", "image_path", ":", "Path", "of", "image", ":", "param", "width", ":", "Width", "of", "image", ":", "param", "height", ":", "Height", "of", "image", ":", "param", "mode", ":", "Mode", "of", "image", "...
def get_image(image_path, width, height, mode): """ Read image from image_path :param image_path: Path of image :param width: Width of image :param height: Height of image :param mode: Mode of image :return: Image data """ image = Image.open(image_path) if image.size != (width, height): # HACK - Check if image is from the CELEBA dataset # Remove most pixels that aren't part of a face face_width = face_height = 108 j = (image.size[0] - face_width) // 2 i = (image.size[1] - face_height) // 2 image = image.crop([j, i, j + face_width, i + face_height]) image = image.resize([width, height], Image.BILINEAR) return np.array(image.convert(mode))
[ "def", "get_image", "(", "image_path", ",", "width", ",", "height", ",", "mode", ")", ":", "image", "=", "Image", ".", "open", "(", "image_path", ")", "if", "image", ".", "size", "!=", "(", "width", ",", "height", ")", ":", "# HACK - Check if image is fr...
https://github.com/TarrySingh/Artificial-Intelligence-Deep-Learning-Machine-Learning-Tutorials/blob/5bb97d7e3ffd913abddb4cfa7d78a1b4c868890e/deep-learning/udacity-deeplearning/face_generation/helper.py#L64-L83
Refefer/Dampr
340580afeff23d1f43e23019c7e3a879468aad8d
dampr/base.py
python
BlockMapper.finish
(self)
return ()
Mapping is finished. In the case of aggregations, this should yield out all remaining key-values to consume.
Mapping is finished. In the case of aggregations, this should yield out all remaining key-values to consume.
[ "Mapping", "is", "finished", ".", "In", "the", "case", "of", "aggregations", "this", "should", "yield", "out", "all", "remaining", "key", "-", "values", "to", "consume", "." ]
def finish(self): """ Mapping is finished. In the case of aggregations, this should yield out all remaining key-values to consume. """ return ()
[ "def", "finish", "(", "self", ")", ":", "return", "(", ")" ]
https://github.com/Refefer/Dampr/blob/340580afeff23d1f43e23019c7e3a879468aad8d/dampr/base.py#L83-L88
stopstalk/stopstalk-deployment
10c3ab44c4ece33ae515f6888c15033db2004bb1
aws_lambda/spoj_aws_lambda_function/lambda_code/requests/packages/urllib3/filepost.py
python
iter_fields
(fields)
return ((k, v) for k, v in fields)
.. deprecated:: 1.6 Iterate over fields. The addition of :class:`~urllib3.fields.RequestField` makes this function obsolete. Instead, use :func:`iter_field_objects`, which returns :class:`~urllib3.fields.RequestField` objects. Supports list of (k, v) tuples and dicts.
.. deprecated:: 1.6
[ "..", "deprecated", "::", "1", ".", "6" ]
def iter_fields(fields): """ .. deprecated:: 1.6 Iterate over fields. The addition of :class:`~urllib3.fields.RequestField` makes this function obsolete. Instead, use :func:`iter_field_objects`, which returns :class:`~urllib3.fields.RequestField` objects. Supports list of (k, v) tuples and dicts. """ if isinstance(fields, dict): return ((k, v) for k, v in six.iteritems(fields)) return ((k, v) for k, v in fields)
[ "def", "iter_fields", "(", "fields", ")", ":", "if", "isinstance", "(", "fields", ",", "dict", ")", ":", "return", "(", "(", "k", ",", "v", ")", "for", "k", ",", "v", "in", "six", ".", "iteritems", "(", "fields", ")", ")", "return", "(", "(", "...
https://github.com/stopstalk/stopstalk-deployment/blob/10c3ab44c4ece33ae515f6888c15033db2004bb1/aws_lambda/spoj_aws_lambda_function/lambda_code/requests/packages/urllib3/filepost.py#L41-L56
smart-mobile-software/gitstack
d9fee8f414f202143eb6e620529e8e5539a2af56
python/Lib/wsgiref/handlers.py
python
BaseHandler.send_preamble
(self)
Transmit version/status/date/server, via self._write()
Transmit version/status/date/server, via self._write()
[ "Transmit", "version", "/", "status", "/", "date", "/", "server", "via", "self", ".", "_write", "()" ]
def send_preamble(self): """Transmit version/status/date/server, via self._write()""" if self.origin_server: if self.client_is_modern(): self._write('HTTP/%s %s\r\n' % (self.http_version,self.status)) if 'Date' not in self.headers: self._write( 'Date: %s\r\n' % format_date_time(time.time()) ) if self.server_software and 'Server' not in self.headers: self._write('Server: %s\r\n' % self.server_software) else: self._write('Status: %s\r\n' % self.status)
[ "def", "send_preamble", "(", "self", ")", ":", "if", "self", ".", "origin_server", ":", "if", "self", ".", "client_is_modern", "(", ")", ":", "self", ".", "_write", "(", "'HTTP/%s %s\\r\\n'", "%", "(", "self", ".", "http_version", ",", "self", ".", "stat...
https://github.com/smart-mobile-software/gitstack/blob/d9fee8f414f202143eb6e620529e8e5539a2af56/python/Lib/wsgiref/handlers.py#L185-L197
ProgVal/Limnoria
181e34baf90a8cabc281e8349da6e36e1e558608
plugins/User/plugin.py
python
User.identify
(self, irc, msg, args, user, password)
<name> <password> Identifies the user as <name>. This command (and all other commands that include a password) must be sent to the bot privately, not in a channel.
<name> <password>
[ "<name", ">", "<password", ">" ]
def identify(self, irc, msg, args, user, password): """<name> <password> Identifies the user as <name>. This command (and all other commands that include a password) must be sent to the bot privately, not in a channel. """ if user.checkPassword(password): try: user.addAuth(msg.prefix) ircdb.users.setUser(user, flush=False) irc.replySuccess() except ValueError: irc.error(_('Your secure flag is true and your hostmask ' 'doesn\'t match any of your known hostmasks.')) else: self.log.warning('Failed identification attempt by %s (password ' 'did not match for %s).', msg.prefix, user.name) irc.error(conf.supybot.replies.incorrectAuthentication())
[ "def", "identify", "(", "self", ",", "irc", ",", "msg", ",", "args", ",", "user", ",", "password", ")", ":", "if", "user", ".", "checkPassword", "(", "password", ")", ":", "try", ":", "user", ".", "addAuth", "(", "msg", ".", "prefix", ")", "ircdb",...
https://github.com/ProgVal/Limnoria/blob/181e34baf90a8cabc281e8349da6e36e1e558608/plugins/User/plugin.py#L458-L476
python/mypy
17850b3bd77ae9efb5d21f656c4e4e05ac48d894
mypy/dmypy/client.py
python
do_kill
(args: argparse.Namespace)
Kill daemon process with SIGKILL.
Kill daemon process with SIGKILL.
[ "Kill", "daemon", "process", "with", "SIGKILL", "." ]
def do_kill(args: argparse.Namespace) -> None: """Kill daemon process with SIGKILL.""" pid, _ = get_status(args.status_file) try: kill(pid) except OSError as err: fail(str(err)) else: print("Daemon killed")
[ "def", "do_kill", "(", "args", ":", "argparse", ".", "Namespace", ")", "->", "None", ":", "pid", ",", "_", "=", "get_status", "(", "args", ".", "status_file", ")", "try", ":", "kill", "(", "pid", ")", "except", "OSError", "as", "err", ":", "fail", ...
https://github.com/python/mypy/blob/17850b3bd77ae9efb5d21f656c4e4e05ac48d894/mypy/dmypy/client.py#L319-L327
0vercl0k/stuffz
2ff82f4739d7e215c6140d4987efa8310db39d55
ollydbg2-udd-files/udd.py
python
breakpoint_type_to_access
(ty)
return ''.join(a if (ty & mask) == mask else '-' for mask, a in flags)
0x00200000|0x00400000|0x00800000 -> rwx
0x00200000|0x00400000|0x00800000 -> rwx
[ "0x00200000|0x00400000|0x00800000", "-", ">", "rwx" ]
def breakpoint_type_to_access(ty): '''0x00200000|0x00400000|0x00800000 -> rwx''' flags = [ (0x00200000, 'r'), (0x00400000, 'w'), (0x00800000, 'x') ] return ''.join(a if (ty & mask) == mask else '-' for mask, a in flags)
[ "def", "breakpoint_type_to_access", "(", "ty", ")", ":", "flags", "=", "[", "(", "0x00200000", ",", "'r'", ")", ",", "(", "0x00400000", ",", "'w'", ")", ",", "(", "0x00800000", ",", "'x'", ")", "]", "return", "''", ".", "join", "(", "a", "if", "(",...
https://github.com/0vercl0k/stuffz/blob/2ff82f4739d7e215c6140d4987efa8310db39d55/ollydbg2-udd-files/udd.py#L237-L244
0xdea/tactical-exploitation
231146ac5b4caa44ed73fade0ec29767d28b20b5
seitan.py
python
get_targets
(args)
return [t.rstrip() for t in args.f]
Get targets from command line or file
Get targets from command line or file
[ "Get", "targets", "from", "command", "line", "or", "file" ]
def get_targets(args): """ Get targets from command line or file """ if args.t: return [args.t] return [t.rstrip() for t in args.f]
[ "def", "get_targets", "(", "args", ")", ":", "if", "args", ".", "t", ":", "return", "[", "args", ".", "t", "]", "return", "[", "t", ".", "rstrip", "(", ")", "for", "t", "in", "args", ".", "f", "]" ]
https://github.com/0xdea/tactical-exploitation/blob/231146ac5b4caa44ed73fade0ec29767d28b20b5/seitan.py#L257-L263
rowliny/DiffHelper
ab3a96f58f9579d0023aed9ebd785f4edf26f8af
Tool/SitePackages/nltk/sem/logic.py
python
LogicParser.handle
(self, tok, context)
This method is intended to be overridden for logics that use different operators or expressions
This method is intended to be overridden for logics that use different operators or expressions
[ "This", "method", "is", "intended", "to", "be", "overridden", "for", "logics", "that", "use", "different", "operators", "or", "expressions" ]
def handle(self, tok, context): """This method is intended to be overridden for logics that use different operators or expressions""" if self.isvariable(tok): return self.handle_variable(tok, context) elif tok in Tokens.NOT_LIST: return self.handle_negation(tok, context) elif tok in Tokens.LAMBDA_LIST: return self.handle_lambda(tok, context) elif tok in Tokens.QUANTS: return self.handle_quant(tok, context) elif tok == Tokens.OPEN: return self.handle_open(tok, context)
[ "def", "handle", "(", "self", ",", "tok", ",", "context", ")", ":", "if", "self", ".", "isvariable", "(", "tok", ")", ":", "return", "self", ".", "handle_variable", "(", "tok", ",", "context", ")", "elif", "tok", "in", "Tokens", ".", "NOT_LIST", ":",...
https://github.com/rowliny/DiffHelper/blob/ab3a96f58f9579d0023aed9ebd785f4edf26f8af/Tool/SitePackages/nltk/sem/logic.py#L296-L312
theotherp/nzbhydra
4b03d7f769384b97dfc60dade4806c0fc987514e
libs/werkzeug/contrib/cache.py
python
BaseCache.get_dict
(self, *keys)
return dict(zip(keys, self.get_many(*keys)))
Like :meth:`get_many` but return a dict:: d = cache.get_dict("foo", "bar") foo = d["foo"] bar = d["bar"] :param keys: The function accepts multiple keys as positional arguments.
Like :meth:`get_many` but return a dict::
[ "Like", ":", "meth", ":", "get_many", "but", "return", "a", "dict", "::" ]
def get_dict(self, *keys): """Like :meth:`get_many` but return a dict:: d = cache.get_dict("foo", "bar") foo = d["foo"] bar = d["bar"] :param keys: The function accepts multiple keys as positional arguments. """ return dict(zip(keys, self.get_many(*keys)))
[ "def", "get_dict", "(", "self", ",", "*", "keys", ")", ":", "return", "dict", "(", "zip", "(", "keys", ",", "self", ".", "get_many", "(", "*", "keys", ")", ")", ")" ]
https://github.com/theotherp/nzbhydra/blob/4b03d7f769384b97dfc60dade4806c0fc987514e/libs/werkzeug/contrib/cache.py#L132-L142
celery/kombu
853b13f1d018ebfe7ad2d064a3111cac9fcf5383
kombu/transport/qpid.py
python
Channel.queue_purge
(self, queue, **kwargs)
return self._purge(queue)
Remove all undelivered messages from queue. Purge all undelivered messages from a queue specified by name. If the queue does not exist an exception is raised. The queue message depth is first checked, and then the broker is asked to purge that number of messages. The integer number of messages requested to be purged is returned. The actual number of messages purged may be different than the requested number of messages to purge. Sometimes delivered messages are asked to be purged, but are not. This case fails silently, which is the correct behavior when a message that has been delivered to a different consumer, who has not ACKed the message, and still has an active session with the broker. Messages in that case are not safe for purging and will be retained by the broker. The client is unable to change this delivery behavior. Internally, this method relies on :meth:`_purge`. :param queue: The name of the queue which should have all messages removed. :type queue: str :return: The number of messages requested to be purged. :rtype: int :raises: :class:`qpid.messaging.exceptions.NotFound` if the queue being purged cannot be found.
Remove all undelivered messages from queue.
[ "Remove", "all", "undelivered", "messages", "from", "queue", "." ]
def queue_purge(self, queue, **kwargs): """Remove all undelivered messages from queue. Purge all undelivered messages from a queue specified by name. If the queue does not exist an exception is raised. The queue message depth is first checked, and then the broker is asked to purge that number of messages. The integer number of messages requested to be purged is returned. The actual number of messages purged may be different than the requested number of messages to purge. Sometimes delivered messages are asked to be purged, but are not. This case fails silently, which is the correct behavior when a message that has been delivered to a different consumer, who has not ACKed the message, and still has an active session with the broker. Messages in that case are not safe for purging and will be retained by the broker. The client is unable to change this delivery behavior. Internally, this method relies on :meth:`_purge`. :param queue: The name of the queue which should have all messages removed. :type queue: str :return: The number of messages requested to be purged. :rtype: int :raises: :class:`qpid.messaging.exceptions.NotFound` if the queue being purged cannot be found. """ return self._purge(queue)
[ "def", "queue_purge", "(", "self", ",", "queue", ",", "*", "*", "kwargs", ")", ":", "return", "self", ".", "_purge", "(", "queue", ")" ]
https://github.com/celery/kombu/blob/853b13f1d018ebfe7ad2d064a3111cac9fcf5383/kombu/transport/qpid.py#L795-L826
tdamdouni/Pythonista
3e082d53b6b9b501a3c8cf3251a8ad4c8be9c2ad
stash/shellista-Transistor1.py
python
Shell.do_ls
(self, line)
list directory contents
list directory contents
[ "list", "directory", "contents" ]
def do_ls(self, line): """list directory contents""" files = self.bash(line) if files is None: return elif (not files): files = ['.'] files_for_path = dict() for filef in files: full_file = os.path.normpath(os.path.abspath(filef)) file_name = os.path.basename(full_file) dir_name = os.path.normpath(os.path.dirname(full_file)) if (not os.path.exists(full_file)): print("! Error: Skipped, missing -", self.pprint(filef)) continue if (os.path.isdir(full_file)): # Need to add this as a key and all the files contained inside it _dirs = files_for_path.get(full_file, set()) for new_file in os.listdir(full_file): _dirs.add(os.path.normpath(full_file) + '/' + os.path.normpath(new_file)) files_for_path[full_file] = _dirs else: _dirs = files_for_path.get(dir_name, set()) _dirs.add(full_file) files_for_path[dir_name] = _dirs # Iterate over the paths, in alphabetical order: paths = sorted(files_for_path.keys()) cwd = os.path.normpath(os.getcwd()) in_cwd = False if (cwd in paths): # Move cwd to the front, mark that it's present paths.remove(cwd) paths = [cwd] + paths in_cwd = True for i,path in enumerate(paths): if (i > 0): print("\n" + self.pprint(path) + "/:") elif (not in_cwd): print(self.pprint(path) + "/:") for filef in sorted(list(files_for_path[path])): full_file = os.path.normpath(os.path.abspath(filef)) file_name = os.path.basename(full_file) if (os.path.isdir(full_file)): print(file_name + "/") else: try: print(file_name + (" (%s)" % (self.sizeof_fmt(os.stat(full_file).st_size)))) except OSError: print(file_name + " (OSError)")
[ "def", "do_ls", "(", "self", ",", "line", ")", ":", "files", "=", "self", ".", "bash", "(", "line", ")", "if", "files", "is", "None", ":", "return", "elif", "(", "not", "files", ")", ":", "files", "=", "[", "'.'", "]", "files_for_path", "=", "dic...
https://github.com/tdamdouni/Pythonista/blob/3e082d53b6b9b501a3c8cf3251a8ad4c8be9c2ad/stash/shellista-Transistor1.py#L833-L881
Nandaka/PixivUtil2
3495f52c8889a45af29a0356045f230248abc177
PixivHelper.py
python
convert_ugoira
(ugoira_file, exportname, ffmpeg, codec, param, extension, image=None)
modified based on https://github.com/tsudoko/ugoira-tools/blob/master/ugoira2webm/ugoira2webm.py
modified based on https://github.com/tsudoko/ugoira-tools/blob/master/ugoira2webm/ugoira2webm.py
[ "modified", "based", "on", "https", ":", "//", "github", ".", "com", "/", "tsudoko", "/", "ugoira", "-", "tools", "/", "blob", "/", "master", "/", "ugoira2webm", "/", "ugoira2webm", ".", "py" ]
def convert_ugoira(ugoira_file, exportname, ffmpeg, codec, param, extension, image=None): ''' modified based on https://github.com/tsudoko/ugoira-tools/blob/master/ugoira2webm/ugoira2webm.py ''' # if not os.path.exists(os.path.abspath(ffmpeg)): # raise PixivException(f"Cannot find ffmpeg executables => {ffmpeg}", errorCode=PixivException.MISSING_CONFIG) d = tempfile.mkdtemp(prefix="convert_ugoira") d = d.replace(os.sep, '/') # Issue #1035 if not os.path.exists(d): new_temp = os.path.abspath(f"ugoira_{int(datetime.now().timestamp())}") new_temp = new_temp.replace(os.sep, '/') os.makedirs(new_temp) print_and_log("warn", f"Cannot create temp folder at {d}, using current folder as the temp location => {new_temp}") d = new_temp # check again if still fail if not os.path.exists(d): raise PixivException(f"Cannot create temp folder => {d}", errorCode=PixivException.OTHER_ERROR) if exportname is None or len(exportname) == 0: name = '.'.join(ugoira_file.split('.')[:-1]) exportname = f"{os.path.basename(name)}.{extension}" tempname = d + "/temp." + extension cmd = f"{ffmpeg} -y -safe 0 -i \"{d}/i.ffconcat\" -c:v {codec} {param} \"{tempname}\"" if codec is None: cmd = f"{ffmpeg} -y -safe 0 -i \"{d}/i.ffconcat\" {param} \"{tempname}\"" try: frames = {} ffconcat = "ffconcat version 1.0\n" with zipfile.ZipFile(ugoira_file) as f: f.extractall(d) with open(d + "/animation.json") as f: frames = json.load(f)['frames'] for i in frames: ffconcat += "file " + i['file'] + '\n' ffconcat += "duration " + str(float(i['delay']) / 1000) + '\n' # Fix ffmpeg concat demuxer as described in issue #381 # this will increase the frame count, but will fix the last frame timestamp issue. ffconcat += "file " + frames[-1]['file'] + '\n' with open(d + "/i.ffconcat", "w") as f: f.write(ffconcat) ffmpeg_args = shlex.split(cmd) get_logger().info(f"[convert_ugoira()] running with cmd: {cmd}") p = subprocess.Popen(ffmpeg_args, stderr=subprocess.PIPE) # progress report chatter = "" print_and_log('info', f"Start encoding {exportname}") while p.stderr: buff = p.stderr.readline().decode('utf-8').rstrip('\n') chatter += buff if buff.endswith("\r"): if _config.verboseOutput: print(chatter.strip()) elif chatter.find("frame=") > 0 \ or chatter.lower().find("stream") > 0: print(chatter.strip()) elif chatter.lower().find("error") > 0 \ or chatter.lower().find("could not") > 0 \ or chatter.lower().find("unknown") > 0 \ or chatter.lower().find("invalid") > 0 \ or chatter.lower().find("trailing options") > 0 \ or chatter.lower().find("cannot") > 0 \ or chatter.lower().find("can't") > 0: print_and_log("error", chatter.strip()) chatter = "" if len(buff) == 0: break ret = p.wait() if(p.returncode != 0): print_and_log("error", f"Failed when converting image using {cmd} ==> ffmpeg return exit code={p.returncode}, expected to return 0.") else: print_and_log("info", f"- Done with status = {ret}") shutil.move(tempname, exportname) # set last-modified and last-accessed timestamp if image is not None and _config.setLastModified and exportname is not None and os.path.isfile(exportname): ts = time.mktime(image.worksDateDateTime.timetuple()) os.utime(exportname, (ts, ts)) except FileNotFoundError: print_and_log("error", f"Failed when converting, ffmpeg command used: {cmd}") raise finally: if os.path.exists(d): shutil.rmtree(d) print()
[ "def", "convert_ugoira", "(", "ugoira_file", ",", "exportname", ",", "ffmpeg", ",", "codec", ",", "param", ",", "extension", ",", "image", "=", "None", ")", ":", "# if not os.path.exists(os.path.abspath(ffmpeg)):", "# raise PixivException(f\"Cannot find ffmpeg executabl...
https://github.com/Nandaka/PixivUtil2/blob/3495f52c8889a45af29a0356045f230248abc177/PixivHelper.py#L988-L1084
huawei-noah/Pretrained-Language-Model
d4694a134bdfacbaef8ff1d99735106bd3b3372b
PMLM/tokenization.py
python
BasicTokenizer._tokenize_chinese_chars
(self, text)
return "".join(output)
Adds whitespace around any CJK character.
Adds whitespace around any CJK character.
[ "Adds", "whitespace", "around", "any", "CJK", "character", "." ]
def _tokenize_chinese_chars(self, text): """Adds whitespace around any CJK character.""" output = [] for char in text: cp = ord(char) if self._is_chinese_char(cp): output.append(" ") output.append(char) output.append(" ") else: output.append(char) return "".join(output)
[ "def", "_tokenize_chinese_chars", "(", "self", ",", "text", ")", ":", "output", "=", "[", "]", "for", "char", "in", "text", ":", "cp", "=", "ord", "(", "char", ")", "if", "self", ".", "_is_chinese_char", "(", "cp", ")", ":", "output", ".", "append", ...
https://github.com/huawei-noah/Pretrained-Language-Model/blob/d4694a134bdfacbaef8ff1d99735106bd3b3372b/PMLM/tokenization.py#L252-L263
googleads/googleads-python-lib
b3b42a6deedbe6eaa1c9b30183a9eae3f9e9a7ee
examples/adwords/v201809/campaign_management/add_draft.py
python
main
(client, base_campaign_id)
[]
def main(client, base_campaign_id): draft_service = client.GetService('DraftService', version='v201809') draft = { 'baseCampaignId': base_campaign_id, 'draftName': 'Test Draft #%s' % uuid.uuid4() } draft_operation = {'operator': 'ADD', 'operand': draft} draft = draft_service.mutate([draft_operation])['value'][0] draft_campaign_id = draft['draftCampaignId'] # Once the draft is created, you can modify the draft campaign as if it were a # real campaign. For example, you may add criteria, adjust bids, or even # include additional ads. Adding a criteria is shown here. campaign_criterion_service = client.GetService('CampaignCriterionService', version='v201809') criterion = { 'xsi_type': 'Language', 'id': 1003 # Spanish } criterion_operation = { # Make sure to use the draftCampaignId when modifying the virtual draft # campaign. 'operator': 'ADD', 'operand': { 'campaignId': draft_campaign_id, 'criterion': criterion } } criterion = campaign_criterion_service.mutate([criterion_operation])[ 'value'][0] print('Draft updated to include criteria in campaign with ID %d' % draft_campaign_id)
[ "def", "main", "(", "client", ",", "base_campaign_id", ")", ":", "draft_service", "=", "client", ".", "GetService", "(", "'DraftService'", ",", "version", "=", "'v201809'", ")", "draft", "=", "{", "'baseCampaignId'", ":", "base_campaign_id", ",", "'draftName'", ...
https://github.com/googleads/googleads-python-lib/blob/b3b42a6deedbe6eaa1c9b30183a9eae3f9e9a7ee/examples/adwords/v201809/campaign_management/add_draft.py#L37-L74
apple/ccs-calendarserver
13c706b985fb728b9aab42dc0fef85aae21921c3
twistedcaldav/database.py
python
AbstractADBAPIDatabase.__repr__
(self)
return "<%s %r>" % (self.__class__.__name__, self.pool)
[]
def __repr__(self): return "<%s %r>" % (self.__class__.__name__, self.pool)
[ "def", "__repr__", "(", "self", ")", ":", "return", "\"<%s %r>\"", "%", "(", "self", ".", "__class__", ".", "__name__", ",", "self", ".", "pool", ")" ]
https://github.com/apple/ccs-calendarserver/blob/13c706b985fb728b9aab42dc0fef85aae21921c3/twistedcaldav/database.py#L98-L99
Theano/Theano
8fd9203edfeecebced9344b0c70193be292a9ade
theano/_version.py
python
run_command
(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None)
return stdout, p.returncode
Call the given command(s).
Call the given command(s).
[ "Call", "the", "given", "command", "(", "s", ")", "." ]
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=None): """Call the given command(s).""" assert isinstance(commands, list) p = None for c in commands: try: dispcmd = str([c] + args) # remember shell=False, so use git.cmd on windows, not just git p = subprocess.Popen([c] + args, cwd=cwd, env=env, stdout=subprocess.PIPE, stderr=(subprocess.PIPE if hide_stderr else None)) break except EnvironmentError: e = sys.exc_info()[1] if e.errno == errno.ENOENT: continue if verbose: print("unable to run %s" % dispcmd) print(e) return None, None else: if verbose: print("unable to find command, tried %s" % (commands,)) return None, None stdout = p.communicate()[0].strip() if sys.version_info[0] >= 3: stdout = stdout.decode() if p.returncode != 0: if verbose: print("unable to run %s (error)" % dispcmd) print("stdout was %s" % stdout) return None, p.returncode return stdout, p.returncode
[ "def", "run_command", "(", "commands", ",", "args", ",", "cwd", "=", "None", ",", "verbose", "=", "False", ",", "hide_stderr", "=", "False", ",", "env", "=", "None", ")", ":", "assert", "isinstance", "(", "commands", ",", "list", ")", "p", "=", "None...
https://github.com/Theano/Theano/blob/8fd9203edfeecebced9344b0c70193be292a9ade/theano/_version.py#L70-L104
fonttools/fonttools
892322aaff6a89bea5927379ec06bc0da3dfb7df
Lib/fontTools/cffLib/specializer.py
python
_GeneralizerDecombinerCommandsMap.vhcurveto
(args)
[]
def vhcurveto(args): if len(args) < 4 or len(args) % 8 not in {0,1,4,5}: raise ValueError(args) last_args = None if len(args) % 2 == 1: lastStraight = len(args) % 8 == 5 args, last_args = args[:-5], args[-5:] it = _everyN(args, 4) try: while True: args = next(it) yield ('rrcurveto', [0, args[0], args[1], args[2], args[3], 0]) args = next(it) yield ('rrcurveto', [args[0], 0, args[1], args[2], 0, args[3]]) except StopIteration: pass if last_args: args = last_args if lastStraight: yield ('rrcurveto', [0, args[0], args[1], args[2], args[3], args[4]]) else: yield ('rrcurveto', [args[0], 0, args[1], args[2], args[4], args[3]])
[ "def", "vhcurveto", "(", "args", ")", ":", "if", "len", "(", "args", ")", "<", "4", "or", "len", "(", "args", ")", "%", "8", "not", "in", "{", "0", ",", "1", ",", "4", ",", "5", "}", ":", "raise", "ValueError", "(", "args", ")", "last_args", ...
https://github.com/fonttools/fonttools/blob/892322aaff6a89bea5927379ec06bc0da3dfb7df/Lib/fontTools/cffLib/specializer.py#L238-L258
donnemartin/gitsome
d7c57abc7cb66e9c910a844f15d4536866da3310
xonsh/tools.py
python
deprecated
(deprecated_in=None, removed_in=None)
return decorated
Parametrized decorator that deprecates a function in a graceful manner. Updates the decorated function's docstring to mention the version that deprecation occurred in and the version it will be removed in if both of these values are passed. When removed_in is not a release equal to or less than the current release, call ``warnings.warn`` with details, while raising ``DeprecationWarning``. When removed_in is a release equal to or less than the current release, raise an ``AssertionError``. Parameters ---------- deprecated_in : str The version number that deprecated this function. removed_in : str The version number that this function will be removed in.
Parametrized decorator that deprecates a function in a graceful manner.
[ "Parametrized", "decorator", "that", "deprecates", "a", "function", "in", "a", "graceful", "manner", "." ]
def deprecated(deprecated_in=None, removed_in=None): """Parametrized decorator that deprecates a function in a graceful manner. Updates the decorated function's docstring to mention the version that deprecation occurred in and the version it will be removed in if both of these values are passed. When removed_in is not a release equal to or less than the current release, call ``warnings.warn`` with details, while raising ``DeprecationWarning``. When removed_in is a release equal to or less than the current release, raise an ``AssertionError``. Parameters ---------- deprecated_in : str The version number that deprecated this function. removed_in : str The version number that this function will be removed in. """ message_suffix = _deprecated_message_suffix(deprecated_in, removed_in) if not message_suffix: message_suffix = "" def decorated(func): warning_message = "{} has been deprecated".format(func.__name__) warning_message += message_suffix @functools.wraps(func) def wrapped(*args, **kwargs): _deprecated_error_on_expiration(func.__name__, removed_in) func(*args, **kwargs) warnings.warn(warning_message, DeprecationWarning) wrapped.__doc__ = ( "{}\n\n{}".format(wrapped.__doc__, warning_message) if wrapped.__doc__ else warning_message ) return wrapped return decorated
[ "def", "deprecated", "(", "deprecated_in", "=", "None", ",", "removed_in", "=", "None", ")", ":", "message_suffix", "=", "_deprecated_message_suffix", "(", "deprecated_in", ",", "removed_in", ")", "if", "not", "message_suffix", ":", "message_suffix", "=", "\"\"", ...
https://github.com/donnemartin/gitsome/blob/d7c57abc7cb66e9c910a844f15d4536866da3310/xonsh/tools.py#L2381-L2424
cea-sec/miasm
09376c524aedc7920a7eda304d6095e12f6958f4
miasm/analysis/dse.py
python
DSEEngine.add_handler
(self, addr, callback)
Add a @callback for address @addr before any state update. The state IS NOT updated after returning from the callback @addr: int @callback: func(dse instance)
Add a
[ "Add", "a" ]
def add_handler(self, addr, callback): """Add a @callback for address @addr before any state update. The state IS NOT updated after returning from the callback @addr: int @callback: func(dse instance)""" self.handler[addr] = callback
[ "def", "add_handler", "(", "self", ",", "addr", ",", "callback", ")", ":", "self", ".", "handler", "[", "addr", "]", "=", "callback" ]
https://github.com/cea-sec/miasm/blob/09376c524aedc7920a7eda304d6095e12f6958f4/miasm/analysis/dse.py#L243-L248
PyCQA/pylint
3fc855f9d0fa8e6410be5a23cf954ffd5471b4eb
pylint/pyreverse/inspector.py
python
IdGeneratorMixIn.generate_id
(self)
return self.id_count
generate a new identifier
generate a new identifier
[ "generate", "a", "new", "identifier" ]
def generate_id(self): """generate a new identifier""" self.id_count += 1 return self.id_count
[ "def", "generate_id", "(", "self", ")", ":", "self", ".", "id_count", "+=", "1", "return", "self", ".", "id_count" ]
https://github.com/PyCQA/pylint/blob/3fc855f9d0fa8e6410be5a23cf954ffd5471b4eb/pylint/pyreverse/inspector.py#L77-L80
JonnyHaystack/i3-resurrect
80e3fd6d048fe473c8cb8b2dfb75b1ace3846408
i3_resurrect/main.py
python
restore_workspace
(workspace, numeric, directory, profile, target)
Restore i3 workspace layout and programs.
Restore i3 workspace layout and programs.
[ "Restore", "i3", "workspace", "layout", "and", "programs", "." ]
def restore_workspace(workspace, numeric, directory, profile, target): """ Restore i3 workspace layout and programs. """ i3 = i3ipc.Connection() if workspace is None: workspace = i3.get_tree().find_focused().workspace().name directory = util.resolve_directory(directory, profile) if numeric and not workspace.isdigit(): util.eprint('Invalid workspace number.') sys.exit(1) # Get layout name from file. workspace_layout = layout.read(workspace, directory, profile) if 'name' in workspace_layout and profile is None: workspace_name = workspace_layout['name'] else: workspace_name = workspace # Switch to the workspace which we are loading. i3.command(f'workspace --no-auto-back-and-forth "{workspace_name}"') if target != 'programs_only': # Load workspace layout. layout.restore(workspace_name, workspace_layout) if target != 'layout_only': # Restore programs. saved_programs = programs.read(workspace, directory, profile) programs.restore(workspace_name, saved_programs)
[ "def", "restore_workspace", "(", "workspace", ",", "numeric", ",", "directory", ",", "profile", ",", "target", ")", ":", "i3", "=", "i3ipc", ".", "Connection", "(", ")", "if", "workspace", "is", "None", ":", "workspace", "=", "i3", ".", "get_tree", "(", ...
https://github.com/JonnyHaystack/i3-resurrect/blob/80e3fd6d048fe473c8cb8b2dfb75b1ace3846408/i3_resurrect/main.py#L91-L123
Lookyloo/lookyloo
45ec8efe64d4b549e2598bee0300bb8ffb33ea91
lookyloo/default/helpers.py
python
get_config
(config_type: str, entry: str, quiet: bool=False)
return sample_config[entry]
Get an entry from the given config_type file. Automatic fallback to the sample file
Get an entry from the given config_type file. Automatic fallback to the sample file
[ "Get", "an", "entry", "from", "the", "given", "config_type", "file", ".", "Automatic", "fallback", "to", "the", "sample", "file" ]
def get_config(config_type: str, entry: str, quiet: bool=False) -> Any: """Get an entry from the given config_type file. Automatic fallback to the sample file""" global configs if not configs: load_configs() if config_type in configs: if entry in configs[config_type]: return configs[config_type][entry] else: if not quiet: logger.warning(f'Unable to find {entry} in config file.') else: if not quiet: logger.warning(f'No {config_type} config file available.') if not quiet: logger.warning(f'Falling back on sample config, please initialize the {config_type} config file.') with (get_homedir() / 'config' / f'{config_type}.json.sample').open() as _c: sample_config = json.load(_c) return sample_config[entry]
[ "def", "get_config", "(", "config_type", ":", "str", ",", "entry", ":", "str", ",", "quiet", ":", "bool", "=", "False", ")", "->", "Any", ":", "global", "configs", "if", "not", "configs", ":", "load_configs", "(", ")", "if", "config_type", "in", "confi...
https://github.com/Lookyloo/lookyloo/blob/45ec8efe64d4b549e2598bee0300bb8ffb33ea91/lookyloo/default/helpers.py#L61-L79
sympy/sympy
d822fcba181155b85ff2b29fe525adbafb22b448
sympy/physics/quantum/trace.py
python
Tr.__new__
(cls, *args)
Construct a Trace object. Parameters ========== args = SymPy expression indices = tuple/list if indices, optional
Construct a Trace object.
[ "Construct", "a", "Trace", "object", "." ]
def __new__(cls, *args): """ Construct a Trace object. Parameters ========== args = SymPy expression indices = tuple/list if indices, optional """ # expect no indices,int or a tuple/list/Tuple if (len(args) == 2): if not isinstance(args[1], (list, Tuple, tuple)): indices = Tuple(args[1]) else: indices = Tuple(*args[1]) expr = args[0] elif (len(args) == 1): indices = Tuple() expr = args[0] else: raise ValueError("Arguments to Tr should be of form " "(expr[, [indices]])") if isinstance(expr, Matrix): return expr.trace() elif hasattr(expr, 'trace') and callable(expr.trace): #for any objects that have trace() defined e.g numpy return expr.trace() elif isinstance(expr, Add): return Add(*[Tr(arg, indices) for arg in expr.args]) elif isinstance(expr, Mul): c_part, nc_part = expr.args_cnc() if len(nc_part) == 0: return Mul(*c_part) else: obj = Expr.__new__(cls, Mul(*nc_part), indices ) #this check is needed to prevent cached instances #being returned even if len(c_part)==0 return Mul(*c_part)*obj if len(c_part) > 0 else obj elif isinstance(expr, Pow): if (_is_scalar(expr.args[0]) and _is_scalar(expr.args[1])): return expr else: return Expr.__new__(cls, expr, indices) else: if (_is_scalar(expr)): return expr return Expr.__new__(cls, expr, indices)
[ "def", "__new__", "(", "cls", ",", "*", "args", ")", ":", "# expect no indices,int or a tuple/list/Tuple", "if", "(", "len", "(", "args", ")", "==", "2", ")", ":", "if", "not", "isinstance", "(", "args", "[", "1", "]", ",", "(", "list", ",", "Tuple", ...
https://github.com/sympy/sympy/blob/d822fcba181155b85ff2b29fe525adbafb22b448/sympy/physics/quantum/trace.py#L110-L161
oilshell/oil
94388e7d44a9ad879b12615f6203b38596b5a2d3
opy/pytree.py
python
WildcardPattern.match
(self, node, results=None)
return self.match_seq([node], results)
Does this pattern exactly match a node?
Does this pattern exactly match a node?
[ "Does", "this", "pattern", "exactly", "match", "a", "node?" ]
def match(self, node, results=None): """Does this pattern exactly match a node?""" return self.match_seq([node], results)
[ "def", "match", "(", "self", ",", "node", ",", "results", "=", "None", ")", ":", "return", "self", ".", "match_seq", "(", "[", "node", "]", ",", "results", ")" ]
https://github.com/oilshell/oil/blob/94388e7d44a9ad879b12615f6203b38596b5a2d3/opy/pytree.py#L628-L630
heynemann/pyccuracy
0bbe3bcff4d13a6501bf77d5af9457f6a1491ab6
pyccuracy/drivers/core/selenium_webdriver.py
python
SeleniumWebdriver.radio_uncheck
(self, radio_selector)
return self.checkbox_uncheck(radio_selector)
[]
def radio_uncheck(self, radio_selector): return self.checkbox_uncheck(radio_selector)
[ "def", "radio_uncheck", "(", "self", ",", "radio_selector", ")", ":", "return", "self", ".", "checkbox_uncheck", "(", "radio_selector", ")" ]
https://github.com/heynemann/pyccuracy/blob/0bbe3bcff4d13a6501bf77d5af9457f6a1491ab6/pyccuracy/drivers/core/selenium_webdriver.py#L134-L135
MillionIntegrals/vel
f3ce7da64362ad207f40f2c0d58d9300a25df3e8
vel/api/data/image_ops.py
python
lighting
(im, b, c)
return np.clip((im-mu)*c+mu+b,0.,1.).astype(np.float32)
adjusts image's balance and contrast
adjusts image's balance and contrast
[ "adjusts", "image", "s", "balance", "and", "contrast" ]
def lighting(im, b, c): ''' adjusts image's balance and contrast''' if b==0 and c==1: return im mu = np.average(im) return np.clip((im-mu)*c+mu+b,0.,1.).astype(np.float32)
[ "def", "lighting", "(", "im", ",", "b", ",", "c", ")", ":", "if", "b", "==", "0", "and", "c", "==", "1", ":", "return", "im", "mu", "=", "np", ".", "average", "(", "im", ")", "return", "np", ".", "clip", "(", "(", "im", "-", "mu", ")", "*...
https://github.com/MillionIntegrals/vel/blob/f3ce7da64362ad207f40f2c0d58d9300a25df3e8/vel/api/data/image_ops.py#L80-L84
JaniceWuo/MovieRecommend
4c86db64ca45598917d304f535413df3bc9fea65
movierecommend/venv1/Lib/site-packages/django/db/backends/sqlite3/creation.py
python
DatabaseCreation._create_test_db
(self, verbosity, autoclobber, keepdb=False)
return test_database_name
[]
def _create_test_db(self, verbosity, autoclobber, keepdb=False): test_database_name = self._get_test_db_name() if keepdb: return test_database_name if not self.is_in_memory_db(test_database_name): # Erase the old test database if verbosity >= 1: print("Destroying old test database for alias %s..." % ( self._get_database_display_str(verbosity, test_database_name), )) if os.access(test_database_name, os.F_OK): if not autoclobber: confirm = input( "Type 'yes' if you would like to try deleting the test " "database '%s', or 'no' to cancel: " % test_database_name ) if autoclobber or confirm == 'yes': try: os.remove(test_database_name) except Exception as e: sys.stderr.write("Got an error deleting the old test database: %s\n" % e) sys.exit(2) else: print("Tests cancelled.") sys.exit(1) return test_database_name
[ "def", "_create_test_db", "(", "self", ",", "verbosity", ",", "autoclobber", ",", "keepdb", "=", "False", ")", ":", "test_database_name", "=", "self", ".", "_get_test_db_name", "(", ")", "if", "keepdb", ":", "return", "test_database_name", "if", "not", "self",...
https://github.com/JaniceWuo/MovieRecommend/blob/4c86db64ca45598917d304f535413df3bc9fea65/movierecommend/venv1/Lib/site-packages/django/db/backends/sqlite3/creation.py#L33-L59
IronLanguages/ironpython3
7a7bb2a872eeab0d1009fc8a6e24dca43f65b693
Src/StdLib/Lib/importlib/_bootstrap.py
python
_install
(sys_module, _imp_module)
Install importlib as the implementation of import.
Install importlib as the implementation of import.
[ "Install", "importlib", "as", "the", "implementation", "of", "import", "." ]
def _install(sys_module, _imp_module): """Install importlib as the implementation of import.""" _setup(sys_module, _imp_module) supported_loaders = _get_supported_file_loaders() sys.path_hooks.extend([FileFinder.path_hook(*supported_loaders)]) sys.meta_path.append(BuiltinImporter) sys.meta_path.append(FrozenImporter) if _os.__name__ == 'nt': sys.meta_path.append(WindowsRegistryFinder) sys.meta_path.append(PathFinder)
[ "def", "_install", "(", "sys_module", ",", "_imp_module", ")", ":", "_setup", "(", "sys_module", ",", "_imp_module", ")", "supported_loaders", "=", "_get_supported_file_loaders", "(", ")", "sys", ".", "path_hooks", ".", "extend", "(", "[", "FileFinder", ".", "...
https://github.com/IronLanguages/ironpython3/blob/7a7bb2a872eeab0d1009fc8a6e24dca43f65b693/Src/StdLib/Lib/importlib/_bootstrap.py#L2452-L2461