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
dropbox/dropbox-sdk-python
015437429be224732990041164a21a0501235db1
dropbox/team_log.py
python
EventType.file_unlike_comment
(cls, val)
return cls('file_unlike_comment', val)
Create an instance of this class set to the ``file_unlike_comment`` tag with value ``val``. :param FileUnlikeCommentType val: :rtype: EventType
Create an instance of this class set to the ``file_unlike_comment`` tag with value ``val``.
[ "Create", "an", "instance", "of", "this", "class", "set", "to", "the", "file_unlike_comment", "tag", "with", "value", "val", "." ]
def file_unlike_comment(cls, val): """ Create an instance of this class set to the ``file_unlike_comment`` tag with value ``val``. :param FileUnlikeCommentType val: :rtype: EventType """ return cls('file_unlike_comment', val)
[ "def", "file_unlike_comment", "(", "cls", ",", "val", ")", ":", "return", "cls", "(", "'file_unlike_comment'", ",", "val", ")" ]
https://github.com/dropbox/dropbox-sdk-python/blob/015437429be224732990041164a21a0501235db1/dropbox/team_log.py#L23324-L23332
Qiskit/qiskit-terra
b66030e3b9192efdd3eb95cf25c6545fe0a13da4
qiskit/visualization/pulse/matplotlib.py
python
EventsOutputChannels._trim
(self, events: Dict[int, Any])
return events_in_time_range
Return events during given `time_range`. Args: events: time and operation of events. Returns: Events within the specified time range.
Return events during given `time_range`.
[ "Return", "events", "during", "given", "time_range", "." ]
def _trim(self, events: Dict[int, Any]) -> Dict[int, Any]: """Return events during given `time_range`. Args: events: time and operation of events. Returns: Events within the specified time range. """ events_in_time_range = {} for k, v in events.items(): if self.t0 <= k <= self.tf: events_in_time_range[k] = v return events_in_time_range
[ "def", "_trim", "(", "self", ",", "events", ":", "Dict", "[", "int", ",", "Any", "]", ")", "->", "Dict", "[", "int", ",", "Any", "]", ":", "events_in_time_range", "=", "{", "}", "for", "k", ",", "v", "in", "events", ".", "items", "(", ")", ":",...
https://github.com/Qiskit/qiskit-terra/blob/b66030e3b9192efdd3eb95cf25c6545fe0a13da4/qiskit/visualization/pulse/matplotlib.py#L261-L276
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/bmp280/sensor.py
python
Bmp280TemperatureSensor.update
(self)
Fetch new state data for the sensor.
Fetch new state data for the sensor.
[ "Fetch", "new", "state", "data", "for", "the", "sensor", "." ]
def update(self): """Fetch new state data for the sensor.""" try: self._attr_native_value = round(self._bmp280.temperature, 1) if not self.available: _LOGGER.warning("Communication restored with temperature sensor") self._attr_available = True except OSError: # this is thrown when a working sensor is unplugged between two updates _LOGGER.warning( "Unable to read temperature data due to a communication problem" ) self._attr_available = False
[ "def", "update", "(", "self", ")", ":", "try", ":", "self", ".", "_attr_native_value", "=", "round", "(", "self", ".", "_bmp280", ".", "temperature", ",", "1", ")", "if", "not", "self", ".", "available", ":", "_LOGGER", ".", "warning", "(", "\"Communic...
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/bmp280/sensor.py#L111-L123
khanhnamle1994/natural-language-processing
01d450d5ac002b0156ef4cf93a07cb508c1bcdc5
assignment1/.env/lib/python2.7/site-packages/IPython/kernel/blocking/channels.py
python
BlockingChannelMixin.get_msgs
(self)
return msgs
Get all messages that are currently ready.
Get all messages that are currently ready.
[ "Get", "all", "messages", "that", "are", "currently", "ready", "." ]
def get_msgs(self): """ Get all messages that are currently ready. """ msgs = [] while True: try: msgs.append(self.get_msg(block=False)) except Empty: break return msgs
[ "def", "get_msgs", "(", "self", ")", ":", "msgs", "=", "[", "]", "while", "True", ":", "try", ":", "msgs", ".", "append", "(", "self", ".", "get_msg", "(", "block", "=", "False", ")", ")", "except", "Empty", ":", "break", "return", "msgs" ]
https://github.com/khanhnamle1994/natural-language-processing/blob/01d450d5ac002b0156ef4cf93a07cb508c1bcdc5/assignment1/.env/lib/python2.7/site-packages/IPython/kernel/blocking/channels.py#L46-L54
getsentry/sentry
83b1f25aac3e08075e0e2495bc29efaf35aca18a
src/sentry/integrations/jira_server/client.py
python
JiraServer.user_id_field
(self)
return "name"
Jira-Server doesn't require GDPR compliant API usage so we can use `name`
Jira-Server doesn't require GDPR compliant API usage so we can use `name`
[ "Jira", "-", "Server", "doesn", "t", "require", "GDPR", "compliant", "API", "usage", "so", "we", "can", "use", "name" ]
def user_id_field(self): """ Jira-Server doesn't require GDPR compliant API usage so we can use `name` """ return "name"
[ "def", "user_id_field", "(", "self", ")", ":", "return", "\"name\"" ]
https://github.com/getsentry/sentry/blob/83b1f25aac3e08075e0e2495bc29efaf35aca18a/src/sentry/integrations/jira_server/client.py#L143-L147
zvtvz/zvt
054bf8a3e7a049df7087c324fa87e8effbaf5bdc
src/zvt/contract/factor.py
python
Factor.drawer_sub_df_list
(self)
return None
[]
def drawer_sub_df_list(self) -> Optional[List[pd.DataFrame]]: if (self.transformer is not None or self.accumulator is not None) and pd_is_not_null(self.result_df): return [self.result_df] return None
[ "def", "drawer_sub_df_list", "(", "self", ")", "->", "Optional", "[", "List", "[", "pd", ".", "DataFrame", "]", "]", ":", "if", "(", "self", ".", "transformer", "is", "not", "None", "or", "self", ".", "accumulator", "is", "not", "None", ")", "and", "...
https://github.com/zvtvz/zvt/blob/054bf8a3e7a049df7087c324fa87e8effbaf5bdc/src/zvt/contract/factor.py#L456-L459
picrust/picrust2
610ffbcd28f8bf0f9fa93c88873498a39a77c57f
picrust2/util.py
python
write_phylip
(seq, outfile)
Will write a dictionary containing id, sequence pairs in Phylip format. Originally written to run PaPaRa.
Will write a dictionary containing id, sequence pairs in Phylip format. Originally written to run PaPaRa.
[ "Will", "write", "a", "dictionary", "containing", "id", "sequence", "pairs", "in", "Phylip", "format", ".", "Originally", "written", "to", "run", "PaPaRa", "." ]
def write_phylip(seq, outfile): '''Will write a dictionary containing id, sequence pairs in Phylip format. Originally written to run PaPaRa.''' out_phylip = open(outfile, "w") seq_count = 0 for s in seq: # Write header if this is first line. if seq_count == 0: seq_length = len(seq[s]) out_phylip.write(str(len(seq)) + " " + str(seq_length) + "\n") seq_count += 1 if seq_length != len(seq[s]): # Throw error if sequence is unexpected length. raise SystemExit("Expected sequence " + s + " to be length " + str(seq_length) + ", but was " + str(len(seq[s]))) out_phylip.write(s + " " + seq[s] + "\n") out_phylip.close()
[ "def", "write_phylip", "(", "seq", ",", "outfile", ")", ":", "out_phylip", "=", "open", "(", "outfile", ",", "\"w\"", ")", "seq_count", "=", "0", "for", "s", "in", "seq", ":", "# Write header if this is first line.", "if", "seq_count", "==", "0", ":", "seq...
https://github.com/picrust/picrust2/blob/610ffbcd28f8bf0f9fa93c88873498a39a77c57f/picrust2/util.py#L134-L162
hubblestack/hubble
763142474edcecdec5fd25591dc29c3536e8f969
hubblestack/modules/nebula_osquery.py
python
version
()
return __version__
Report version of this module
Report version of this module
[ "Report", "version", "of", "this", "module" ]
def version(): """ Report version of this module """ return __version__
[ "def", "version", "(", ")", ":", "return", "__version__" ]
https://github.com/hubblestack/hubble/blob/763142474edcecdec5fd25591dc29c3536e8f969/hubblestack/modules/nebula_osquery.py#L588-L592
andresriancho/w3af
cd22e5252243a87aaa6d0ddea47cf58dacfe00a9
w3af/core/data/request/fuzzable_request.py
python
FuzzableRequest.get_force_fuzzing_url_parts
(self)
return list(self._force_fuzzing_url_parts)
Returns a list of url parts which should be fuzzed. :return: A tuple of (path part, is variable) tuples.`
Returns a list of url parts which should be fuzzed. :return: A tuple of (path part, is variable) tuples.`
[ "Returns", "a", "list", "of", "url", "parts", "which", "should", "be", "fuzzed", ".", ":", "return", ":", "A", "tuple", "of", "(", "path", "part", "is", "variable", ")", "tuples", "." ]
def get_force_fuzzing_url_parts(self): """ Returns a list of url parts which should be fuzzed. :return: A tuple of (path part, is variable) tuples.` """ return list(self._force_fuzzing_url_parts)
[ "def", "get_force_fuzzing_url_parts", "(", "self", ")", ":", "return", "list", "(", "self", ".", "_force_fuzzing_url_parts", ")" ]
https://github.com/andresriancho/w3af/blob/cd22e5252243a87aaa6d0ddea47cf58dacfe00a9/w3af/core/data/request/fuzzable_request.py#L487-L492
007gzs/dingtalk-sdk
7979da2e259fdbc571728cae2425a04dbc65850a
dingtalk/client/api/taobao.py
python
TbDingDing.dingtalk_oapi_attendance_getusergroup
( self, userid )
return self._top_request( "dingtalk.oapi.attendance.getusergroup", { "userid": userid } )
获取用户考勤组 在钉钉考勤微应用中,考勤组是一类具有相同的班次、考勤位置等考勤规则的人或部门的组合,一个企业中的一个人只能属于一个考勤组。如果您的企业使用了钉钉考勤并希望获取员工的考勤组信息,可选择使用此接口 文档地址:https://open-doc.dingtalk.com/docs/api.htm?apiId=36987 :param userid: 员工在企业内的UserID,企业用来唯一标识用户的字段。
获取用户考勤组 在钉钉考勤微应用中,考勤组是一类具有相同的班次、考勤位置等考勤规则的人或部门的组合,一个企业中的一个人只能属于一个考勤组。如果您的企业使用了钉钉考勤并希望获取员工的考勤组信息,可选择使用此接口 文档地址:https://open-doc.dingtalk.com/docs/api.htm?apiId=36987
[ "获取用户考勤组", "在钉钉考勤微应用中,考勤组是一类具有相同的班次、考勤位置等考勤规则的人或部门的组合,一个企业中的一个人只能属于一个考勤组。如果您的企业使用了钉钉考勤并希望获取员工的考勤组信息,可选择使用此接口", "文档地址:https", ":", "//", "open", "-", "doc", ".", "dingtalk", ".", "com", "/", "docs", "/", "api", ".", "htm?apiId", "=", "36987" ]
def dingtalk_oapi_attendance_getusergroup( self, userid ): """ 获取用户考勤组 在钉钉考勤微应用中,考勤组是一类具有相同的班次、考勤位置等考勤规则的人或部门的组合,一个企业中的一个人只能属于一个考勤组。如果您的企业使用了钉钉考勤并希望获取员工的考勤组信息,可选择使用此接口 文档地址:https://open-doc.dingtalk.com/docs/api.htm?apiId=36987 :param userid: 员工在企业内的UserID,企业用来唯一标识用户的字段。 """ return self._top_request( "dingtalk.oapi.attendance.getusergroup", { "userid": userid } )
[ "def", "dingtalk_oapi_attendance_getusergroup", "(", "self", ",", "userid", ")", ":", "return", "self", ".", "_top_request", "(", "\"dingtalk.oapi.attendance.getusergroup\"", ",", "{", "\"userid\"", ":", "userid", "}", ")" ]
https://github.com/007gzs/dingtalk-sdk/blob/7979da2e259fdbc571728cae2425a04dbc65850a/dingtalk/client/api/taobao.py#L2109-L2125
PyCQA/astroid
a815443f62faae05249621a396dcf0afd884a619
astroid/nodes/scoped_nodes/scoped_nodes.py
python
ClassDef.local_attr
(self, name, context=None)
Get the list of assign nodes associated to the given name. Assignments are looked for in both this class and in parents. :returns: The list of assignments to the given name. :rtype: list(NodeNG) :raises AttributeInferenceError: If no attribute with this name can be found in this class or parent classes.
Get the list of assign nodes associated to the given name.
[ "Get", "the", "list", "of", "assign", "nodes", "associated", "to", "the", "given", "name", "." ]
def local_attr(self, name, context=None): """Get the list of assign nodes associated to the given name. Assignments are looked for in both this class and in parents. :returns: The list of assignments to the given name. :rtype: list(NodeNG) :raises AttributeInferenceError: If no attribute with this name can be found in this class or parent classes. """ result = [] if name in self.locals: result = self.locals[name] else: class_node = next(self.local_attr_ancestors(name, context), None) if class_node: result = class_node.locals[name] result = [n for n in result if not isinstance(n, node_classes.DelAttr)] if result: return result raise AttributeInferenceError(target=self, attribute=name, context=context)
[ "def", "local_attr", "(", "self", ",", "name", ",", "context", "=", "None", ")", ":", "result", "=", "[", "]", "if", "name", "in", "self", ".", "locals", ":", "result", "=", "self", ".", "locals", "[", "name", "]", "else", ":", "class_node", "=", ...
https://github.com/PyCQA/astroid/blob/a815443f62faae05249621a396dcf0afd884a619/astroid/nodes/scoped_nodes/scoped_nodes.py#L2629-L2650
ESCOMP/CESM
4e21488773baa1bd9fb06fb8750db9f9bd12b705
manage_externals/manic/externals_description.py
python
LstripReader.__iter__
(self)
return self
Begin an iteration
Begin an iteration
[ "Begin", "an", "iteration" ]
def __iter__(self): """Begin an iteration""" self._index = 0 return self
[ "def", "__iter__", "(", "self", ")", ":", "self", ".", "_index", "=", "0", "return", "self" ]
https://github.com/ESCOMP/CESM/blob/4e21488773baa1bd9fb06fb8750db9f9bd12b705/manage_externals/manic/externals_description.py#L133-L136
nerdvegas/rez
d392c65bf63b4bca8106f938cec49144ba54e770
src/rez/vendor/attr/_make.py
python
_make_attr_tuple_class
(cls_name, attr_names)
return globs[attr_class_name]
Create a tuple subclass to hold `Attribute`s for an `attrs` class. The subclass is a bare tuple with properties for names. class MyClassAttributes(tuple): __slots__ = () x = property(itemgetter(0))
Create a tuple subclass to hold `Attribute`s for an `attrs` class.
[ "Create", "a", "tuple", "subclass", "to", "hold", "Attribute", "s", "for", "an", "attrs", "class", "." ]
def _make_attr_tuple_class(cls_name, attr_names): """ Create a tuple subclass to hold `Attribute`s for an `attrs` class. The subclass is a bare tuple with properties for names. class MyClassAttributes(tuple): __slots__ = () x = property(itemgetter(0)) """ attr_class_name = "{}Attributes".format(cls_name) attr_class_template = [ "class {}(tuple):".format(attr_class_name), " __slots__ = ()", ] if attr_names: for i, attr_name in enumerate(attr_names): attr_class_template.append( _tuple_property_pat.format(index=i, attr_name=attr_name) ) else: attr_class_template.append(" pass") globs = {"_attrs_itemgetter": itemgetter, "_attrs_property": property} eval(compile("\n".join(attr_class_template), "", "exec"), globs) return globs[attr_class_name]
[ "def", "_make_attr_tuple_class", "(", "cls_name", ",", "attr_names", ")", ":", "attr_class_name", "=", "\"{}Attributes\"", ".", "format", "(", "cls_name", ")", "attr_class_template", "=", "[", "\"class {}(tuple):\"", ".", "format", "(", "attr_class_name", ")", ",", ...
https://github.com/nerdvegas/rez/blob/d392c65bf63b4bca8106f938cec49144ba54e770/src/rez/vendor/attr/_make.py#L222-L247
facebookresearch/SpanBERT
0670d8b6a38f6714b85ea7a033f16bd8cc162676
pretraining/fairseq/utils.py
python
_upgrade_state_dict
(state)
return state
Helper for upgrading old model checkpoints.
Helper for upgrading old model checkpoints.
[ "Helper", "for", "upgrading", "old", "model", "checkpoints", "." ]
def _upgrade_state_dict(state): """Helper for upgrading old model checkpoints.""" # add optimizer_history if 'optimizer_history' not in state: state['optimizer_history'] = [ { 'criterion_name': 'CrossEntropyCriterion', 'best_loss': state['best_loss'], }, ] state['last_optimizer_state'] = state['optimizer'] del state['optimizer'] del state['best_loss'] # move extra_state into sub-dictionary if 'epoch' in state and 'extra_state' not in state: state['extra_state'] = { 'epoch': state['epoch'], 'batch_offset': state['batch_offset'], 'val_loss': state['val_loss'], } del state['epoch'] del state['batch_offset'] del state['val_loss'] # reduce optimizer history's memory usage (only keep the last state) if 'optimizer' in state['optimizer_history'][-1]: state['last_optimizer_state'] = state['optimizer_history'][-1]['optimizer'] for optim_hist in state['optimizer_history']: del optim_hist['optimizer'] # record the optimizer class name if 'optimizer_name' not in state['optimizer_history'][-1]: state['optimizer_history'][-1]['optimizer_name'] = 'FairseqNAG' # move best_loss into lr_scheduler_state if 'lr_scheduler_state' not in state['optimizer_history'][-1]: state['optimizer_history'][-1]['lr_scheduler_state'] = { 'best': state['optimizer_history'][-1]['best_loss'], } del state['optimizer_history'][-1]['best_loss'] # keep track of number of updates if 'num_updates' not in state['optimizer_history'][-1]: state['optimizer_history'][-1]['num_updates'] = 0 # old model checkpoints may not have separate source/target positions if hasattr(state['args'], 'max_positions') and not hasattr(state['args'], 'max_source_positions'): state['args'].max_source_positions = state['args'].max_positions state['args'].max_target_positions = state['args'].max_positions # use stateful training data iterator if 'train_iterator' not in state['extra_state']: state['extra_state']['train_iterator'] = { 'epoch': state['extra_state']['epoch'], 'iterations_in_epoch': state['extra_state'].get('batch_offset', 0), } return state
[ "def", "_upgrade_state_dict", "(", "state", ")", ":", "# add optimizer_history", "if", "'optimizer_history'", "not", "in", "state", ":", "state", "[", "'optimizer_history'", "]", "=", "[", "{", "'criterion_name'", ":", "'CrossEntropyCriterion'", ",", "'best_loss'", ...
https://github.com/facebookresearch/SpanBERT/blob/0670d8b6a38f6714b85ea7a033f16bd8cc162676/pretraining/fairseq/utils.py#L81-L131
AppScale/gts
46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9
AppServer/lib/django-1.3/django/contrib/gis/db/backends/postgis/operations.py
python
PostGISOperations.convert_extent3d
(self, box3d)
return (xmin, ymin, zmin, xmax, ymax, zmax)
Returns a 6-tuple extent for the `Extent3D` aggregate by converting the 3d bounding-box text returnded by PostGIS (`box3d` argument), for example: "BOX3D(-90.0 30.0 1, -85.0 40.0 2)".
Returns a 6-tuple extent for the `Extent3D` aggregate by converting the 3d bounding-box text returnded by PostGIS (`box3d` argument), for example: "BOX3D(-90.0 30.0 1, -85.0 40.0 2)".
[ "Returns", "a", "6", "-", "tuple", "extent", "for", "the", "Extent3D", "aggregate", "by", "converting", "the", "3d", "bounding", "-", "box", "text", "returnded", "by", "PostGIS", "(", "box3d", "argument", ")", "for", "example", ":", "BOX3D", "(", "-", "9...
def convert_extent3d(self, box3d): """ Returns a 6-tuple extent for the `Extent3D` aggregate by converting the 3d bounding-box text returnded by PostGIS (`box3d` argument), for example: "BOX3D(-90.0 30.0 1, -85.0 40.0 2)". """ ll, ur = box3d[6:-1].split(',') xmin, ymin, zmin = map(float, ll.split()) xmax, ymax, zmax = map(float, ur.split()) return (xmin, ymin, zmin, xmax, ymax, zmax)
[ "def", "convert_extent3d", "(", "self", ",", "box3d", ")", ":", "ll", ",", "ur", "=", "box3d", "[", "6", ":", "-", "1", "]", ".", "split", "(", "','", ")", "xmin", ",", "ymin", ",", "zmin", "=", "map", "(", "float", ",", "ll", ".", "split", "...
https://github.com/AppScale/gts/blob/46f909cf5dc5ba81faf9d81dc9af598dcf8a82a9/AppServer/lib/django-1.3/django/contrib/gis/db/backends/postgis/operations.py#L301-L310
dbsr/vimfox
4a0145937226843b4b8b5681136ab9a45fb5d066
vimfox/server/server.py
python
VimFoxNamespace.initialize
(self)
return True
[]
def initialize(self): self.logger = app.logger self.log('socket initialized') self.sockets[id(self)] = self return True
[ "def", "initialize", "(", "self", ")", ":", "self", ".", "logger", "=", "app", ".", "logger", "self", ".", "log", "(", "'socket initialized'", ")", "self", ".", "sockets", "[", "id", "(", "self", ")", "]", "=", "self", "return", "True" ]
https://github.com/dbsr/vimfox/blob/4a0145937226843b4b8b5681136ab9a45fb5d066/vimfox/server/server.py#L29-L34
cloudera/hue
23f02102d4547c17c32bd5ea0eb24e9eadd657a4
desktop/core/ext-py/docutils-0.14/docutils/utils/math/math2html.py
python
NumberCounter.getsequence
(self, sequence)
return sequence[(self.value - 1) % len(sequence)]
Get the next value from elyxer.a sequence.
Get the next value from elyxer.a sequence.
[ "Get", "the", "next", "value", "from", "elyxer", ".", "a", "sequence", "." ]
def getsequence(self, sequence): "Get the next value from elyxer.a sequence." return sequence[(self.value - 1) % len(sequence)]
[ "def", "getsequence", "(", "self", ",", "sequence", ")", ":", "return", "sequence", "[", "(", "self", ".", "value", "-", "1", ")", "%", "len", "(", "sequence", ")", "]" ]
https://github.com/cloudera/hue/blob/23f02102d4547c17c32bd5ea0eb24e9eadd657a4/desktop/core/ext-py/docutils-0.14/docutils/utils/math/math2html.py#L3215-L3217
keiffster/program-y
8c99b56f8c32f01a7b9887b5daae9465619d0385
src/programy/mappings/maps.py
python
MapCollection._reload_collection
(self, maps_store_engine, map_name)
[]
def _reload_collection(self, maps_store_engine, map_name): maps_store = maps_store_engine.maps_store() maps_store.reload(self, map_name)
[ "def", "_reload_collection", "(", "self", ",", "maps_store_engine", ",", "map_name", ")", ":", "maps_store", "=", "maps_store_engine", ".", "maps_store", "(", ")", "maps_store", ".", "reload", "(", "self", ",", "map_name", ")" ]
https://github.com/keiffster/program-y/blob/8c99b56f8c32f01a7b9887b5daae9465619d0385/src/programy/mappings/maps.py#L77-L79
EmilyAlsentzer/clinicalBERT
a9d91698929b7189311bba364ccdd0360e847276
downstream_tasks/run_classifier.py
python
MedNLIProcessor.get_dev_examples
(self, data_dir)
return self._create_examples(file_path)
Gets a collection of `InputExample`s for the dev set.
Gets a collection of `InputExample`s for the dev set.
[ "Gets", "a", "collection", "of", "InputExample", "s", "for", "the", "dev", "set", "." ]
def get_dev_examples(self, data_dir): """Gets a collection of `InputExample`s for the dev set.""" file_path = os.path.join(data_dir, "mli_dev_v1.jsonl") return self._create_examples(file_path)
[ "def", "get_dev_examples", "(", "self", ",", "data_dir", ")", ":", "file_path", "=", "os", ".", "path", ".", "join", "(", "data_dir", ",", "\"mli_dev_v1.jsonl\"", ")", "return", "self", ".", "_create_examples", "(", "file_path", ")" ]
https://github.com/EmilyAlsentzer/clinicalBERT/blob/a9d91698929b7189311bba364ccdd0360e847276/downstream_tasks/run_classifier.py#L225-L228
tobi-wan-kenobi/bumblebee-status
08b5386140fb14ecbccdf9eb7520f597967dee4d
bumblebee_status/util/location.py
python
coordinates
()
return __get("latitude"), __get("longitude")
Returns a latitude, longitude pair :return: current latitude and longitude :rtype: pair of strings
Returns a latitude, longitude pair
[ "Returns", "a", "latitude", "longitude", "pair" ]
def coordinates(): """Returns a latitude, longitude pair :return: current latitude and longitude :rtype: pair of strings """ return __get("latitude"), __get("longitude")
[ "def", "coordinates", "(", ")", ":", "return", "__get", "(", "\"latitude\"", ")", ",", "__get", "(", "\"longitude\"", ")" ]
https://github.com/tobi-wan-kenobi/bumblebee-status/blob/08b5386140fb14ecbccdf9eb7520f597967dee4d/bumblebee_status/util/location.py#L76-L82
edfungus/Crouton
ada98b3930192938a48909072b45cb84b945f875
clients/python_clients/venv/lib/python2.7/site-packages/setuptools/command/egg_info.py
python
manifest_maker.write_manifest
(self)
Write the file list in 'self.filelist' to the manifest file named by 'self.manifest'.
Write the file list in 'self.filelist' to the manifest file named by 'self.manifest'.
[ "Write", "the", "file", "list", "in", "self", ".", "filelist", "to", "the", "manifest", "file", "named", "by", "self", ".", "manifest", "." ]
def write_manifest(self): """ Write the file list in 'self.filelist' to the manifest file named by 'self.manifest'. """ self.filelist._repair() # Now _repairs should encodability, but not unicode files = [self._manifest_normalize(f) for f in self.filelist.files] msg = "writing manifest file '%s'" % self.manifest self.execute(write_file, (self.manifest, files), msg)
[ "def", "write_manifest", "(", "self", ")", ":", "self", ".", "filelist", ".", "_repair", "(", ")", "# Now _repairs should encodability, but not unicode", "files", "=", "[", "self", ".", "_manifest_normalize", "(", "f", ")", "for", "f", "in", "self", ".", "file...
https://github.com/edfungus/Crouton/blob/ada98b3930192938a48909072b45cb84b945f875/clients/python_clients/venv/lib/python2.7/site-packages/setuptools/command/egg_info.py#L303-L313
rwth-i6/returnn
f2d718a197a280b0d5f0fd91a7fcb8658560dddb
returnn/theano/layers/output.py
python
OutputLayer.__init__
(self, loss, y, dtype=None, reshape_target=False, copy_input=None, copy_output=None, time_limit=0, use_source_index=False, auto_fix_target_length=False, sigmoid_outputs=False, exp_outputs=False, gauss_outputs=False, activation=None, prior_scale=0.0, log_prior=None, use_label_priors=0, compute_priors_via_baum_welch=False, compute_priors=False, compute_priors_exp_average=0, compute_priors_accumulate_batches=None, compute_distortions=False, softmax_smoothing=1.0, grad_clip_z=None, grad_discard_out_of_bound_z=None, normalize_length=False, exclude_labels=[], include_labels=[], apply_softmax=True, batchwise_softmax=False, substract_prior_from_output=False, input_output_similarity=None, input_output_similarity_scale=1, scale_by_error=False, copy_weights=False, target_delay=0, compute_sequence_weights=False, **kwargs)
:param theano.Variable index: index for batches :param str loss: e.g. 'ce'
:param theano.Variable index: index for batches :param str loss: e.g. 'ce'
[ ":", "param", "theano", ".", "Variable", "index", ":", "index", "for", "batches", ":", "param", "str", "loss", ":", "e", ".", "g", ".", "ce" ]
def __init__(self, loss, y, dtype=None, reshape_target=False, copy_input=None, copy_output=None, time_limit=0, use_source_index=False, auto_fix_target_length=False, sigmoid_outputs=False, exp_outputs=False, gauss_outputs=False, activation=None, prior_scale=0.0, log_prior=None, use_label_priors=0, compute_priors_via_baum_welch=False, compute_priors=False, compute_priors_exp_average=0, compute_priors_accumulate_batches=None, compute_distortions=False, softmax_smoothing=1.0, grad_clip_z=None, grad_discard_out_of_bound_z=None, normalize_length=False, exclude_labels=[], include_labels=[], apply_softmax=True, batchwise_softmax=False, substract_prior_from_output=False, input_output_similarity=None, input_output_similarity_scale=1, scale_by_error=False, copy_weights=False, target_delay=0, compute_sequence_weights=False, **kwargs): """ :param theano.Variable index: index for batches :param str loss: e.g. 'ce' """ super(OutputLayer, self).__init__(**kwargs) self.set_attr("normalize_length", normalize_length) if dtype: self.set_attr('dtype', dtype) if copy_input: self.set_attr("copy_input", copy_input.name) if reshape_target: self.set_attr("reshape_target",reshape_target) if grad_clip_z is not None: self.set_attr("grad_clip_z", grad_clip_z) if compute_distortions: self.set_attr("compute_distortions", compute_distortions) if grad_discard_out_of_bound_z is not None: self.set_attr("grad_discard_out_of_bound_z", grad_discard_out_of_bound_z) if not apply_softmax: self.set_attr("apply_softmax", apply_softmax) if substract_prior_from_output: self.set_attr("substract_prior_from_output", substract_prior_from_output) if input_output_similarity: self.set_attr("input_output_similarity", input_output_similarity) self.set_attr("input_output_similarity_scale", input_output_similarity_scale) if use_source_index: self.set_attr("use_source_index", use_source_index) src_index = self.sources[0].index self.index = src_index if compute_sequence_weights: self.set_attr('compute_sequence_weights', compute_sequence_weights) if not copy_input or copy_weights: if copy_weights: self.params = {} self.b = self.add_param(copy_input.b) self.W_in = [ self.add_param(W) for W in copy_input.W_in ] self.masks = copy_input.masks self.mass = copy_input.mass else: self.W_in = [self.add_param(self.create_forward_weights(source.attrs['n_out'], self.attrs['n_out'], name="W_in_%s_%s" % (source.name, self.name))) for source in self.sources] self.z = self.b assert len(self.sources) == len(self.masks) == len(self.W_in) assert len(self.sources) > 0 for source, m, W in zip(self.sources, self.masks, self.W_in): source_output = source.output # 4D input from TwoD Layers -> collapse height dimension if source_output.ndim == 4: source_output = source_output.sum(axis=0) if source.attrs['sparse']: if source.output.ndim == 3: input = source_output[:, :, 0] # old sparse format else: assert source_output.ndim == 2 input = source.output self.z += W[T.cast(input, 'int32')] elif m is None: self.z += self.dot(source_output, W) else: self.z += self.dot(self.mass * m * source_output, W) else: self.params = {} self.z = copy_input.output assert self.z.ndim == 3 if grad_clip_z is not None: grad_clip_z = numpy.float32(grad_clip_z) self.z = theano.gradient.grad_clip(self.z, -grad_clip_z, grad_clip_z) if grad_discard_out_of_bound_z is not None: grad_discard_out_of_bound_z = numpy.float32(grad_discard_out_of_bound_z) self.z = grad_discard_out_of_bound(self.z, -grad_discard_out_of_bound_z, grad_discard_out_of_bound_z) if auto_fix_target_length: self.set_attr("auto_fix_target_length", auto_fix_target_length) source_index = self.sources[0].index from returnn.theano.util import pad self.index = pad(source=self.index, axis=0, target_axis_len=source_index.shape[0]) if y is not None: y = pad(source=y, axis=0, target_axis_len=source_index.shape[0]) if not copy_output: self.y = y self.norm = numpy.float32(1) else: if hasattr(copy_output, 'index_out'): self.norm = T.sum(self.index, dtype='float32') / T.sum(copy_output.index_out, dtype='float32') self.index = copy_output.index_out else: self.norm = T.sum(self.index, dtype='float32') / T.sum(copy_output.index, dtype='float32') self.index = copy_output.index self.y = y = copy_output.y_out self.copy_output = copy_output if y is None: self.y_data_flat = None elif isinstance(y, T.Variable): if reshape_target: if copy_output: if isinstance(copy_output,CAlignmentLayer): ind = copy_output.reduced_index.T.flatten() self.y_data_flat = y.T.flatten() self.y_data_flat = self.y_data_flat[(ind > 0).nonzero()] self.index = T.ones((self.z.shape[0], self.z.shape[1]), 'int8') else: self.y_data_flat = time_batch_make_flat(y) #self.y_data_flat = theano.printing.Print('ydataflat',attrs=['shape'])(self.y_data_flat) else: src_index = self.sources[0].index self.index = src_index self.y_data_flat = y.T.flatten() self.y_data_flat = self.y_data_flat[(self.y_data_flat >= 0).nonzero()] else: self.y_data_flat = time_batch_make_flat(y) else: assert self.attrs.get("target", "").endswith("[sparse:coo]") assert isinstance(self.y, tuple) assert len(self.y) == 3 s0, s1, weight = self.y from returnn.theano.native_op import max_and_argmax_sparse n_time = self.z.shape[0] n_batch = self.z.shape[1] mask = self.network.j[self.attrs.get("target", "").replace("[sparse:coo]", "[sparse:coo:2:0]")] out_arg = T.zeros((n_time, n_batch), dtype="float32") out_max = T.zeros((n_time, n_batch), dtype="float32") - numpy.float32(1e16) out_arg, out_max = max_and_argmax_sparse(s0, s1, weight, mask, out_arg, out_max) assert out_arg.ndim == 2 self.y_data_flat = out_arg.astype("int32") self.target_index = self.index if time_limit == 'inf': num = T.cast(T.sum(self.index), 'float32') if self.eval_flag: self.index = self.sources[0].index else: padx = T.zeros((T.abs_(self.index.shape[0] - self.z.shape[0]), self.index.shape[1], self.z.shape[2]), 'float32') + self.z[-1] pady = T.zeros((T.abs_(self.index.shape[0] - self.z.shape[0]), self.index.shape[1]), 'int32') # + y[-1] padi = T.ones((T.abs_(self.index.shape[0] - self.z.shape[0]), self.index.shape[1]), 'int8') self.z = theano.ifelse.ifelse(T.lt(self.z.shape[0], self.index.shape[0]), T.concatenate([self.z, padx], axis=0), self.z) self.y_data_flat = time_batch_make_flat(theano.ifelse.ifelse(T.gt(self.z.shape[0], self.index.shape[0]), T.concatenate([y, pady], axis=0), y)) self.index = theano.ifelse.ifelse(T.gt(self.z.shape[0], self.index.shape[0]), T.concatenate([padi, self.index], axis=0), self.index) self.norm *= num / T.cast(T.sum(self.index), 'float32') elif time_limit > 0: end = T.min([self.z.shape[0], T.constant(time_limit, 'int32')]) num = T.cast(T.sum(self.index), 'float32') self.index = T.set_subtensor(self.index[end:], T.zeros_like(self.index[end:])) self.norm = num / T.cast(T.sum(self.index), 'float32') self.z = T.set_subtensor(self.z[end:], T.zeros_like(self.z[end:])) if target_delay > 0: self.z = T.concatenate([self.z[target_delay:],self.z[-1].dimshuffle('x',0,1).repeat(target_delay,axis=0)],axis=0) self.set_attr('from', ",".join([s.name for s in self.sources])) index_flat = self.index.flatten() assert not (exclude_labels and include_labels) if include_labels: exclude_labels = [ i for i in range(self.attrs['n_out']) if not i in include_labels ] assert len(exclude_labels) < self.attrs['n_out'] for label in exclude_labels: index_flat = T.set_subtensor(index_flat[(T.eq(self.y_data_flat, label) > 0).nonzero()], numpy.int8(0)) self.i = (index_flat > 0).nonzero() self.j = ((numpy.int32(1) - index_flat) > 0).nonzero() self.loss = as_str(loss.encode("utf8")) self.attrs['loss'] = self.loss if softmax_smoothing != 1.0: self.attrs['softmax_smoothing'] = softmax_smoothing print("Logits before the softmax scaled with factor ", softmax_smoothing, file=log.v4) self.z *= numpy.float32(softmax_smoothing) if self.loss == 'priori': self.priori = self.shared(value=numpy.ones((self.attrs['n_out'],), dtype=theano.config.floatX), borrow=True) if input_output_similarity: # First a self-similarity of input and output, # and then add -similarity or distance between those to the constraints, # so that the input and output correlate on a frame-by-frame basis. # Here some other similarities/distances we could try: # https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.pdist.html # https://brenocon.com/blog/2012/03/cosine-similarity-pearson-correlation-and-ols-coefficients/ from returnn.theano.util import self_similarity_cosine self_similarity = self_similarity_cosine # maybe other data_layer = self.find_data_layer() assert data_layer assert data_layer.output.ndim == 3 n_time = data_layer.output.shape[0] n_batch = data_layer.output.shape[1] findex = T.cast(self.output_index(), "float32") findex_bc = findex.reshape((n_time * n_batch,)).dimshuffle(0, 'x') findex_sum = T.sum(findex) data = data_layer.output.reshape((n_time * n_batch, data_layer.output.shape[2])) * findex_bc assert self.z.ndim == 3 z = self.z.reshape((n_time * n_batch, self.z.shape[2])) * findex_bc data_self_sim = T.flatten(self_similarity(data)) z_self_sim = T.flatten(self_similarity(z)) assert data_self_sim.ndim == z_self_sim.ndim == 1 sim = T.dot(data_self_sim, z_self_sim) # maybe others make sense assert sim.ndim == 0 # sim is ~ proportional to T * T, so divide by T. sim *= numpy.float32(input_output_similarity_scale) / findex_sum self.constraints -= sim if sigmoid_outputs: self.set_attr("sigmoid_outputs", sigmoid_outputs) if exp_outputs: self.set_attr("exp_outputs", exp_outputs) if gauss_outputs: self.set_attr("gauss_outputs", gauss_outputs) if activation: self.set_attr("activation", activation) self.y_m = T.reshape(self.z, (self.z.shape[0] * self.z.shape[1], self.z.shape[2]), ndim=2) if self.loss == 'sse' or not self.attrs.get("apply_softmax", True): self.p_y_given_x = self.z elif self.loss == 'sse_sigmoid': self.p_y_given_x = T.nnet.sigmoid(self.z) elif exp_outputs: # or not exp_normalize: self.p_y_given_x = T.exp(self.z) elif sigmoid_outputs: self.p_y_given_x = T.nnet.sigmoid(self.z) elif gauss_outputs: self.p_y_given_x = T.exp(-T.sqr(self.z)) elif activation: from returnn.theano.activation_functions import strtoact_single_joined act_f = strtoact_single_joined(activation) self.p_y_given_x = act_f(self.z) elif batchwise_softmax: n_frames = self.z.shape[0] n_batches = self.z.shape[1] n_features = self.z.shape[2] y_m = T.switch(T.eq(self.index.reshape((n_frames, n_batches, 1)), 0), float('-inf'), self.z) time_major = y_m.dimshuffle(1, 0, 2).reshape((n_batches, n_frames * n_features)) softmax = T.nnet.softmax(time_major) self.p_y_given_x = softmax.reshape((n_batches, n_frames, n_features)).dimshuffle(1, 0, 2) else: # standard case self.p_y_given_x = T.reshape(T.nnet.softmax(self.y_m), self.z.shape) if self.loss == "priori": self.p_y_given_x /= self.priori self.p_y_given_x_flat = T.reshape(self.p_y_given_x, self.y_m.shape) self.y_pred = T.argmax(self.p_y_given_x_flat, axis=-1) self.output = self.p_y_given_x self.prior_scale = prior_scale if prior_scale: self.set_attr("prior_scale", prior_scale) if log_prior is not None: # We expect a filename to the priors, stored as txt, in +log space. assert isinstance(log_prior, str) self.set_attr("log_prior", log_prior) from returnn.util.basic import load_txt_vector assert os.path.exists(log_prior) log_prior = load_txt_vector(log_prior) assert len(log_prior) == self.attrs['n_out'], "dim missmatch: %i != %i" % (len(log_prior), self.attrs['n_out']) log_prior = numpy.array(log_prior, dtype="float32") self.log_prior = log_prior if compute_priors_via_baum_welch: self.set_attr("compute_priors_via_baum_welch", compute_priors_via_baum_welch) assert compute_priors if compute_priors: self.set_attr('compute_priors', compute_priors) if compute_priors_exp_average: self.set_attr('compute_priors_exp_average', compute_priors_exp_average) if compute_priors_accumulate_batches: self.set_attr("compute_priors_accumulate_batches", compute_priors_accumulate_batches) custom = T.mean(self.p_y_given_x_flat[(self.sources[0].index.flatten()>0).nonzero()], axis=0) custom_init = numpy.ones((self.attrs['n_out'],), 'float32') / numpy.float32(self.attrs['n_out']) if use_label_priors > 0: # use labels to compute priors in first epoch self.set_attr("use_label_priors", use_label_priors) custom_0 = T.mean(theano.tensor.extra_ops.to_one_hot(self.y_data_flat[self.i], self.attrs['n_out'], 'float32'), axis=0) custom = T.switch(T.le(self.network.epoch, use_label_priors), custom_0, custom) self.priors = self.add_param(theano.shared(custom_init, 'priors'), 'priors', custom_update=custom, custom_update_normalized=not compute_priors_exp_average, custom_update_exp_average=compute_priors_exp_average, custom_update_accumulate_batches=compute_priors_accumulate_batches) self.log_prior = T.log(T.maximum(self.priors, numpy.float32(1e-20))) if self.attrs.get("substract_prior_from_output", False): log_out = T.log(T.clip(self.output, numpy.float32(1.e-20), numpy.float(1.e20))) prior_scale = numpy.float32(self.attrs.get("prior_scale", 1)) self.output = T.exp(log_out - self.log_prior * prior_scale) self.p_y_given_x = self.output self.p_y_given_x_flat = T.reshape(self.p_y_given_x, self.y_m.shape) if self.attrs.get('compute_distortions', False): p = self.p_y_given_x_flat[self.i] momentum = p[:-1] * p[1:] momentum = T.sum(momentum, axis=-1) loop = T.mean(momentum) forward = numpy.float32(1) - loop self.distortions = { 'loop': self.add_param(theano.shared(numpy.ones((1,), 'float32') * numpy.float32(0.5), 'loop'), 'loop', custom_update=loop, custom_update_normalized=True), 'forward': self.add_param(theano.shared(numpy.ones((1,), 'float32') * numpy.float32(0.5), 'forward'), 'forward', custom_update=forward, custom_update_normalized=True) } self.cost_scale_val = T.constant(1) if scale_by_error and self.train_flag: rpcx = self.p_y_given_x_flat[T.arange(self.p_y_given_x_flat.shape[0]),self.y_data_flat] #rpcx -= rpcx.min() rpcx /= rpcx.max() #weight = T.constant(1) - rpcx #weight = (T.constant(1) - self.p_y_given_x_flat[T.arange(self.p_y_given_x_flat.shape[0]),self.y_data_flat]) #weight = weight.dimshuffle(0,'x').repeat(self.z.shape[2],axis=1).reshape(self.z.shape) #weight = T.cast(T.neq(T.argmax(self.p_y_given_x_flat, axis=1), self.y_data_flat), 'float32').dimshuffle(0,'x').repeat(self.z.shape[2],axis=1).reshape(self.z.shape) weight = T.cast(T.eq(T.argmax(self.p_y_given_x_flat, axis=1), self.y_data_flat), 'float32').dimshuffle(0,'x').repeat(self.z.shape[2], axis=1).reshape(self.z.shape) self.p_y_given_x = T.exp(weight * T.log(self.p_y_given_x)) #self.z = self.p_y_given_x self.p_y_given_x_flat = self.p_y_given_x.reshape((self.p_y_given_x.shape[0]*self.p_y_given_x.shape[1],self.p_y_given_x.shape[2])) self.y_m = T.reshape(self.p_y_given_x, (self.p_y_given_x.shape[0] * self.p_y_given_x.shape[1], self.p_y_given_x.shape[2]), ndim=2)
[ "def", "__init__", "(", "self", ",", "loss", ",", "y", ",", "dtype", "=", "None", ",", "reshape_target", "=", "False", ",", "copy_input", "=", "None", ",", "copy_output", "=", "None", ",", "time_limit", "=", "0", ",", "use_source_index", "=", "False", ...
https://github.com/rwth-i6/returnn/blob/f2d718a197a280b0d5f0fd91a7fcb8658560dddb/returnn/theano/layers/output.py#L26-L356
maas/maas
db2f89970c640758a51247c59bf1ec6f60cf4ab5
src/metadataserver/user_data/templates/snippets/maas_run_scripts.py
python
oauth_token
(string)
Helper to use as type for OAuth token commandline args.
Helper to use as type for OAuth token commandline args.
[ "Helper", "to", "use", "as", "type", "for", "OAuth", "token", "commandline", "args", "." ]
def oauth_token(string): """Helper to use as type for OAuth token commandline args.""" try: return Credentials.from_string(string) except InvalidCredentialsFormat as e: raise argparse.ArgumentTypeError(str(e))
[ "def", "oauth_token", "(", "string", ")", ":", "try", ":", "return", "Credentials", ".", "from_string", "(", "string", ")", "except", "InvalidCredentialsFormat", "as", "e", ":", "raise", "argparse", ".", "ArgumentTypeError", "(", "str", "(", "e", ")", ")" ]
https://github.com/maas/maas/blob/db2f89970c640758a51247c59bf1ec6f60cf4ab5/src/metadataserver/user_data/templates/snippets/maas_run_scripts.py#L189-L194
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/wilight/cover.py
python
WiLightCover.is_closed
(self)
return ( self._status["motor_state"] == WL_STOPPED and wilight_to_hass_position(self._status["position_current"]) == 0 )
Return if the cover is closed or not.
Return if the cover is closed or not.
[ "Return", "if", "the", "cover", "is", "closed", "or", "not", "." ]
def is_closed(self): """Return if the cover is closed or not.""" if "motor_state" not in self._status or "position_current" not in self._status: return None return ( self._status["motor_state"] == WL_STOPPED and wilight_to_hass_position(self._status["position_current"]) == 0 )
[ "def", "is_closed", "(", "self", ")", ":", "if", "\"motor_state\"", "not", "in", "self", ".", "_status", "or", "\"position_current\"", "not", "in", "self", ".", "_status", ":", "return", "None", "return", "(", "self", ".", "_status", "[", "\"motor_state\"", ...
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/wilight/cover.py#L80-L87
joxeankoret/pyew
8eb3e49a9bf57c0787fa79ecae0671129ef3f2e8
envi/archs/i386/emu.py
python
IntelEmulator._emu_setGpReg
(self, reg, val, tsize)
Automagically map all general purpose register accesses to their tsize equiv. Helps clean up a lot of code (and makes a nice place for AMD64 to hook ;) )
Automagically map all general purpose register accesses to their tsize equiv. Helps clean up a lot of code (and makes a nice place for AMD64 to hook ;) )
[ "Automagically", "map", "all", "general", "purpose", "register", "accesses", "to", "their", "tsize", "equiv", ".", "Helps", "clean", "up", "a", "lot", "of", "code", "(", "and", "makes", "a", "nice", "place", "for", "AMD64", "to", "hook", ";", ")", ")" ]
def _emu_setGpReg(self, reg, val, tsize): """ Automagically map all general purpose register accesses to their tsize equiv. Helps clean up a lot of code (and makes a nice place for AMD64 to hook ;) ) """ if tsize == 1: reg += 0x00080000 elif tsize == 2: reg += 0x00100000 self.setRegister(reg, value)
[ "def", "_emu_setGpReg", "(", "self", ",", "reg", ",", "val", ",", "tsize", ")", ":", "if", "tsize", "==", "1", ":", "reg", "+=", "0x00080000", "elif", "tsize", "==", "2", ":", "reg", "+=", "0x00100000", "self", ".", "setRegister", "(", "reg", ",", ...
https://github.com/joxeankoret/pyew/blob/8eb3e49a9bf57c0787fa79ecae0671129ef3f2e8/envi/archs/i386/emu.py#L985-L995
nltk/nltk
3f74ac55681667d7ef78b664557487145f51eb02
nltk/grammar.py
python
PCFG.__init__
(self, start, productions, calculate_leftcorners=True)
Create a new context-free grammar, from the given start state and set of ``ProbabilisticProductions``. :param start: The start symbol :type start: Nonterminal :param productions: The list of productions that defines the grammar :type productions: list(Production) :raise ValueError: if the set of productions with any left-hand-side do not have probabilities that sum to a value within EPSILON of 1. :param calculate_leftcorners: False if we don't want to calculate the leftcorner relation. In that case, some optimized chart parsers won't work. :type calculate_leftcorners: bool
Create a new context-free grammar, from the given start state and set of ``ProbabilisticProductions``.
[ "Create", "a", "new", "context", "-", "free", "grammar", "from", "the", "given", "start", "state", "and", "set", "of", "ProbabilisticProductions", "." ]
def __init__(self, start, productions, calculate_leftcorners=True): """ Create a new context-free grammar, from the given start state and set of ``ProbabilisticProductions``. :param start: The start symbol :type start: Nonterminal :param productions: The list of productions that defines the grammar :type productions: list(Production) :raise ValueError: if the set of productions with any left-hand-side do not have probabilities that sum to a value within EPSILON of 1. :param calculate_leftcorners: False if we don't want to calculate the leftcorner relation. In that case, some optimized chart parsers won't work. :type calculate_leftcorners: bool """ CFG.__init__(self, start, productions, calculate_leftcorners) # Make sure that the probabilities sum to one. probs = {} for production in productions: probs[production.lhs()] = probs.get(production.lhs(), 0) + production.prob() for (lhs, p) in probs.items(): if not ((1 - PCFG.EPSILON) < p < (1 + PCFG.EPSILON)): raise ValueError("Productions for %r do not sum to 1" % lhs)
[ "def", "__init__", "(", "self", ",", "start", ",", "productions", ",", "calculate_leftcorners", "=", "True", ")", ":", "CFG", ".", "__init__", "(", "self", ",", "start", ",", "productions", ",", "calculate_leftcorners", ")", "# Make sure that the probabilities sum...
https://github.com/nltk/nltk/blob/3f74ac55681667d7ef78b664557487145f51eb02/nltk/grammar.py#L1211-L1235
dronekit/dronekit-python
1d89e82807ce543bae5e36426641b717e187c589
dronekit/__init__.py
python
Vehicle.on_message
(self, name)
return decorator
Decorator for message listener callback functions. .. tip:: This is the most elegant way to define message listener callback functions. Use :py:func:`add_message_listener` only if you need to be able to :py:func:`remove the listener <remove_message_listener>` later. A decorated message listener function is called with three arguments every time the specified message is received: * ``self`` - the current vehicle. * ``name`` - the name of the message that was intercepted. * ``message`` - the actual message (a `pymavlink <http://www.qgroundcontrol.org/mavlink/pymavlink>`_ `class <https://www.samba.org/tridge/UAV/pymavlink/apidocs/classIndex.html>`_). For example, in the fragment below ``my_method`` will be called for every heartbeat message: .. code:: python @vehicle.on_message('HEARTBEAT') def my_method(self, name, msg): pass See :ref:`mavlink_messages` for more information. :param String name: The name of the message to be intercepted by the decorated listener function (or '*' to get all messages).
Decorator for message listener callback functions.
[ "Decorator", "for", "message", "listener", "callback", "functions", "." ]
def on_message(self, name): """ Decorator for message listener callback functions. .. tip:: This is the most elegant way to define message listener callback functions. Use :py:func:`add_message_listener` only if you need to be able to :py:func:`remove the listener <remove_message_listener>` later. A decorated message listener function is called with three arguments every time the specified message is received: * ``self`` - the current vehicle. * ``name`` - the name of the message that was intercepted. * ``message`` - the actual message (a `pymavlink <http://www.qgroundcontrol.org/mavlink/pymavlink>`_ `class <https://www.samba.org/tridge/UAV/pymavlink/apidocs/classIndex.html>`_). For example, in the fragment below ``my_method`` will be called for every heartbeat message: .. code:: python @vehicle.on_message('HEARTBEAT') def my_method(self, name, msg): pass See :ref:`mavlink_messages` for more information. :param String name: The name of the message to be intercepted by the decorated listener function (or '*' to get all messages). """ def decorator(fn): if isinstance(name, list): for n in name: self.add_message_listener(n, fn) else: self.add_message_listener(name, fn) return decorator
[ "def", "on_message", "(", "self", ",", "name", ")", ":", "def", "decorator", "(", "fn", ")", ":", "if", "isinstance", "(", "name", ",", "list", ")", ":", "for", "n", "in", "name", ":", "self", ".", "add_message_listener", "(", "n", ",", "fn", ")", ...
https://github.com/dronekit/dronekit-python/blob/1d89e82807ce543bae5e36426641b717e187c589/dronekit/__init__.py#L1469-L1507
crits/crits_services
c7abf91f1865d913cffad4b966599da204f8ae43
pdfinfo_service/pdfparser.py
python
cPDFParseDictionary.Retrieve
(self)
return self.parsed
[]
def Retrieve(self): return self.parsed
[ "def", "Retrieve", "(", "self", ")", ":", "return", "self", ".", "parsed" ]
https://github.com/crits/crits_services/blob/c7abf91f1865d913cffad4b966599da204f8ae43/pdfinfo_service/pdfparser.py#L655-L656
IlyaGusev/rupo
83a5fac0dddd480a401181e5465f0e3c94ad2dcc
rupo/generate/generator.py
python
Generator.generate_poem
(self, metre_schema: str="+-", rhyme_pattern: str="aabb", n_syllables: int=8, letters_to_rhymes: dict=None, beam_width: int=None, sampling_k: int=None, rhyme_score_border: int=4, temperature: float=1.0, seed: int=1337, last_text: str="")
return poem
[]
def generate_poem(self, metre_schema: str="+-", rhyme_pattern: str="aabb", n_syllables: int=8, letters_to_rhymes: dict=None, beam_width: int=None, sampling_k: int=None, rhyme_score_border: int=4, temperature: float=1.0, seed: int=1337, last_text: str="") -> Optional[str]: assert beam_width or sampling_k, "Set sampling_k or beam_width" self.model.set_seed(seed) poem_transform = PoemTransform( stress_vocabulary=self.stress_vocabulary, metre_pattern=metre_schema, rhyme_pattern=rhyme_pattern, n_syllables=n_syllables, eos_index=self.eos_index, letters_to_rhymes=letters_to_rhymes, score_border=rhyme_score_border ) if last_text: words = last_text.lower().split(" ") last_text = " ".join(words[::-1]) filled_syllables = 0 for word in last_text.split(): index = self.token_vocabulary.get_token_index(word) word = self.stress_vocabulary.get_word(index) syllables_count = len(word.syllables) filled_syllables += syllables_count poem_transform.stress_position -= filled_syllables poem_transform.rhyme_position -= 1 last_index = self.token_vocabulary.get_token_index(words[-1]) last_word = self.stress_vocabulary.get_word(last_index) poem_transform.letters_to_rhymes[rhyme_pattern[-1]].add(last_word) self.model.transforms.append(poem_transform) try: if beam_width: poem = self.model.beam_decoding(last_text, beam_width=beam_width, temperature=temperature) elif sampling_k: poem = self.model.sample_decoding(last_text, k=sampling_k, temperature=temperature) else: assert False except Exception as e: self.model.transforms.pop() raise e self.model.transforms.pop() words = poem.split(" ") words = words[::-1] result_words = [] current_n_syllables = 0 for word in words: result_words.append(word) index = self.token_vocabulary.get_token_index(word) word = self.stress_vocabulary.get_word(index) syllables_count = len(word.syllables) current_n_syllables += syllables_count if n_syllables == current_n_syllables: current_n_syllables = 0 result_words.append("\n") poem = " ".join(result_words) poem = "\n".join([line.strip() for line in poem.split("\n")]) return poem
[ "def", "generate_poem", "(", "self", ",", "metre_schema", ":", "str", "=", "\"+-\"", ",", "rhyme_pattern", ":", "str", "=", "\"aabb\"", ",", "n_syllables", ":", "int", "=", "8", ",", "letters_to_rhymes", ":", "dict", "=", "None", ",", "beam_width", ":", ...
https://github.com/IlyaGusev/rupo/blob/83a5fac0dddd480a401181e5465f0e3c94ad2dcc/rupo/generate/generator.py#L28-L97
yuxiaokui/Intranet-Penetration
f57678a204840c83cbf3308e3470ae56c5ff514b
proxy/XX-Net/code/default/python27/1.0/lib/noarch/sortedcontainers/sortedlistwithkey.py
python
SortedListWithKey._expand
(self, pos)
Splits sublists that are more than double the load level. Updates the index when the sublist length is less than double the load level. This requires incrementing the nodes in a traversal from the leaf node to the root. For an example traversal see self._loc.
Splits sublists that are more than double the load level.
[ "Splits", "sublists", "that", "are", "more", "than", "double", "the", "load", "level", "." ]
def _expand(self, pos): """ Splits sublists that are more than double the load level. Updates the index when the sublist length is less than double the load level. This requires incrementing the nodes in a traversal from the leaf node to the root. For an example traversal see self._loc. """ _lists, _keys, _index = self._lists, self._keys, self._index if len(_keys[pos]) > self._twice: _maxes, _load = self._maxes, self._load half = _keys[pos][_load:] half_list = _lists[pos][_load:] del _keys[pos][_load:] del _lists[pos][_load:] _maxes[pos] = _keys[pos][-1] _maxes.insert(pos + 1, half[-1]) _keys.insert(pos + 1, half) _lists.insert(pos + 1, half_list) del _index[:] else: if len(_index) > 0: child = self._offset + pos while child > 0: _index[child] += 1 child = (child - 1) >> 1 _index[0] += 1
[ "def", "_expand", "(", "self", ",", "pos", ")", ":", "_lists", ",", "_keys", ",", "_index", "=", "self", ".", "_lists", ",", "self", ".", "_keys", ",", "self", ".", "_index", "if", "len", "(", "_keys", "[", "pos", "]", ")", ">", "self", ".", "_...
https://github.com/yuxiaokui/Intranet-Penetration/blob/f57678a204840c83cbf3308e3470ae56c5ff514b/proxy/XX-Net/code/default/python27/1.0/lib/noarch/sortedcontainers/sortedlistwithkey.py#L88-L118
biopython/biopython
2dd97e71762af7b046d7f7f8a4f1e38db6b06c86
Bio/Entrez/__init__.py
python
read
(handle, validate=True, escape=False)
return record
Parse an XML file from the NCBI Entrez Utilities into python objects. This function parses an XML file created by NCBI's Entrez Utilities, returning a multilevel data structure of Python lists and dictionaries. Most XML files returned by NCBI's Entrez Utilities can be parsed by this function, provided its DTD is available. Biopython includes the DTDs for most commonly used Entrez Utilities. The handle must be in binary mode. This allows the parser to detect the encoding from the XML file, and to use it to convert all text in the XML to the correct Unicode string. The functions in Bio.Entrez to access NCBI Entrez will automatically return XML data in binary mode. For files, please use mode "rb" when opening the file, as in >>> from Bio import Entrez >>> handle = open("Entrez/esearch1.xml", "rb") # opened in binary mode >>> record = Entrez.read(handle) >>> print(record['QueryTranslation']) biopython[All Fields] >>> handle.close() If validate is True (default), the parser will validate the XML file against the DTD, and raise an error if the XML file contains tags that are not represented in the DTD. If validate is False, the parser will simply skip such tags. If escape is True, all characters that are not valid HTML are replaced by HTML escape characters to guarantee that the returned strings are valid HTML fragments. For example, a less-than sign (<) is replaced by &lt;. If escape is False (default), the string is returned as is. Whereas the data structure seems to consist of generic Python lists, dictionaries, strings, and so on, each of these is actually a class derived from the base type. This allows us to store the attributes (if any) of each element in a dictionary my_element.attributes, and the tag name in my_element.tag.
Parse an XML file from the NCBI Entrez Utilities into python objects.
[ "Parse", "an", "XML", "file", "from", "the", "NCBI", "Entrez", "Utilities", "into", "python", "objects", "." ]
def read(handle, validate=True, escape=False): """Parse an XML file from the NCBI Entrez Utilities into python objects. This function parses an XML file created by NCBI's Entrez Utilities, returning a multilevel data structure of Python lists and dictionaries. Most XML files returned by NCBI's Entrez Utilities can be parsed by this function, provided its DTD is available. Biopython includes the DTDs for most commonly used Entrez Utilities. The handle must be in binary mode. This allows the parser to detect the encoding from the XML file, and to use it to convert all text in the XML to the correct Unicode string. The functions in Bio.Entrez to access NCBI Entrez will automatically return XML data in binary mode. For files, please use mode "rb" when opening the file, as in >>> from Bio import Entrez >>> handle = open("Entrez/esearch1.xml", "rb") # opened in binary mode >>> record = Entrez.read(handle) >>> print(record['QueryTranslation']) biopython[All Fields] >>> handle.close() If validate is True (default), the parser will validate the XML file against the DTD, and raise an error if the XML file contains tags that are not represented in the DTD. If validate is False, the parser will simply skip such tags. If escape is True, all characters that are not valid HTML are replaced by HTML escape characters to guarantee that the returned strings are valid HTML fragments. For example, a less-than sign (<) is replaced by &lt;. If escape is False (default), the string is returned as is. Whereas the data structure seems to consist of generic Python lists, dictionaries, strings, and so on, each of these is actually a class derived from the base type. This allows us to store the attributes (if any) of each element in a dictionary my_element.attributes, and the tag name in my_element.tag. """ from .Parser import DataHandler handler = DataHandler(validate, escape) record = handler.read(handle) return record
[ "def", "read", "(", "handle", ",", "validate", "=", "True", ",", "escape", "=", "False", ")", ":", "from", ".", "Parser", "import", "DataHandler", "handler", "=", "DataHandler", "(", "validate", ",", "escape", ")", "record", "=", "handler", ".", "read", ...
https://github.com/biopython/biopython/blob/2dd97e71762af7b046d7f7f8a4f1e38db6b06c86/Bio/Entrez/__init__.py#L462-L504
EmuKit/emukit
cdcb0d070d7f1c5585260266160722b636786859
emukit/core/initial_designs/random_design.py
python
RandomDesign.__init__
(self, parameter_space: ParameterSpace)
:param parameter_space: The parameter space to generate design for.
:param parameter_space: The parameter space to generate design for.
[ ":", "param", "parameter_space", ":", "The", "parameter", "space", "to", "generate", "design", "for", "." ]
def __init__(self, parameter_space: ParameterSpace) -> None: """ :param parameter_space: The parameter space to generate design for. """ super(RandomDesign, self).__init__(parameter_space)
[ "def", "__init__", "(", "self", ",", "parameter_space", ":", "ParameterSpace", ")", "->", "None", ":", "super", "(", "RandomDesign", ",", "self", ")", ".", "__init__", "(", "parameter_space", ")" ]
https://github.com/EmuKit/emukit/blob/cdcb0d070d7f1c5585260266160722b636786859/emukit/core/initial_designs/random_design.py#L15-L19
taomujian/linbing
fe772a58f41e3b046b51a866bdb7e4655abaf51a
python/app/thirdparty/dirsearch/thirdparty/requests/models.py
python
Response.iter_content
(self, chunk_size=1, decode_unicode=False)
return chunks
Iterates over the response data. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. The chunk size is the number of bytes it should read into memory. This is not necessarily the length of each item returned as decoding can take place. chunk_size must be of type int or None. A value of None will function differently depending on the value of `stream`. stream=True will read data as it arrives in whatever size the chunks are received. If stream=False, data is returned as a single chunk. If decode_unicode is True, content will be decoded using the best available encoding based on the response.
Iterates over the response data. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. The chunk size is the number of bytes it should read into memory. This is not necessarily the length of each item returned as decoding can take place.
[ "Iterates", "over", "the", "response", "data", ".", "When", "stream", "=", "True", "is", "set", "on", "the", "request", "this", "avoids", "reading", "the", "content", "at", "once", "into", "memory", "for", "large", "responses", ".", "The", "chunk", "size",...
def iter_content(self, chunk_size=1, decode_unicode=False): """Iterates over the response data. When stream=True is set on the request, this avoids reading the content at once into memory for large responses. The chunk size is the number of bytes it should read into memory. This is not necessarily the length of each item returned as decoding can take place. chunk_size must be of type int or None. A value of None will function differently depending on the value of `stream`. stream=True will read data as it arrives in whatever size the chunks are received. If stream=False, data is returned as a single chunk. If decode_unicode is True, content will be decoded using the best available encoding based on the response. """ def generate(): # Special case for urllib3. if hasattr(self.raw, 'stream'): try: for chunk in self.raw.stream(chunk_size, decode_content=True): yield chunk except ProtocolError as e: raise ChunkedEncodingError(e) except DecodeError as e: raise ContentDecodingError(e) except ReadTimeoutError as e: raise ConnectionError(e) else: # Standard file-like object. while True: chunk = self.raw.read(chunk_size) if not chunk: break yield chunk self._content_consumed = True if self._content_consumed and isinstance(self._content, bool): raise StreamConsumedError() elif chunk_size is not None and not isinstance(chunk_size, int): raise TypeError("chunk_size must be an int, it is instead a %s." % type(chunk_size)) # simulate reading small chunks of the content reused_chunks = iter_slices(self._content, chunk_size) stream_chunks = generate() chunks = reused_chunks if self._content_consumed else stream_chunks if decode_unicode: chunks = stream_decode_response_unicode(chunks, self) return chunks
[ "def", "iter_content", "(", "self", ",", "chunk_size", "=", "1", ",", "decode_unicode", "=", "False", ")", ":", "def", "generate", "(", ")", ":", "# Special case for urllib3.", "if", "hasattr", "(", "self", ".", "raw", ",", "'stream'", ")", ":", "try", "...
https://github.com/taomujian/linbing/blob/fe772a58f41e3b046b51a866bdb7e4655abaf51a/python/app/thirdparty/dirsearch/thirdparty/requests/models.py#L732-L785
agronholm/pythonfutures
acba785c8a5c331edce05dfa760540b8ea8a81f1
concurrent/futures/_base.py
python
Executor.shutdown
(self, wait=True)
Clean-up the resources associated with the Executor. It is safe to call this method several times. Otherwise, no other methods can be called after this one. Args: wait: If True then shutdown will not return until all running futures have finished executing and the resources used by the executor have been reclaimed.
Clean-up the resources associated with the Executor.
[ "Clean", "-", "up", "the", "resources", "associated", "with", "the", "Executor", "." ]
def shutdown(self, wait=True): """Clean-up the resources associated with the Executor. It is safe to call this method several times. Otherwise, no other methods can be called after this one. Args: wait: If True then shutdown will not return until all running futures have finished executing and the resources used by the executor have been reclaimed. """ pass
[ "def", "shutdown", "(", "self", ",", "wait", "=", "True", ")", ":", "pass" ]
https://github.com/agronholm/pythonfutures/blob/acba785c8a5c331edce05dfa760540b8ea8a81f1/concurrent/futures/_base.py#L649-L660
blampe/IbPy
cba912d2ecc669b0bf2980357ea7942e49c0825e
ib/ext/EWrapperMsgGenerator.py
python
EWrapperMsgGenerator.updateMktDepth
(cls, tickerId, position, operation, side, price, size)
return "updateMktDepth: " + str(tickerId) + " " + str(position) + " " + str(operation) + " " + str(side) + " " + str(price) + " " + str(size)
generated source for method updateMktDepth
generated source for method updateMktDepth
[ "generated", "source", "for", "method", "updateMktDepth" ]
def updateMktDepth(cls, tickerId, position, operation, side, price, size): """ generated source for method updateMktDepth """ return "updateMktDepth: " + str(tickerId) + " " + str(position) + " " + str(operation) + " " + str(side) + " " + str(price) + " " + str(size)
[ "def", "updateMktDepth", "(", "cls", ",", "tickerId", ",", "position", ",", "operation", ",", "side", ",", "price", ",", "size", ")", ":", "return", "\"updateMktDepth: \"", "+", "str", "(", "tickerId", ")", "+", "\" \"", "+", "str", "(", "position", ")",...
https://github.com/blampe/IbPy/blob/cba912d2ecc669b0bf2980357ea7942e49c0825e/ib/ext/EWrapperMsgGenerator.py#L404-L406
tendenci/tendenci
0f2c348cc0e7d41bc56f50b00ce05544b083bf1d
tendenci/apps/forms_builder/forms/utils.py
python
generate_email_subject
(form, form_entry)
return subject
Generates email subject from subject template
Generates email subject from subject template
[ "Generates", "email", "subject", "from", "subject", "template" ]
def generate_email_subject(form, form_entry): """ Generates email subject from subject template """ if form.subject_template: subject = form.subject_template field_entries = form_entry.entry_fields() for field_entry in field_entries: label = field_entry.field.label value = field_entry.value # removes parens and asterisks so they don't break the re compile. label = re.sub(r'[\*()]', '', label) if not value: value = '' p = re.compile(r'(-\s+)?\[%s\]' % label, re.IGNORECASE) else: p = re.compile(r'\[%s\]' % label, re.IGNORECASE) subject = p.sub(value.replace('\\', ''), subject) # title p = re.compile(r'\[title\]', re.IGNORECASE) subject = p.sub(form.title, subject) # replace those brackets with blank string p = re.compile(r'(-\s+)?\[[\d\D\s\S\w\W]*?\]') subject = p.sub('', subject) else: subject = "%s:" % (form.title) if form_entry.get_first_name(): subject = "%s %s" % (subject, form_entry.get_first_name()) if form_entry.get_last_name(): subject = "%s %s" % (subject, form_entry.get_last_name()) if form_entry.get_full_name(): subject = "%s %s" % (subject, form_entry.get_full_name()) if form_entry.get_phone_number(): subject = "%s - %s" % (subject, form_entry.get_phone_number()) if form_entry.get_email_address(): subject = "%s - %s" % (subject, form_entry.get_email_address()) return subject
[ "def", "generate_email_subject", "(", "form", ",", "form_entry", ")", ":", "if", "form", ".", "subject_template", ":", "subject", "=", "form", ".", "subject_template", "field_entries", "=", "form_entry", ".", "entry_fields", "(", ")", "for", "field_entry", "in",...
https://github.com/tendenci/tendenci/blob/0f2c348cc0e7d41bc56f50b00ce05544b083bf1d/tendenci/apps/forms_builder/forms/utils.py#L53-L93
usb-tools/ViewSB
0318dc7b3d7da290a841b1681e62a0654c8c82e6
viewsb/decoders/filters.py
python
USBPacketFilter.consume_packet
(self, packet)
Trivial implementation of consume_packet that silently discards all packets consumed.
Trivial implementation of consume_packet that silently discards all packets consumed.
[ "Trivial", "implementation", "of", "consume_packet", "that", "silently", "discards", "all", "packets", "consumed", "." ]
def consume_packet(self, packet): """ Trivial implementation of consume_packet that silently discards all packets consumed. """ pass
[ "def", "consume_packet", "(", "self", ",", "packet", ")", ":", "pass" ]
https://github.com/usb-tools/ViewSB/blob/0318dc7b3d7da290a841b1681e62a0654c8c82e6/viewsb/decoders/filters.py#L32-L34
merenlab/anvio
9b792e2cedc49ecb7c0bed768261595a0d87c012
anvio/dbops.py
python
ContigsDatabase.compress_nt_position_info
(self, contig_length, genes_in_contig, genes_in_contigs_dict)
return nt_position_info_list
Compress info regarding each nucleotide position in a given contig into a small int Every nucleotide position is represented by four bits depending on whether they occur in a coding open reading frame, and which base they correspond to in a codon. 0000 |||| ||| \ ||| Third codon pos? || \ || Second codon pos? | \ | First codon pos? \ Whether the position is in an noncoding gene (call_type = NONCODING or UNKNOWN) 8: int('1000', 2); nt position is in an noncoding gene 4: int('0100', 2); nt position is in a coding gene, and is at the 1st position in the codon 2: int('0010', 2); nt position is in a coding gene, and is at the 2nd position in the codon 1: int('0001', 2); nt position is in a coding gene, and is at the 3rd position in the codon 0: int('0000', 2); nt position not in a gene Notes ===== - This code could be much faster by populating and returning a numpy array rather than a list - Upon testing (2020/05/19), this function is about 8% of runtime for anvi-gen-contigs-database (ignoring ORF prediction) so vectorization of this function is probably not worth it at this point in time.
Compress info regarding each nucleotide position in a given contig into a small int
[ "Compress", "info", "regarding", "each", "nucleotide", "position", "in", "a", "given", "contig", "into", "a", "small", "int" ]
def compress_nt_position_info(self, contig_length, genes_in_contig, genes_in_contigs_dict): """Compress info regarding each nucleotide position in a given contig into a small int Every nucleotide position is represented by four bits depending on whether they occur in a coding open reading frame, and which base they correspond to in a codon. 0000 |||| ||| \ ||| Third codon pos? || \ || Second codon pos? | \ | First codon pos? \ Whether the position is in an noncoding gene (call_type = NONCODING or UNKNOWN) 8: int('1000', 2); nt position is in an noncoding gene 4: int('0100', 2); nt position is in a coding gene, and is at the 1st position in the codon 2: int('0010', 2); nt position is in a coding gene, and is at the 2nd position in the codon 1: int('0001', 2); nt position is in a coding gene, and is at the 3rd position in the codon 0: int('0000', 2); nt position not in a gene Notes ===== - This code could be much faster by populating and returning a numpy array rather than a list - Upon testing (2020/05/19), this function is about 8% of runtime for anvi-gen-contigs-database (ignoring ORF prediction) so vectorization of this function is probably not worth it at this point in time. """ # first we create a list of zeros for each position of the contig nt_position_info_list = [0] * contig_length coding = constants.gene_call_types['CODING'] for gene_unique_id, start, stop in genes_in_contig: gene_call = genes_in_contigs_dict[gene_unique_id] if gene_call['call_type'] != coding: for nt_position in range(start, stop): nt_position_info_list[nt_position] = 8 continue # if the gene stop is identical to the contig length, # just move on: if stop == contig_length: continue if gene_call['direction'] == 'f': for nt_position in range(start, stop, 3): nt_position_info_list[nt_position] = 4 nt_position_info_list[nt_position + 1] = 2 nt_position_info_list[nt_position + 2] = 1 elif gene_call['direction'] == 'r': for nt_position in range(stop - 1, start - 1, -3): nt_position_info_list[nt_position] = 4 nt_position_info_list[nt_position - 1] = 2 nt_position_info_list[nt_position - 2] = 1 return nt_position_info_list
[ "def", "compress_nt_position_info", "(", "self", ",", "contig_length", ",", "genes_in_contig", ",", "genes_in_contigs_dict", ")", ":", "# first we create a list of zeros for each position of the contig", "nt_position_info_list", "=", "[", "0", "]", "*", "contig_length", "codi...
https://github.com/merenlab/anvio/blob/9b792e2cedc49ecb7c0bed768261595a0d87c012/anvio/dbops.py#L4457-L4518
JordyZomer/autoSubTakeover
3825a35a34043d71843cd1ced8fa468198ae7587
versioneer.py
python
git_versions_from_keywords
(keywords, tag_prefix, verbose)
return { "version": "0+unknown", "full-revisionid": keywords["full"].strip(), "dirty": False, "error": "no suitable tags", "date": None, }
Get version information from git keywords.
Get version information from git keywords.
[ "Get", "version", "information", "from", "git", "keywords", "." ]
def git_versions_from_keywords(keywords, tag_prefix, verbose): """Get version information from git keywords.""" if not keywords: raise NotThisMethod("no keywords at all, weird") date = keywords.get("date") if date is not None: # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant # datestamp. However we prefer "%ci" (which expands to an "ISO-8601 # -like" string, which we must then edit to make compliant), because # it's been around since git-1.5.3, and it's too difficult to # discover which version we're using, or to work around using an # older one. date = date.strip().replace(" ", "T", 1).replace(" ", "", 1) refnames = keywords["refnames"].strip() if refnames.startswith("$Format"): if verbose: print("keywords are unexpanded, not using") raise NotThisMethod("unexpanded keywords, not a git-archive tarball") refs = set([r.strip() for r in refnames.strip("()").split(",")]) # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of # just "foo-1.0". If we see a "tag: " prefix, prefer those. TAG = "tag: " tags = set([r[len(TAG) :] for r in refs if r.startswith(TAG)]) if not tags: # Either we're using git < 1.8.3, or there really are no tags. We use # a heuristic: assume all version tags have a digit. The old git %d # expansion behaves like git log --decorate=short and strips out the # refs/heads/ and refs/tags/ prefixes that would let us distinguish # between branches and tags. By ignoring refnames without digits, we # filter out many common branch names like "release" and # "stabilization", as well as "HEAD" and "master". tags = set([r for r in refs if re.search(r"\d", r)]) if verbose: print("discarding '%s', no digits" % ",".join(refs - tags)) if verbose: print("likely tags: %s" % ",".join(sorted(tags))) for ref in sorted(tags): # sorting will prefer e.g. "2.0" over "2.0rc1" if ref.startswith(tag_prefix): r = ref[len(tag_prefix) :] if verbose: print("picking %s" % r) return { "version": r, "full-revisionid": keywords["full"].strip(), "dirty": False, "error": None, "date": date, } # no suitable tags, so version is "0+unknown", but full hex is still there if verbose: print("no suitable tags, using unknown + full revision id") return { "version": "0+unknown", "full-revisionid": keywords["full"].strip(), "dirty": False, "error": "no suitable tags", "date": None, }
[ "def", "git_versions_from_keywords", "(", "keywords", ",", "tag_prefix", ",", "verbose", ")", ":", "if", "not", "keywords", ":", "raise", "NotThisMethod", "(", "\"no keywords at all, weird\"", ")", "date", "=", "keywords", ".", "get", "(", "\"date\"", ")", "if",...
https://github.com/JordyZomer/autoSubTakeover/blob/3825a35a34043d71843cd1ced8fa468198ae7587/versioneer.py#L989-L1047
ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework
cb692f527e4e819b6c228187c5702d990a180043
external/Scripting Engine/Xenotix Python Scripting Engine/bin/x86/Debug/Lib/imaplib.py
python
IMAP4.setacl
(self, mailbox, who, what)
return self._simple_command('SETACL', mailbox, who, what)
Set a mailbox acl. (typ, [data]) = <instance>.setacl(mailbox, who, what)
Set a mailbox acl.
[ "Set", "a", "mailbox", "acl", "." ]
def setacl(self, mailbox, who, what): """Set a mailbox acl. (typ, [data]) = <instance>.setacl(mailbox, who, what) """ return self._simple_command('SETACL', mailbox, who, what)
[ "def", "setacl", "(", "self", ",", "mailbox", ",", "who", ",", "what", ")", ":", "return", "self", ".", "_simple_command", "(", "'SETACL'", ",", "mailbox", ",", "who", ",", "what", ")" ]
https://github.com/ajinabraham/OWASP-Xenotix-XSS-Exploit-Framework/blob/cb692f527e4e819b6c228187c5702d990a180043/external/Scripting Engine/Xenotix Python Scripting Engine/bin/x86/Debug/Lib/imaplib.py#L663-L668
JetBrains/colorSchemeTool
5536207cf92f66509318e8fc51dacc2b5a80cac7
colorSchemeTool.py
python
find_by_scope
(settings, scope)
return ss_less_specific if (ss_less_specific is not None) else less_specific
[]
def find_by_scope(settings, scope): # compound scope less_specific = None less_specific_weight = 0 less_specific_selector_size = 0 # simple scope (without whitespaces and '-') ss_less_specific = None ss_less_specific_weight = 0 for setting in settings: scope_of_setting = setting.get('scope', None) if scope_of_setting is None: if scope is None: return setting else: if not isinstance(scope_of_setting, list): scopes_of_setting = scope_of_setting.split(",") else: scopes_of_setting = scope_of_setting for aScope in scopes_of_setting: aScope = aScope.strip() # ignore excludes in scopes selectors, # more accurate parsing/matching required! chain_without_excludes = aScope.split(' -')[0] aScope_selectors = chain_without_excludes.split(' ') # We need: # 1. "Match the element deepest down in the scope e.g. string wins over source.php when the scope is source.php string.quoted." # it is very simple implementation of above rule matchingScope = aScope_selectors[-1] if matchingScope is None: continue # Consider scope size as scope size until first not excluded element aScopeSelectorSize = 0 for i in range(0, len(aScope_selectors) - 1): aScopeSelectorSize = len(aScope_selectors[i].strip()) isSimpleScope = (aScopeSelectorSize == 0) if matchingScope == scope: if isSimpleScope: return setting less_specific = setting less_specific_weight = len(matchingScope) less_specific_selector_size = aScopeSelectorSize if scope is not None and scope.startswith(matchingScope): # We need: # 2. "Match most of the deepest element e.g. string.quoted wins over string." # so let's consider matched symbols count as weight new_match_weight = len(matchingScope) weight = ss_less_specific_weight if isSimpleScope else less_specific_weight if new_match_weight > weight: if isSimpleScope: ss_less_specific = setting ss_less_specific_weight = new_match_weight else: less_specific = setting less_specific_weight = new_match_weight less_specific_selector_size = aScopeSelectorSize else: # if matched part is equal and scope isn't simple - let's choose the shortest scope # in general case should work better, because some where particular complicated # scope won't override similar but more general scope if not isSimpleScope and (new_match_weight == weight): if less_specific_selector_size > aScopeSelectorSize: less_specific = setting less_specific_weight = new_match_weight less_specific_selector_size = aScopeSelectorSize return ss_less_specific if (ss_less_specific is not None) else less_specific
[ "def", "find_by_scope", "(", "settings", ",", "scope", ")", ":", "# compound scope", "less_specific", "=", "None", "less_specific_weight", "=", "0", "less_specific_selector_size", "=", "0", "# simple scope (without whitespaces and '-')", "ss_less_specific", "=", "None", "...
https://github.com/JetBrains/colorSchemeTool/blob/5536207cf92f66509318e8fc51dacc2b5a80cac7/colorSchemeTool.py#L701-L770
bruderstein/PythonScript
df9f7071ddf3a079e3a301b9b53a6dc78cf1208f
PythonLib/tcl/tkinter/__init__.py
python
Wm.wm_aspect
(self, minNumer=None, minDenom=None, maxNumer=None, maxDenom=None)
return self._getints( self.tk.call('wm', 'aspect', self._w, minNumer, minDenom, maxNumer, maxDenom))
Instruct the window manager to set the aspect ratio (width/height) of this widget to be between MINNUMER/MINDENOM and MAXNUMER/MAXDENOM. Return a tuple of the actual values if no argument is given.
Instruct the window manager to set the aspect ratio (width/height) of this widget to be between MINNUMER/MINDENOM and MAXNUMER/MAXDENOM. Return a tuple of the actual values if no argument is given.
[ "Instruct", "the", "window", "manager", "to", "set", "the", "aspect", "ratio", "(", "width", "/", "height", ")", "of", "this", "widget", "to", "be", "between", "MINNUMER", "/", "MINDENOM", "and", "MAXNUMER", "/", "MAXDENOM", ".", "Return", "a", "tuple", ...
def wm_aspect(self, minNumer=None, minDenom=None, maxNumer=None, maxDenom=None): """Instruct the window manager to set the aspect ratio (width/height) of this widget to be between MINNUMER/MINDENOM and MAXNUMER/MAXDENOM. Return a tuple of the actual values if no argument is given.""" return self._getints( self.tk.call('wm', 'aspect', self._w, minNumer, minDenom, maxNumer, maxDenom))
[ "def", "wm_aspect", "(", "self", ",", "minNumer", "=", "None", ",", "minDenom", "=", "None", ",", "maxNumer", "=", "None", ",", "maxDenom", "=", "None", ")", ":", "return", "self", ".", "_getints", "(", "self", ".", "tk", ".", "call", "(", "'wm'", ...
https://github.com/bruderstein/PythonScript/blob/df9f7071ddf3a079e3a301b9b53a6dc78cf1208f/PythonLib/tcl/tkinter/__init__.py#L1973-L1982
seppius-xbmc-repo/ru
d0879d56ec8243b2c7af44fda5cf3d1ff77fd2e2
plugin.video.online.anidub.com/resources/lib/BeautifulSoup.py
python
PageElement.extract
(self)
return self
Destructively rips this element out of the tree.
Destructively rips this element out of the tree.
[ "Destructively", "rips", "this", "element", "out", "of", "the", "tree", "." ]
def extract(self): """Destructively rips this element out of the tree.""" if self.parent: try: del self.parent.contents[self.parent.index(self)] except ValueError: pass #Find the two elements that would be next to each other if #this element (and any children) hadn't been parsed. Connect #the two. lastChild = self._lastRecursiveChild() nextElement = lastChild.next if self.previous: self.previous.next = nextElement if nextElement: nextElement.previous = self.previous self.previous = None lastChild.next = None self.parent = None if self.previousSibling: self.previousSibling.nextSibling = self.nextSibling if self.nextSibling: self.nextSibling.previousSibling = self.previousSibling self.previousSibling = self.nextSibling = None return self
[ "def", "extract", "(", "self", ")", ":", "if", "self", ".", "parent", ":", "try", ":", "del", "self", ".", "parent", ".", "contents", "[", "self", ".", "parent", ".", "index", "(", "self", ")", "]", "except", "ValueError", ":", "pass", "#Find the two...
https://github.com/seppius-xbmc-repo/ru/blob/d0879d56ec8243b2c7af44fda5cf3d1ff77fd2e2/plugin.video.online.anidub.com/resources/lib/BeautifulSoup.py#L153-L180
JJBOY/BMN-Boundary-Matching-Network
a92c1d79c19d88b1d57b5abfae5a0be33f3002eb
post_processing.py
python
BMN_post_processing
(opt)
[]
def BMN_post_processing(opt): video_dict = getDatasetDict(opt) video_list = list(video_dict.keys()) # [:100] global result_dict result_dict = mp.Manager().dict() num_videos = len(video_list) num_videos_per_thread = num_videos // opt["post_process_thread"] processes = [] for tid in range(opt["post_process_thread"] - 1): tmp_video_list = video_list[tid * num_videos_per_thread:(tid + 1) * num_videos_per_thread] p = mp.Process(target=video_post_process, args=(opt, tmp_video_list, video_dict)) p.start() processes.append(p) tmp_video_list = video_list[(opt["post_process_thread"] - 1) * num_videos_per_thread:] p = mp.Process(target=video_post_process, args=(opt, tmp_video_list, video_dict)) p.start() processes.append(p) for p in processes: p.join() result_dict = dict(result_dict) output_dict = {"version": "VERSION 1.3", "results": result_dict, "external_data": {}} outfile = open(opt["result_file"], "w") json.dump(output_dict, outfile) outfile.close()
[ "def", "BMN_post_processing", "(", "opt", ")", ":", "video_dict", "=", "getDatasetDict", "(", "opt", ")", "video_list", "=", "list", "(", "video_dict", ".", "keys", "(", ")", ")", "# [:100]", "global", "result_dict", "result_dict", "=", "mp", ".", "Manager",...
https://github.com/JJBOY/BMN-Boundary-Matching-Network/blob/a92c1d79c19d88b1d57b5abfae5a0be33f3002eb/post_processing.py#L102-L127
happinesslz/TANet
2d4b2ab99b8e57c03671b0f1531eab7dca8f3c1f
second.pytorch_with_TANet/second/core/box_np_ops.py
python
limit_period
(val, offset=0.5, period=np.pi)
return val - np.floor(val / period + offset) * period
[]
def limit_period(val, offset=0.5, period=np.pi): return val - np.floor(val / period + offset) * period
[ "def", "limit_period", "(", "val", ",", "offset", "=", "0.5", ",", "period", "=", "np", ".", "pi", ")", ":", "return", "val", "-", "np", ".", "floor", "(", "val", "/", "period", "+", "offset", ")", "*", "period" ]
https://github.com/happinesslz/TANet/blob/2d4b2ab99b8e57c03671b0f1531eab7dca8f3c1f/second.pytorch_with_TANet/second/core/box_np_ops.py#L503-L504
annoviko/pyclustering
bf4f51a472622292627ec8c294eb205585e50f52
pyclustering/nnet/examples/sync_examples.py
python
negative_connection_9_grid_struct
()
Comment: Right coloring
Comment: Right coloring
[ "Comment", ":", "Right", "coloring" ]
def negative_connection_9_grid_struct(): "Comment: Right coloring" _ = template_dynamic_sync(9, -2, conn = conn_type.GRID_FOUR)
[ "def", "negative_connection_9_grid_struct", "(", ")", ":", "_", "=", "template_dynamic_sync", "(", "9", ",", "-", "2", ",", "conn", "=", "conn_type", ".", "GRID_FOUR", ")" ]
https://github.com/annoviko/pyclustering/blob/bf4f51a472622292627ec8c294eb205585e50f52/pyclustering/nnet/examples/sync_examples.py#L65-L67
Esri/ArcREST
ab240fde2b0200f61d4a5f6df033516e53f2f416
src/arcrest/manageorg/_parameters.py
python
PublishCSVParameters.columnNames
(self)
return self._columnNames
gets/sets the columnNames
gets/sets the columnNames
[ "gets", "/", "sets", "the", "columnNames" ]
def columnNames(self): """gets/sets the columnNames""" return self._columnNames
[ "def", "columnNames", "(", "self", ")", ":", "return", "self", ".", "_columnNames" ]
https://github.com/Esri/ArcREST/blob/ab240fde2b0200f61d4a5f6df033516e53f2f416/src/arcrest/manageorg/_parameters.py#L1906-L1908
theotherp/nzbhydra
4b03d7f769384b97dfc60dade4806c0fc987514e
libs/cherrypy/_cptree.py
python
Application.get_serving
(self, local, remote, scheme, sproto)
return req, resp
Create and return a Request and Response object.
Create and return a Request and Response object.
[ "Create", "and", "return", "a", "Request", "and", "Response", "object", "." ]
def get_serving(self, local, remote, scheme, sproto): """Create and return a Request and Response object.""" req = self.request_class(local, remote, scheme, sproto) req.app = self for name, toolbox in self.toolboxes.items(): req.namespaces[name] = toolbox resp = self.response_class() cherrypy.serving.load(req, resp) cherrypy.engine.publish('acquire_thread') cherrypy.engine.publish('before_request') return req, resp
[ "def", "get_serving", "(", "self", ",", "local", ",", "remote", ",", "scheme", ",", "sproto", ")", ":", "req", "=", "self", ".", "request_class", "(", "local", ",", "remote", ",", "scheme", ",", "sproto", ")", "req", ".", "app", "=", "self", "for", ...
https://github.com/theotherp/nzbhydra/blob/4b03d7f769384b97dfc60dade4806c0fc987514e/libs/cherrypy/_cptree.py#L122-L135
flennerhag/mlens
6cbc11354b5f9500a33d9cefb700a1bba9d3199a
mlens/config.py
python
set_dtype
(dtype)
Set the dtype to use during estimation. Parameters ---------- dtype : object numpy dtype
Set the dtype to use during estimation.
[ "Set", "the", "dtype", "to", "use", "during", "estimation", "." ]
def set_dtype(dtype): """Set the dtype to use during estimation. Parameters ---------- dtype : object numpy dtype """ global _DTYPE _DTYPE = dtype
[ "def", "set_dtype", "(", "dtype", ")", ":", "global", "_DTYPE", "_DTYPE", "=", "dtype" ]
https://github.com/flennerhag/mlens/blob/6cbc11354b5f9500a33d9cefb700a1bba9d3199a/mlens/config.py#L133-L142
tomplus/kubernetes_asyncio
f028cc793e3a2c519be6a52a49fb77ff0b014c9b
kubernetes_asyncio/client/models/v1_lease.py
python
V1Lease.__repr__
(self)
return self.to_str()
For `print` and `pprint`
For `print` and `pprint`
[ "For", "print", "and", "pprint" ]
def __repr__(self): """For `print` and `pprint`""" return self.to_str()
[ "def", "__repr__", "(", "self", ")", ":", "return", "self", ".", "to_str", "(", ")" ]
https://github.com/tomplus/kubernetes_asyncio/blob/f028cc793e3a2c519be6a52a49fb77ff0b014c9b/kubernetes_asyncio/client/models/v1_lease.py#L186-L188
saltstack/halite
1eacc7e3f51b670573aecb8980661e0c5dbfa0f4
halite/bottle.py
python
BaseResponse.iter_headers
(self)
return self.headerlist
Yield (header, value) tuples, skipping headers that are not allowed with the current response status code.
Yield (header, value) tuples, skipping headers that are not allowed with the current response status code.
[ "Yield", "(", "header", "value", ")", "tuples", "skipping", "headers", "that", "are", "not", "allowed", "with", "the", "current", "response", "status", "code", "." ]
def iter_headers(self): ''' Yield (header, value) tuples, skipping headers that are not allowed with the current response status code. ''' return self.headerlist
[ "def", "iter_headers", "(", "self", ")", ":", "return", "self", ".", "headerlist" ]
https://github.com/saltstack/halite/blob/1eacc7e3f51b670573aecb8980661e0c5dbfa0f4/halite/bottle.py#L1510-L1513
openshift/openshift-tools
1188778e728a6e4781acf728123e5b356380fe6f
openshift/installer/vendored/openshift-ansible-3.11.28-1/roles/lib_openshift/library/oc_configmap.py
python
Utils._write
(filename, contents)
Actually write the file contents to disk. This helps with mocking.
Actually write the file contents to disk. This helps with mocking.
[ "Actually", "write", "the", "file", "contents", "to", "disk", ".", "This", "helps", "with", "mocking", "." ]
def _write(filename, contents): ''' Actually write the file contents to disk. This helps with mocking. ''' with open(filename, 'w') as sfd: sfd.write(str(contents))
[ "def", "_write", "(", "filename", ",", "contents", ")", ":", "with", "open", "(", "filename", ",", "'w'", ")", "as", "sfd", ":", "sfd", ".", "write", "(", "str", "(", "contents", ")", ")" ]
https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/openshift/installer/vendored/openshift-ansible-3.11.28-1/roles/lib_openshift/library/oc_configmap.py#L1163-L1167
apache/tvm
6eb4ed813ebcdcd9558f0906a1870db8302ff1e0
python/tvm/topi/arm_cpu/mprofile/dsp/micro_kernel/max_pool.py
python
intrin_max
(shape, in_dtype, out_dtype)
return intrin_decl, uniq_id
Defines a v7e-m DSP-accelerated max pool.
Defines a v7e-m DSP-accelerated max pool.
[ "Defines", "a", "v7e", "-", "m", "DSP", "-", "accelerated", "max", "pool", "." ]
def intrin_max(shape, in_dtype, out_dtype): """Defines a v7e-m DSP-accelerated max pool.""" UNIQ_ID_LEN = 8 uniq_id = "".join(random.choices(string.ascii_uppercase, k=UNIQ_ID_LEN)) func_prefix = "max8" assert in_dtype == "int8" assert out_dtype == "int8" x = te.placeholder(shape, name="x", dtype=in_dtype) k = te.reduce_axis((0, 1), name="rc") z = te.compute(shape, lambda *i: tvm.tir.max(x[i], axis=[k]).astype(out_dtype)) def _intrin_func(ins, outs): aa = ins[0] cc = outs[0] def _body(): ib = tvm.tir.ir_builder.create() ib.emit( tvm.tir.call_extern( cc.dtype, f"{func_prefix}_{uniq_id}", aa.access_ptr("r"), cc.access_ptr("w"), cc.strides[0], ) ) return ib.get() def _reduce_reset(): ib = tvm.tir.ir_builder.create() ib.emit( tvm.tir.call_extern( cc.dtype, f"{func_prefix}_reset_{uniq_id}", cc.access_ptr("w"), cc.strides[0] ) ) return ib.get() def _reduce_update(): return _body() return _body(), _reduce_reset(), _reduce_update() binds = { t: tvm.tir.decl_buffer( t.shape, t.dtype, t.op.name, strides=[te.var(f"{t.op.name}_s_{i}") for i in range(0, len(t.shape))], offset_factor=1, ) for t in [x, z] } intrin_decl = te.decl_tensor_intrin(z.op, _intrin_func, binds=binds) return intrin_decl, uniq_id
[ "def", "intrin_max", "(", "shape", ",", "in_dtype", ",", "out_dtype", ")", ":", "UNIQ_ID_LEN", "=", "8", "uniq_id", "=", "\"\"", ".", "join", "(", "random", ".", "choices", "(", "string", ".", "ascii_uppercase", ",", "k", "=", "UNIQ_ID_LEN", ")", ")", ...
https://github.com/apache/tvm/blob/6eb4ed813ebcdcd9558f0906a1870db8302ff1e0/python/tvm/topi/arm_cpu/mprofile/dsp/micro_kernel/max_pool.py#L28-L84
guillermooo/Vintageous
f958207009902052aed5fcac09745f1742648604
vi/inputs.py
python
vi_at
(state)
return p
[]
def vi_at(state): p = parser_def(command=one_char, interactive_command=None, input_param=None, on_done=None, type=input_types.INMEDIATE) return p
[ "def", "vi_at", "(", "state", ")", ":", "p", "=", "parser_def", "(", "command", "=", "one_char", ",", "interactive_command", "=", "None", ",", "input_param", "=", "None", ",", "on_done", "=", "None", ",", "type", "=", "input_types", ".", "INMEDIATE", ")"...
https://github.com/guillermooo/Vintageous/blob/f958207009902052aed5fcac09745f1742648604/vi/inputs.py#L98-L104
IBM/pytorchpipe
9cb17271666061cb19fe24197ecd5e4c8d32c5da
ptp/components/tasks/image_text_to_class/vqa_med_2019.py
python
VQAMED2019.filter_sources
(self, source_files, source_image_folders, source_categories)
return source_files, source_image_folders, source_categories
Loads the dataset from one or more files. :param source_files: List of source files. :param source_image_folders: List of folders containing image files. :param source_categories: List of categories associated with each of those files. (<UNK> unknown) :return: Tuple consisting of: filtered source_files and filtered source_categories
Loads the dataset from one or more files.
[ "Loads", "the", "dataset", "from", "one", "or", "more", "files", "." ]
def filter_sources(self, source_files, source_image_folders, source_categories): """ Loads the dataset from one or more files. :param source_files: List of source files. :param source_image_folders: List of folders containing image files. :param source_categories: List of categories associated with each of those files. (<UNK> unknown) :return: Tuple consisting of: filtered source_files and filtered source_categories """ # Check categories that user want to use. use_files = [False] * 4 categs = {'C1': 0, 'C2': 1, 'C3': 2, 'C4': 3} # Parse categories from configuration list. loaded_categs = get_value_list_from_dictionary("categories", self.config, ['C1', 'C2', 'C3', 'C4', 'all']) for cat in loaded_categs: # "Special" case. if cat == "all": use_files = [True] * 4 # Make no sense to continue. break else: use_files[categs[cat]] = True # Filter. _, source_files, source_image_folders, source_categories = zip(*(filter(lambda x: x[0], zip(use_files, source_files, source_image_folders, source_categories)))) return source_files, source_image_folders, source_categories
[ "def", "filter_sources", "(", "self", ",", "source_files", ",", "source_image_folders", ",", "source_categories", ")", ":", "# Check categories that user want to use.", "use_files", "=", "[", "False", "]", "*", "4", "categs", "=", "{", "'C1'", ":", "0", ",", "'C...
https://github.com/IBM/pytorchpipe/blob/9cb17271666061cb19fe24197ecd5e4c8d32c5da/ptp/components/tasks/image_text_to_class/vqa_med_2019.py#L346-L373
cagbal/ros_people_object_detection_tensorflow
982ffd4a54b8059638f5cd4aa167299c7fc9e61f
src/object_detection/trainer.py
python
train
(create_tensor_dict_fn, create_model_fn, train_config, master, task, num_clones, worker_replicas, clone_on_cpu, ps_tasks, worker_job_name, is_chief, train_dir, graph_hook_fn=None)
Training function for detection models. Args: create_tensor_dict_fn: a function to create a tensor input dictionary. create_model_fn: a function that creates a DetectionModel and generates losses. train_config: a train_pb2.TrainConfig protobuf. master: BNS name of the TensorFlow master to use. task: The task id of this training instance. num_clones: The number of clones to run per machine. worker_replicas: The number of work replicas to train with. clone_on_cpu: True if clones should be forced to run on CPU. ps_tasks: Number of parameter server tasks. worker_job_name: Name of the worker job. is_chief: Whether this replica is the chief replica. train_dir: Directory to write checkpoints and training summaries to. graph_hook_fn: Optional function that is called after the training graph is completely built. This is helpful to perform additional changes to the training graph such as optimizing batchnorm. The function should modify the default graph.
Training function for detection models.
[ "Training", "function", "for", "detection", "models", "." ]
def train(create_tensor_dict_fn, create_model_fn, train_config, master, task, num_clones, worker_replicas, clone_on_cpu, ps_tasks, worker_job_name, is_chief, train_dir, graph_hook_fn=None): """Training function for detection models. Args: create_tensor_dict_fn: a function to create a tensor input dictionary. create_model_fn: a function that creates a DetectionModel and generates losses. train_config: a train_pb2.TrainConfig protobuf. master: BNS name of the TensorFlow master to use. task: The task id of this training instance. num_clones: The number of clones to run per machine. worker_replicas: The number of work replicas to train with. clone_on_cpu: True if clones should be forced to run on CPU. ps_tasks: Number of parameter server tasks. worker_job_name: Name of the worker job. is_chief: Whether this replica is the chief replica. train_dir: Directory to write checkpoints and training summaries to. graph_hook_fn: Optional function that is called after the training graph is completely built. This is helpful to perform additional changes to the training graph such as optimizing batchnorm. The function should modify the default graph. """ detection_model = create_model_fn() data_augmentation_options = [ preprocessor_builder.build(step) for step in train_config.data_augmentation_options] with tf.Graph().as_default(): # Build a configuration specifying multi-GPU and multi-replicas. deploy_config = model_deploy.DeploymentConfig( num_clones=num_clones, clone_on_cpu=clone_on_cpu, replica_id=task, num_replicas=worker_replicas, num_ps_tasks=ps_tasks, worker_job_name=worker_job_name) # Place the global step on the device storing the variables. with tf.device(deploy_config.variables_device()): global_step = slim.create_global_step() with tf.device(deploy_config.inputs_device()): input_queue = create_input_queue( train_config.batch_size // num_clones, create_tensor_dict_fn, train_config.batch_queue_capacity, train_config.num_batch_queue_threads, train_config.prefetch_queue_capacity, data_augmentation_options) # Gather initial summaries. # TODO(rathodv): See if summaries can be added/extracted from global tf # collections so that they don't have to be passed around. summaries = set(tf.get_collection(tf.GraphKeys.SUMMARIES)) global_summaries = set([]) model_fn = functools.partial(_create_losses, create_model_fn=create_model_fn, train_config=train_config) clones = model_deploy.create_clones(deploy_config, model_fn, [input_queue]) first_clone_scope = clones[0].scope # Gather update_ops from the first clone. These contain, for example, # the updates for the batch_norm variables created by model_fn. update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS, first_clone_scope) with tf.device(deploy_config.optimizer_device()): training_optimizer, optimizer_summary_vars = optimizer_builder.build( train_config.optimizer) for var in optimizer_summary_vars: tf.summary.scalar(var.op.name, var, family='LearningRate') sync_optimizer = None if train_config.sync_replicas: training_optimizer = tf.train.SyncReplicasOptimizer( training_optimizer, replicas_to_aggregate=train_config.replicas_to_aggregate, total_num_replicas=worker_replicas) sync_optimizer = training_optimizer # Create ops required to initialize the model from a given checkpoint. init_fn = None if train_config.fine_tune_checkpoint: if not train_config.fine_tune_checkpoint_type: # train_config.from_detection_checkpoint field is deprecated. For # backward compatibility, fine_tune_checkpoint_type is set based on # from_detection_checkpoint. if train_config.from_detection_checkpoint: train_config.fine_tune_checkpoint_type = 'detection' else: train_config.fine_tune_checkpoint_type = 'classification' var_map = detection_model.restore_map( fine_tune_checkpoint_type=train_config.fine_tune_checkpoint_type, load_all_detection_checkpoint_vars=( train_config.load_all_detection_checkpoint_vars)) available_var_map = (variables_helper. get_variables_available_in_checkpoint( var_map, train_config.fine_tune_checkpoint)) init_saver = tf.train.Saver(available_var_map) def initializer_fn(sess): init_saver.restore(sess, train_config.fine_tune_checkpoint) init_fn = initializer_fn with tf.device(deploy_config.optimizer_device()): regularization_losses = (None if train_config.add_regularization_loss else []) total_loss, grads_and_vars = model_deploy.optimize_clones( clones, training_optimizer, regularization_losses=regularization_losses) total_loss = tf.check_numerics(total_loss, 'LossTensor is inf or nan.') # Optionally multiply bias gradients by train_config.bias_grad_multiplier. if train_config.bias_grad_multiplier: biases_regex_list = ['.*/biases'] grads_and_vars = variables_helper.multiply_gradients_matching_regex( grads_and_vars, biases_regex_list, multiplier=train_config.bias_grad_multiplier) # Optionally freeze some layers by setting their gradients to be zero. if train_config.freeze_variables: grads_and_vars = variables_helper.freeze_gradients_matching_regex( grads_and_vars, train_config.freeze_variables) # Optionally clip gradients if train_config.gradient_clipping_by_norm > 0: with tf.name_scope('clip_grads'): grads_and_vars = slim.learning.clip_gradient_norms( grads_and_vars, train_config.gradient_clipping_by_norm) # Create gradient updates. grad_updates = training_optimizer.apply_gradients(grads_and_vars, global_step=global_step) update_ops.append(grad_updates) update_op = tf.group(*update_ops, name='update_barrier') with tf.control_dependencies([update_op]): train_tensor = tf.identity(total_loss, name='train_op') if graph_hook_fn: with tf.device(deploy_config.variables_device()): graph_hook_fn() # Add summaries. for model_var in slim.get_model_variables(): global_summaries.add(tf.summary.histogram('ModelVars/' + model_var.op.name, model_var)) for loss_tensor in tf.losses.get_losses(): global_summaries.add(tf.summary.scalar('Losses/' + loss_tensor.op.name, loss_tensor)) global_summaries.add( tf.summary.scalar('Losses/TotalLoss', tf.losses.get_total_loss())) # Add the summaries from the first clone. These contain the summaries # created by model_fn and either optimize_clones() or _gather_clone_loss(). summaries |= set(tf.get_collection(tf.GraphKeys.SUMMARIES, first_clone_scope)) summaries |= global_summaries # Merge all summaries together. summary_op = tf.summary.merge(list(summaries), name='summary_op') # Soft placement allows placing on CPU ops without GPU implementation. session_config = tf.ConfigProto(allow_soft_placement=True, log_device_placement=False) # Save checkpoints regularly. keep_checkpoint_every_n_hours = train_config.keep_checkpoint_every_n_hours saver = tf.train.Saver( keep_checkpoint_every_n_hours=keep_checkpoint_every_n_hours) slim.learning.train( train_tensor, logdir=train_dir, master=master, is_chief=is_chief, session_config=session_config, startup_delay_steps=train_config.startup_delay_steps, init_fn=init_fn, summary_op=summary_op, number_of_steps=( train_config.num_steps if train_config.num_steps else None), save_summaries_secs=120, sync_optimizer=sync_optimizer, saver=saver)
[ "def", "train", "(", "create_tensor_dict_fn", ",", "create_model_fn", ",", "train_config", ",", "master", ",", "task", ",", "num_clones", ",", "worker_replicas", ",", "clone_on_cpu", ",", "ps_tasks", ",", "worker_job_name", ",", "is_chief", ",", "train_dir", ",", ...
https://github.com/cagbal/ros_people_object_detection_tensorflow/blob/982ffd4a54b8059638f5cd4aa167299c7fc9e61f/src/object_detection/trainer.py#L186-L370
voila-dashboards/voila
495bcfea54a5af8b65708c5289e4594067524f2f
voila/execute.py
python
VoilaExecutor.should_strip_error
(self)
return not self.show_tracebacks
Return True if errors should be stripped from the Notebook, False otherwise, depending on the current config.
Return True if errors should be stripped from the Notebook, False otherwise, depending on the current config.
[ "Return", "True", "if", "errors", "should", "be", "stripped", "from", "the", "Notebook", "False", "otherwise", "depending", "on", "the", "current", "config", "." ]
def should_strip_error(self): """Return True if errors should be stripped from the Notebook, False otherwise, depending on the current config.""" return not self.show_tracebacks
[ "def", "should_strip_error", "(", "self", ")", ":", "return", "not", "self", ".", "show_tracebacks" ]
https://github.com/voila-dashboards/voila/blob/495bcfea54a5af8b65708c5289e4594067524f2f/voila/execute.py#L82-L84
omz/PythonistaAppTemplate
f560f93f8876d82a21d108977f90583df08d55af
PythonistaAppTemplate/PythonistaKit.framework/pylib/site-packages/werkzeug/datastructures.py
python
ImmutableTypeConversionDict.copy
(self)
return TypeConversionDict(self)
Return a shallow mutable copy of this object. Keep in mind that the standard library's :func:`copy` function is a no-op for this class like for any other python immutable type (eg: :class:`tuple`).
Return a shallow mutable copy of this object. Keep in mind that the standard library's :func:`copy` function is a no-op for this class like for any other python immutable type (eg: :class:`tuple`).
[ "Return", "a", "shallow", "mutable", "copy", "of", "this", "object", ".", "Keep", "in", "mind", "that", "the", "standard", "library", "s", ":", "func", ":", "copy", "function", "is", "a", "no", "-", "op", "for", "this", "class", "like", "for", "any", ...
def copy(self): """Return a shallow mutable copy of this object. Keep in mind that the standard library's :func:`copy` function is a no-op for this class like for any other python immutable type (eg: :class:`tuple`). """ return TypeConversionDict(self)
[ "def", "copy", "(", "self", ")", ":", "return", "TypeConversionDict", "(", "self", ")" ]
https://github.com/omz/PythonistaAppTemplate/blob/f560f93f8876d82a21d108977f90583df08d55af/PythonistaAppTemplate/PythonistaKit.framework/pylib/site-packages/werkzeug/datastructures.py#L304-L309
opendatacube/datacube-core
b062184be61c140a168de94510bc3661748f112e
datacube/index/_datasets.py
python
DatasetResource.archive_location
(self, id_, uri)
Archive a location of the dataset if it exists. :param typing.Union[UUID, str] id_: dataset id :param str uri: fully qualified uri :return bool: location was able to be archived
Archive a location of the dataset if it exists.
[ "Archive", "a", "location", "of", "the", "dataset", "if", "it", "exists", "." ]
def archive_location(self, id_, uri): """ Archive a location of the dataset if it exists. :param typing.Union[UUID, str] id_: dataset id :param str uri: fully qualified uri :return bool: location was able to be archived """ with self._db.connect() as connection: was_archived = connection.archive_location(id_, uri) return was_archived
[ "def", "archive_location", "(", "self", ",", "id_", ",", "uri", ")", ":", "with", "self", ".", "_db", ".", "connect", "(", ")", "as", "connection", ":", "was_archived", "=", "connection", ".", "archive_location", "(", "id_", ",", "uri", ")", "return", ...
https://github.com/opendatacube/datacube-core/blob/b062184be61c140a168de94510bc3661748f112e/datacube/index/_datasets.py#L464-L474
OpenMDAO/OpenMDAO-Framework
f2e37b7de3edeaaeb2d251b375917adec059db9b
openmdao.main/src/openmdao/main/systems.py
python
System.set_complex_step
(self, complex_step=False)
Toggles complex_step plumbing for this system and all local subsystems.
Toggles complex_step plumbing for this system and all local subsystems.
[ "Toggles", "complex_step", "plumbing", "for", "this", "system", "and", "all", "local", "subsystems", "." ]
def set_complex_step(self, complex_step=False): """ Toggles complex_step plumbing for this system and all local subsystems. """ self.complex_step = complex_step for subsystem in self.local_subsystems(): subsystem.set_complex_step(complex_step)
[ "def", "set_complex_step", "(", "self", ",", "complex_step", "=", "False", ")", ":", "self", ".", "complex_step", "=", "complex_step", "for", "subsystem", "in", "self", ".", "local_subsystems", "(", ")", ":", "subsystem", ".", "set_complex_step", "(", "complex...
https://github.com/OpenMDAO/OpenMDAO-Framework/blob/f2e37b7de3edeaaeb2d251b375917adec059db9b/openmdao.main/src/openmdao/main/systems.py#L810-L817
armancohan/long-summarization
1328d4f37b3a3a460f455e93e84ed4ddcd10dab1
batch_reader.py
python
_section_to_ids
(section, vocab, max_len, pad_id)
Converts words in a section (list of strings) to ids and pad if necessary
Converts words in a section (list of strings) to ids and pad if necessary
[ "Converts", "words", "in", "a", "section", "(", "list", "of", "strings", ")", "to", "ids", "and", "pad", "if", "necessary" ]
def _section_to_ids(section, vocab, max_len, pad_id): """ Converts words in a section (list of strings) to ids and pad if necessary """ section_text = ' '.join(section) section_words = section_text.split() sec_len = len(section_words) if sec_len > max_len: section_words = section_words[:max_len] word_ids = [vocab.word2id(w) for w in section_words]
[ "def", "_section_to_ids", "(", "section", ",", "vocab", ",", "max_len", ",", "pad_id", ")", ":", "section_text", "=", "' '", ".", "join", "(", "section", ")", "section_words", "=", "section_text", ".", "split", "(", ")", "sec_len", "=", "len", "(", "sect...
https://github.com/armancohan/long-summarization/blob/1328d4f37b3a3a460f455e93e84ed4ddcd10dab1/batch_reader.py#L61-L68
tp4a/teleport
1fafd34f1f775d2cf80ea4af6e44468d8e0b24ad
server/www/packages/packages-windows/x86/pyasn1/type/univ.py
python
SequenceAndSetBase.reset
(self)
return self
Remove all components and become a |ASN.1| schema object. See :meth:`isValue` property for more information on the distinction between value and schema objects.
Remove all components and become a |ASN.1| schema object.
[ "Remove", "all", "components", "and", "become", "a", "|ASN", ".", "1|", "schema", "object", "." ]
def reset(self): """Remove all components and become a |ASN.1| schema object. See :meth:`isValue` property for more information on the distinction between value and schema objects. """ self._componentValues = noValue self._dynamicNames = self.DynamicNames() return self
[ "def", "reset", "(", "self", ")", ":", "self", ".", "_componentValues", "=", "noValue", "self", ".", "_dynamicNames", "=", "self", ".", "DynamicNames", "(", ")", "return", "self" ]
https://github.com/tp4a/teleport/blob/1fafd34f1f775d2cf80ea4af6e44468d8e0b24ad/server/www/packages/packages-windows/x86/pyasn1/type/univ.py#L2304-L2312
alcarithemad/zfsp
37a25b83103aa67a269b31cd4413d3baaffcde56
zfs/readcontext.py
python
ReadContext.checksum
(self, data: bytes, valid, checksum)
return util.checksum(data, valid, checksum, self.default_checksum)
[]
def checksum(self, data: bytes, valid, checksum) -> bool: return util.checksum(data, valid, checksum, self.default_checksum)
[ "def", "checksum", "(", "self", ",", "data", ":", "bytes", ",", "valid", ",", "checksum", ")", "->", "bool", ":", "return", "util", ".", "checksum", "(", "data", ",", "valid", ",", "checksum", ",", "self", ".", "default_checksum", ")" ]
https://github.com/alcarithemad/zfsp/blob/37a25b83103aa67a269b31cd4413d3baaffcde56/zfs/readcontext.py#L22-L23
beeware/voc
dd9f15a7d56d00d8c9e501a57194694e601ea401
tools/compile_stdlib.py
python
native_modules
(target)
return set(modules)
Find stdlib modules already implemented in java.
Find stdlib modules already implemented in java.
[ "Find", "stdlib", "modules", "already", "implemented", "in", "java", "." ]
def native_modules(target): """Find stdlib modules already implemented in java.""" modules = [] for folder in ['common', target]: basedir = os.path.join(REPO_ROOT, 'python', folder, 'python') for name in os.listdir(basedir): module_name, ext = os.path.splitext(name) if (ext == '.java' or ext == '' and os.path.isdir(os.path.join(basedir, name))): modules.append(module_name) return set(modules)
[ "def", "native_modules", "(", "target", ")", ":", "modules", "=", "[", "]", "for", "folder", "in", "[", "'common'", ",", "target", "]", ":", "basedir", "=", "os", ".", "path", ".", "join", "(", "REPO_ROOT", ",", "'python'", ",", "folder", ",", "'pyth...
https://github.com/beeware/voc/blob/dd9f15a7d56d00d8c9e501a57194694e601ea401/tools/compile_stdlib.py#L157-L168
wistbean/learn_python3_spider
73c873f4845f4385f097e5057407d03dd37a117b
stackoverflow/venv/lib/python3.6/site-packages/pip-19.0.3-py3.6.egg/pip/_vendor/appdirs.py
python
user_log_dir
(appname=None, appauthor=None, version=None, opinion=True)
return path
r"""Return full path to the user-specific log dir for this application. "appname" is the name of application. If None, just the system directory is returned. "appauthor" (only used on Windows) is the name of the appauthor or distributing body for this application. Typically it is the owning company name. This falls back to appname. You may pass False to disable it. "version" is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be "<major>.<minor>". Only applied when appname is present. "opinion" (boolean) can be False to disable the appending of "Logs" to the base app data dir for Windows, and "log" to the base cache dir for Unix. See discussion below. Typical user log directories are: Mac OS X: ~/Library/Logs/<AppName> Unix: ~/.cache/<AppName>/log # or under $XDG_CACHE_HOME if defined Win XP: C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>\Logs Vista: C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>\Logs On Windows the only suggestion in the MSDN docs is that local settings go in the `CSIDL_LOCAL_APPDATA` directory. (Note: I'm interested in examples of what some windows apps use for a logs dir.) OPINION: This function appends "Logs" to the `CSIDL_LOCAL_APPDATA` value for Windows and appends "log" to the user cache dir for Unix. This can be disabled with the `opinion=False` option.
r"""Return full path to the user-specific log dir for this application.
[ "r", "Return", "full", "path", "to", "the", "user", "-", "specific", "log", "dir", "for", "this", "application", "." ]
def user_log_dir(appname=None, appauthor=None, version=None, opinion=True): r"""Return full path to the user-specific log dir for this application. "appname" is the name of application. If None, just the system directory is returned. "appauthor" (only used on Windows) is the name of the appauthor or distributing body for this application. Typically it is the owning company name. This falls back to appname. You may pass False to disable it. "version" is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be "<major>.<minor>". Only applied when appname is present. "opinion" (boolean) can be False to disable the appending of "Logs" to the base app data dir for Windows, and "log" to the base cache dir for Unix. See discussion below. Typical user log directories are: Mac OS X: ~/Library/Logs/<AppName> Unix: ~/.cache/<AppName>/log # or under $XDG_CACHE_HOME if defined Win XP: C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>\Logs Vista: C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>\Logs On Windows the only suggestion in the MSDN docs is that local settings go in the `CSIDL_LOCAL_APPDATA` directory. (Note: I'm interested in examples of what some windows apps use for a logs dir.) OPINION: This function appends "Logs" to the `CSIDL_LOCAL_APPDATA` value for Windows and appends "log" to the user cache dir for Unix. This can be disabled with the `opinion=False` option. """ if system == "darwin": path = os.path.join( os.path.expanduser('~/Library/Logs'), appname) elif system == "win32": path = user_data_dir(appname, appauthor, version) version = False if opinion: path = os.path.join(path, "Logs") else: path = user_cache_dir(appname, appauthor, version) version = False if opinion: path = os.path.join(path, "log") if appname and version: path = os.path.join(path, version) return path
[ "def", "user_log_dir", "(", "appname", "=", "None", ",", "appauthor", "=", "None", ",", "version", "=", "None", ",", "opinion", "=", "True", ")", ":", "if", "system", "==", "\"darwin\"", ":", "path", "=", "os", ".", "path", ".", "join", "(", "os", ...
https://github.com/wistbean/learn_python3_spider/blob/73c873f4845f4385f097e5057407d03dd37a117b/stackoverflow/venv/lib/python3.6/site-packages/pip-19.0.3-py3.6.egg/pip/_vendor/appdirs.py#L356-L404
Allen7D/mini-shop-server
5f3ddd5a4e5e99a1e005f11abc620cefff2493fc
app/dao/group.py
python
GroupDao.delete_group
(id)
:param id: 权限组id :return:
:param id: 权限组id :return:
[ ":", "param", "id", ":", "权限组id", ":", "return", ":" ]
def delete_group(id): ''' :param id: 权限组id :return: ''' group = Group.get_or_404(id=id, msg='分组不存在,删除失败') if User.get(group_id=id): raise Forbidden(msg='分组下存在用户,不可删除') # 删除group拥有的权限 with db.auto_commit(): db.session.query(Auth).filter( Auth.group_id == id ).delete(synchronize_session=False) group.hard_delete(commit=False)
[ "def", "delete_group", "(", "id", ")", ":", "group", "=", "Group", ".", "get_or_404", "(", "id", "=", "id", ",", "msg", "=", "'分组不存在,删除失败')", "", "if", "User", ".", "get", "(", "group_id", "=", "id", ")", ":", "raise", "Forbidden", "(", "msg", "=",...
https://github.com/Allen7D/mini-shop-server/blob/5f3ddd5a4e5e99a1e005f11abc620cefff2493fc/app/dao/group.py#L46-L60
zzzeek/sqlalchemy
fc5c54fcd4d868c2a4c7ac19668d72f506fe821e
lib/sqlalchemy/orm/collections.py
python
column_mapped_collection
(mapping_spec)
return lambda: MappedCollection(keyfunc)
A dictionary-based collection type with column-based keying. Returns a :class:`.MappedCollection` factory with a keying function generated from mapping_spec, which may be a Column or a sequence of Columns. The key value must be immutable for the lifetime of the object. You can not, for example, map on foreign key values if those key values will change during the session, i.e. from None to a database-assigned integer after a session flush.
A dictionary-based collection type with column-based keying.
[ "A", "dictionary", "-", "based", "collection", "type", "with", "column", "-", "based", "keying", "." ]
def column_mapped_collection(mapping_spec): """A dictionary-based collection type with column-based keying. Returns a :class:`.MappedCollection` factory with a keying function generated from mapping_spec, which may be a Column or a sequence of Columns. The key value must be immutable for the lifetime of the object. You can not, for example, map on foreign key values if those key values will change during the session, i.e. from None to a database-assigned integer after a session flush. """ cols = [ coercions.expect(roles.ColumnArgumentRole, q, argname="mapping_spec") for q in util.to_list(mapping_spec) ] keyfunc = _PlainColumnGetter(cols) return lambda: MappedCollection(keyfunc)
[ "def", "column_mapped_collection", "(", "mapping_spec", ")", ":", "cols", "=", "[", "coercions", ".", "expect", "(", "roles", ".", "ColumnArgumentRole", ",", "q", ",", "argname", "=", "\"mapping_spec\"", ")", "for", "q", "in", "util", ".", "to_list", "(", ...
https://github.com/zzzeek/sqlalchemy/blob/fc5c54fcd4d868c2a4c7ac19668d72f506fe821e/lib/sqlalchemy/orm/collections.py#L233-L251
rspivak/lsbasi
07e1a14516156a21ebe2d82e0bae4bba5ad73dd6
part19/spi.py
python
Parser.term
(self)
return node
term : factor ((MUL | INTEGER_DIV | FLOAT_DIV) factor)*
term : factor ((MUL | INTEGER_DIV | FLOAT_DIV) factor)*
[ "term", ":", "factor", "((", "MUL", "|", "INTEGER_DIV", "|", "FLOAT_DIV", ")", "factor", ")", "*" ]
def term(self): """term : factor ((MUL | INTEGER_DIV | FLOAT_DIV) factor)*""" node = self.factor() while self.current_token.type in ( TokenType.MUL, TokenType.INTEGER_DIV, TokenType.FLOAT_DIV, ): token = self.current_token if token.type == TokenType.MUL: self.eat(TokenType.MUL) elif token.type == TokenType.INTEGER_DIV: self.eat(TokenType.INTEGER_DIV) elif token.type == TokenType.FLOAT_DIV: self.eat(TokenType.FLOAT_DIV) node = BinOp(left=node, op=token, right=self.factor()) return node
[ "def", "term", "(", "self", ")", ":", "node", "=", "self", ".", "factor", "(", ")", "while", "self", ".", "current_token", ".", "type", "in", "(", "TokenType", ".", "MUL", ",", "TokenType", ".", "INTEGER_DIV", ",", "TokenType", ".", "FLOAT_DIV", ",", ...
https://github.com/rspivak/lsbasi/blob/07e1a14516156a21ebe2d82e0bae4bba5ad73dd6/part19/spi.py#L649-L668
chengzhengxin/groupsoftmax-simpledet
3f63a00998c57fee25241cf43a2e8600893ea462
models/tridentnet/resnet_v1.py
python
TridentResNetV1Builder.resnet_c4_factory
(cls, depth, use_3x3_conv0, use_bn_preprocess, num_trident_block, num_branch, branch_dilates, branch_ids, branch_bn_shared, branch_conv_shared, branch_deform, norm_type="local", norm_mom=0.9, ndev=None, fp16=False)
return c4
[]
def resnet_c4_factory(cls, depth, use_3x3_conv0, use_bn_preprocess, num_trident_block, num_branch, branch_dilates, branch_ids, branch_bn_shared, branch_conv_shared, branch_deform, norm_type="local", norm_mom=0.9, ndev=None, fp16=False): c1, c2, c3, c4, c5 = cls.resnet_factory(depth, use_3x3_conv0, use_bn_preprocess, num_trident_block, num_branch, branch_dilates, branch_ids, branch_bn_shared, branch_conv_shared, branch_deform, norm_type, norm_mom, ndev, fp16) return c4
[ "def", "resnet_c4_factory", "(", "cls", ",", "depth", ",", "use_3x3_conv0", ",", "use_bn_preprocess", ",", "num_trident_block", ",", "num_branch", ",", "branch_dilates", ",", "branch_ids", ",", "branch_bn_shared", ",", "branch_conv_shared", ",", "branch_deform", ",", ...
https://github.com/chengzhengxin/groupsoftmax-simpledet/blob/3f63a00998c57fee25241cf43a2e8600893ea462/models/tridentnet/resnet_v1.py#L249-L256
oilshell/oil
94388e7d44a9ad879b12615f6203b38596b5a2d3
opy/gold/class_vs_closure.py
python
Adder2
(amount)
return anon
[]
def Adder2(amount): def anon(x): return x + amount return anon
[ "def", "Adder2", "(", "amount", ")", ":", "def", "anon", "(", "x", ")", ":", "return", "x", "+", "amount", "return", "anon" ]
https://github.com/oilshell/oil/blob/94388e7d44a9ad879b12615f6203b38596b5a2d3/opy/gold/class_vs_closure.py#L57-L60
ladybug-tools/honeybee-legacy
bd62af4862fe022801fb87dbc8794fdf1dff73a9
src/Honeybee_ Run Energy Simulation.py
python
WriteIDF.EPZone
(self, zone)
return zoneStr
[]
def EPZone(self, zone): if zone.isPlenum: zone.partOfArea = False zoneStr = '\nZone,\n' + \ '\t' + zone.name + ',\n' + \ '\t' + `zone.north` + ',\t!-Direction of Relative North {deg}\n' + \ '\t' + `zone.origin.X` + ',\t!- X Origin {m}\n' + \ '\t' + `zone.origin.Y` + ',\t!- Y Origin {m}\n' + \ '\t' + `zone.origin.Z` + ',\t!- Z Origin {m}\n' + \ '\t' + str(zone.zoneType) + ',\t!- Type\n' + \ '\t' + str(zone.multiplier) + ',\t!- Multiplier\n' + \ '\t' + str(zone.ceilingHeight) + ',\t!- Ceiling Height\n' + \ '\t' + str(zone.volume) + ',\t!- Volume\n' + \ '\t' + str(zone.floorArea) + ',\t!- Floor Area\n' + \ '\t' + str(zone.insideConvectionAlgorithm) + ',\t!- Zone Inside Convection Algorithm\n' + \ '\t' + str(zone.outsideConvectionAlgorithm) + ',\t!- Zone Outside Convection Algorithm\n' + \ '\t' + self.booleanToYesNo(zone.partOfArea) + ';\t!- Part of Total Floor Area\n' return zoneStr
[ "def", "EPZone", "(", "self", ",", "zone", ")", ":", "if", "zone", ".", "isPlenum", ":", "zone", ".", "partOfArea", "=", "False", "zoneStr", "=", "'\\nZone,\\n'", "+", "'\\t'", "+", "zone", ".", "name", "+", "',\\n'", "+", "'\\t'", "+", "`zone.north`",...
https://github.com/ladybug-tools/honeybee-legacy/blob/bd62af4862fe022801fb87dbc8794fdf1dff73a9/src/Honeybee_ Run Energy Simulation.py#L117-L136
cocos2d/cocos2d-console
0b55cf8a5ebafffc7977fe5c64a4dea9b2d58c34
plugins/plugin_new/project_new.py
python
TPCreator.project_replace_mac_bundleid
(self, v)
will modify the content of the file
will modify the content of the file
[ "will", "modify", "the", "content", "of", "the", "file" ]
def project_replace_mac_bundleid(self, v): """ will modify the content of the file """ if self.mac_bundleid is None: return dst_project_dir = self.project_dir dst_project_name = self.project_name src_bundleid = v['src_bundle_id'] dst_bundleid = self.mac_bundleid if src_bundleid == dst_bundleid: return cocos.Logging.info(MultiLanguage.get_string('NEW_INFO_STEP_MAC_BUNDLEID_FMT', (src_bundleid, dst_bundleid))) files = v['files'] for f in files: dst = f.replace("PROJECT_NAME", dst_project_name) if os.path.exists(os.path.join(dst_project_dir, dst)): replace_string( os.path.join(dst_project_dir, dst), src_bundleid, dst_bundleid) else: cocos.Logging.warning(MultiLanguage.get_string('NEW_WARNING_FILE_NOT_FOUND_FMT', os.path.join(dst_project_dir, dst)))
[ "def", "project_replace_mac_bundleid", "(", "self", ",", "v", ")", ":", "if", "self", ".", "mac_bundleid", "is", "None", ":", "return", "dst_project_dir", "=", "self", ".", "project_dir", "dst_project_name", "=", "self", ".", "project_name", "src_bundleid", "=",...
https://github.com/cocos2d/cocos2d-console/blob/0b55cf8a5ebafffc7977fe5c64a4dea9b2d58c34/plugins/plugin_new/project_new.py#L689-L712
getavalon/core
31e8cb4760e00e3db64443f6f932b7fd8e96d41d
avalon/vendor/requests/packages/urllib3/contrib/_securetransport/low_level.py
python
_temporary_keychain
()
return keychain, tempdirectory
This function creates a temporary Mac keychain that we can use to work with credentials. This keychain uses a one-time password and a temporary file to store the data. We expect to have one keychain per socket. The returned SecKeychainRef must be freed by the caller, including calling SecKeychainDelete. Returns a tuple of the SecKeychainRef and the path to the temporary directory that contains it.
This function creates a temporary Mac keychain that we can use to work with credentials. This keychain uses a one-time password and a temporary file to store the data. We expect to have one keychain per socket. The returned SecKeychainRef must be freed by the caller, including calling SecKeychainDelete.
[ "This", "function", "creates", "a", "temporary", "Mac", "keychain", "that", "we", "can", "use", "to", "work", "with", "credentials", ".", "This", "keychain", "uses", "a", "one", "-", "time", "password", "and", "a", "temporary", "file", "to", "store", "the"...
def _temporary_keychain(): """ This function creates a temporary Mac keychain that we can use to work with credentials. This keychain uses a one-time password and a temporary file to store the data. We expect to have one keychain per socket. The returned SecKeychainRef must be freed by the caller, including calling SecKeychainDelete. Returns a tuple of the SecKeychainRef and the path to the temporary directory that contains it. """ # Unfortunately, SecKeychainCreate requires a path to a keychain. This # means we cannot use mkstemp to use a generic temporary file. Instead, # we're going to create a temporary directory and a filename to use there. # This filename will be 8 random bytes expanded into base64. We also need # some random bytes to password-protect the keychain we're creating, so we # ask for 40 random bytes. random_bytes = os.urandom(40) filename = base64.b64encode(random_bytes[:8]).decode('utf-8') password = base64.b64encode(random_bytes[8:]) # Must be valid UTF-8 tempdirectory = tempfile.mkdtemp() keychain_path = os.path.join(tempdirectory, filename).encode('utf-8') # We now want to create the keychain itself. keychain = Security.SecKeychainRef() status = Security.SecKeychainCreate( keychain_path, len(password), password, False, None, ctypes.byref(keychain) ) _assert_no_error(status) # Having created the keychain, we want to pass it off to the caller. return keychain, tempdirectory
[ "def", "_temporary_keychain", "(", ")", ":", "# Unfortunately, SecKeychainCreate requires a path to a keychain. This", "# means we cannot use mkstemp to use a generic temporary file. Instead,", "# we're going to create a temporary directory and a filename to use there.", "# This filename will be 8 r...
https://github.com/getavalon/core/blob/31e8cb4760e00e3db64443f6f932b7fd8e96d41d/avalon/vendor/requests/packages/urllib3/contrib/_securetransport/low_level.py#L168-L205
thiagopena/djangoSIGE
e32186b27bfd8acf21b0fa400e699cb5c73e5433
djangosige/apps/login/context_user.py
python
foto_usuario
(request)
return context_dict
[]
def foto_usuario(request): context_dict = {} # Foto do usuario try: user_foto = Usuario.objects.get(user=request.user).user_foto context_dict['user_foto_sidebar'] = user_foto except: pass # Empresa do usuario try: user_empresa = MinhaEmpresa.objects.get( m_usuario=Usuario.objects.get(user=request.user)).m_empresa if user_empresa: context_dict['user_empresa'] = user_empresa except: pass return context_dict
[ "def", "foto_usuario", "(", "request", ")", ":", "context_dict", "=", "{", "}", "# Foto do usuario", "try", ":", "user_foto", "=", "Usuario", ".", "objects", ".", "get", "(", "user", "=", "request", ".", "user", ")", ".", "user_foto", "context_dict", "[", ...
https://github.com/thiagopena/djangoSIGE/blob/e32186b27bfd8acf21b0fa400e699cb5c73e5433/djangosige/apps/login/context_user.py#L9-L27
cisco-sas/kitty
cb0760989dcdfe079e43ac574d872d0b18953a32
kitty/model/low_level/mutated_field.py
python
BitFlip.__init__
(self, value, num_bits=1, fuzzable=True, name=None)
:param value: value to mutate (str or bytes) :param num_bits: number of consequtive bits to flip (invert) :param fuzzable: is field fuzzable (default: True) :param name: name of the object (default: None) :raises: ``KittyException`` if num_bits is bigger than the value length in bits :raises: ``KittyException`` if num_bits is not positive
:param value: value to mutate (str or bytes) :param num_bits: number of consequtive bits to flip (invert) :param fuzzable: is field fuzzable (default: True) :param name: name of the object (default: None)
[ ":", "param", "value", ":", "value", "to", "mutate", "(", "str", "or", "bytes", ")", ":", "param", "num_bits", ":", "number", "of", "consequtive", "bits", "to", "flip", "(", "invert", ")", ":", "param", "fuzzable", ":", "is", "field", "fuzzable", "(", ...
def __init__(self, value, num_bits=1, fuzzable=True, name=None): ''' :param value: value to mutate (str or bytes) :param num_bits: number of consequtive bits to flip (invert) :param fuzzable: is field fuzzable (default: True) :param name: name of the object (default: None) :raises: ``KittyException`` if num_bits is bigger than the value length in bits :raises: ``KittyException`` if num_bits is not positive ''' kassert.is_of_types(value, (bytes, bytearray, str)) value = strToBytes(value) if len(value) * 8 < num_bits: raise KittyException('len of value in bits(%d) < num_bits(%d)' % (len(value) * 8, num_bits)) if num_bits <= 0: raise KittyException('num_bits(%d) <= 0' % (num_bits)) super(BitFlip, self).__init__(value=Bits(bytes=value), encoder=ENC_BITS_DEFAULT, fuzzable=fuzzable, name=name) self._data_len = len(value) * 8 self._num_bits = num_bits self._num_mutations = self._data_len - (num_bits - 1)
[ "def", "__init__", "(", "self", ",", "value", ",", "num_bits", "=", "1", ",", "fuzzable", "=", "True", ",", "name", "=", "None", ")", ":", "kassert", ".", "is_of_types", "(", "value", ",", "(", "bytes", ",", "bytearray", ",", "str", ")", ")", "valu...
https://github.com/cisco-sas/kitty/blob/cb0760989dcdfe079e43ac574d872d0b18953a32/kitty/model/low_level/mutated_field.py#L54-L73
omz/PythonistaAppTemplate
f560f93f8876d82a21d108977f90583df08d55af
PythonistaAppTemplate/PythonistaKit.framework/pylib/distutils/dist.py
python
Distribution.find_config_files
(self)
return files
Find as many configuration files as should be processed for this platform, and return a list of filenames in the order in which they should be parsed. The filenames returned are guaranteed to exist (modulo nasty race conditions). There are three possible config files: distutils.cfg in the Distutils installation directory (ie. where the top-level Distutils __inst__.py file lives), a file in the user's home directory named .pydistutils.cfg on Unix and pydistutils.cfg on Windows/Mac; and setup.cfg in the current directory. The file in the user's home directory can be disabled with the --no-user-cfg option.
Find as many configuration files as should be processed for this platform, and return a list of filenames in the order in which they should be parsed. The filenames returned are guaranteed to exist (modulo nasty race conditions).
[ "Find", "as", "many", "configuration", "files", "as", "should", "be", "processed", "for", "this", "platform", "and", "return", "a", "list", "of", "filenames", "in", "the", "order", "in", "which", "they", "should", "be", "parsed", ".", "The", "filenames", "...
def find_config_files(self): """Find as many configuration files as should be processed for this platform, and return a list of filenames in the order in which they should be parsed. The filenames returned are guaranteed to exist (modulo nasty race conditions). There are three possible config files: distutils.cfg in the Distutils installation directory (ie. where the top-level Distutils __inst__.py file lives), a file in the user's home directory named .pydistutils.cfg on Unix and pydistutils.cfg on Windows/Mac; and setup.cfg in the current directory. The file in the user's home directory can be disabled with the --no-user-cfg option. """ files = [] check_environ() # Where to look for the system-wide Distutils config file sys_dir = os.path.dirname(sys.modules['distutils'].__file__) # Look for the system config file sys_file = os.path.join(sys_dir, "distutils.cfg") if os.path.isfile(sys_file): files.append(sys_file) # What to call the per-user config file if os.name == 'posix': user_filename = ".pydistutils.cfg" else: user_filename = "pydistutils.cfg" # And look for the user config file if self.want_user_cfg: user_file = os.path.join(os.path.expanduser('~'), user_filename) if os.path.isfile(user_file): files.append(user_file) # All platforms support local setup.cfg local_file = "setup.cfg" if os.path.isfile(local_file): files.append(local_file) if DEBUG: self.announce("using config files: %s" % ', '.join(files)) return files
[ "def", "find_config_files", "(", "self", ")", ":", "files", "=", "[", "]", "check_environ", "(", ")", "# Where to look for the system-wide Distutils config file", "sys_dir", "=", "os", ".", "path", ".", "dirname", "(", "sys", ".", "modules", "[", "'distutils'", ...
https://github.com/omz/PythonistaAppTemplate/blob/f560f93f8876d82a21d108977f90583df08d55af/PythonistaAppTemplate/PythonistaKit.framework/pylib/distutils/dist.py#L330-L376
openshift/openshift-tools
1188778e728a6e4781acf728123e5b356380fe6f
openshift/installer/vendored/openshift-ansible-3.9.40/roles/lib_vendored_deps/library/oc_env.py
python
Yedit.put
(self, path, value)
return (True, self.yaml_dict)
put path, value into a dict
put path, value into a dict
[ "put", "path", "value", "into", "a", "dict" ]
def put(self, path, value): ''' put path, value into a dict ''' try: entry = Yedit.get_entry(self.yaml_dict, path, self.separator) except KeyError: entry = None if entry == value: return (False, self.yaml_dict) # deepcopy didn't work # Try to use ruamel.yaml and fallback to pyyaml try: tmp_copy = yaml.load(yaml.round_trip_dump(self.yaml_dict, default_flow_style=False), yaml.RoundTripLoader) except AttributeError: tmp_copy = copy.deepcopy(self.yaml_dict) # set the format attributes if available try: tmp_copy.fa.set_block_style() except AttributeError: pass result = Yedit.add_entry(tmp_copy, path, value, self.separator) if result is None: return (False, self.yaml_dict) # When path equals "" it is a special case. # "" refers to the root of the document # Only update the root path (entire document) when its a list or dict if path == '': if isinstance(result, list) or isinstance(result, dict): self.yaml_dict = result return (True, self.yaml_dict) return (False, self.yaml_dict) self.yaml_dict = tmp_copy return (True, self.yaml_dict)
[ "def", "put", "(", "self", ",", "path", ",", "value", ")", ":", "try", ":", "entry", "=", "Yedit", ".", "get_entry", "(", "self", ".", "yaml_dict", ",", "path", ",", "self", ".", "separator", ")", "except", "KeyError", ":", "entry", "=", "None", "i...
https://github.com/openshift/openshift-tools/blob/1188778e728a6e4781acf728123e5b356380fe6f/openshift/installer/vendored/openshift-ansible-3.9.40/roles/lib_vendored_deps/library/oc_env.py#L597-L638
annoviko/pyclustering
bf4f51a472622292627ec8c294eb205585e50f52
pyclustering/cluster/syncnet.py
python
syncnet._create_connections
(self, radius)
! @brief Create connections between oscillators in line with input radius of connectivity. @param[in] radius (double): Connectivity radius between oscillators.
!
[ "!" ]
def _create_connections(self, radius): """! @brief Create connections between oscillators in line with input radius of connectivity. @param[in] radius (double): Connectivity radius between oscillators. """ if self._ena_conn_weight is True: self._conn_weight = [[0] * self._num_osc for _ in range(0, self._num_osc, 1)] maximum_distance = 0 minimum_distance = float('inf') # Create connections for i in range(0, self._num_osc, 1): for j in range(i + 1, self._num_osc, 1): dist = euclidean_distance(self._osc_loc[i], self._osc_loc[j]) if self._ena_conn_weight is True: self._conn_weight[i][j] = dist self._conn_weight[j][i] = dist if (dist > maximum_distance): maximum_distance = dist if (dist < minimum_distance): minimum_distance = dist if dist <= radius: self.set_connection(i, j) if self._ena_conn_weight is True: multiplier = 1 subtractor = 0 if maximum_distance != minimum_distance: multiplier = (maximum_distance - minimum_distance) subtractor = minimum_distance for i in range(0, self._num_osc, 1): for j in range(i + 1, self._num_osc, 1): value_conn_weight = (self._conn_weight[i][j] - subtractor) / multiplier self._conn_weight[i][j] = value_conn_weight self._conn_weight[j][i] = value_conn_weight
[ "def", "_create_connections", "(", "self", ",", "radius", ")", ":", "if", "self", ".", "_ena_conn_weight", "is", "True", ":", "self", ".", "_conn_weight", "=", "[", "[", "0", "]", "*", "self", ".", "_num_osc", "for", "_", "in", "range", "(", "0", ","...
https://github.com/annoviko/pyclustering/blob/bf4f51a472622292627ec8c294eb205585e50f52/pyclustering/cluster/syncnet.py#L243-L285
mahmoud/boltons
270e974975984f662f998c8f6eb0ebebd964de82
boltons/setutils.py
python
_ComplementSet.intersection
(self, other)
[]
def intersection(self, other): try: return self & other except NotImplementedError: raise TypeError('argument must be another set or complement(set)')
[ "def", "intersection", "(", "self", ",", "other", ")", ":", "try", ":", "return", "self", "&", "other", "except", "NotImplementedError", ":", "raise", "TypeError", "(", "'argument must be another set or complement(set)'", ")" ]
https://github.com/mahmoud/boltons/blob/270e974975984f662f998c8f6eb0ebebd964de82/boltons/setutils.py#L641-L645
elfi-dev/elfi
07ac0ed5e81d5d5fb42de63db3cf9ccc9135b88c
elfi/methods/results.py
python
SmcSample.n_populations
(self)
return len(self.populations)
Return the number of populations.
Return the number of populations.
[ "Return", "the", "number", "of", "populations", "." ]
def n_populations(self): """Return the number of populations.""" return len(self.populations)
[ "def", "n_populations", "(", "self", ")", ":", "return", "len", "(", "self", ".", "populations", ")" ]
https://github.com/elfi-dev/elfi/blob/07ac0ed5e81d5d5fb42de63db3cf9ccc9135b88c/elfi/methods/results.py#L358-L360
cloudera/impyla
0c736af4cad2bade9b8e313badc08ec50e81c948
impala/_thrift_gen/TCLIService/ttypes.py
python
TCloseOperationResp.__repr__
(self)
return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
[]
def __repr__(self): L = ['%s=%r' % (key, value) for key, value in self.__dict__.items()] return '%s(%s)' % (self.__class__.__name__, ', '.join(L))
[ "def", "__repr__", "(", "self", ")", ":", "L", "=", "[", "'%s=%r'", "%", "(", "key", ",", "value", ")", "for", "key", ",", "value", "in", "self", ".", "__dict__", ".", "items", "(", ")", "]", "return", "'%s(%s)'", "%", "(", "self", ".", "__class_...
https://github.com/cloudera/impyla/blob/0c736af4cad2bade9b8e313badc08ec50e81c948/impala/_thrift_gen/TCLIService/ttypes.py#L5275-L5278
chartbeat-labs/textacy
40cd12fe953ef8be5958cff93ad8762262f3b757
src/textacy/extract/matches.py
python
regex_matches
( doclike: types.DocLike, pattern: str | Pattern, *, alignment_mode: str = "strict", # Literal["strict", "contract", "expand"] )
Extract ``Span`` s from a document or sentence whose full texts match against a regular expression ``pattern``. Args: doclike pattern: Valid regular expression against which to match document text, either as a string or compiled pattern object. alignment_mode: How character indices of regex matches snap to spaCy token boundaries. If "strict", only exact alignments are included (no snapping); if "contract", tokens completely within the character span are included; if "expand", tokens at least partially covered by the character span are included. Yields: Next matching ``Span``.
Extract ``Span`` s from a document or sentence whose full texts match against a regular expression ``pattern``.
[ "Extract", "Span", "s", "from", "a", "document", "or", "sentence", "whose", "full", "texts", "match", "against", "a", "regular", "expression", "pattern", "." ]
def regex_matches( doclike: types.DocLike, pattern: str | Pattern, *, alignment_mode: str = "strict", # Literal["strict", "contract", "expand"] ) -> Iterable[Span]: """ Extract ``Span`` s from a document or sentence whose full texts match against a regular expression ``pattern``. Args: doclike pattern: Valid regular expression against which to match document text, either as a string or compiled pattern object. alignment_mode: How character indices of regex matches snap to spaCy token boundaries. If "strict", only exact alignments are included (no snapping); if "contract", tokens completely within the character span are included; if "expand", tokens at least partially covered by the character span are included. Yields: Next matching ``Span``. """ for match in re.finditer(pattern, doclike.text): start_char_idx, end_char_idx = match.span() span = doclike.char_span( start_char_idx, end_char_idx, alignment_mode=alignment_mode ) # Doc.char_span() returns None if character indices don’t map to a valid span if span is not None: yield span
[ "def", "regex_matches", "(", "doclike", ":", "types", ".", "DocLike", ",", "pattern", ":", "str", "|", "Pattern", ",", "*", ",", "alignment_mode", ":", "str", "=", "\"strict\"", ",", "# Literal[\"strict\", \"contract\", \"expand\"]", ")", "->", "Iterable", "[", ...
https://github.com/chartbeat-labs/textacy/blob/40cd12fe953ef8be5958cff93ad8762262f3b757/src/textacy/extract/matches.py#L150-L180
tBuLi/symfit
3bcb66fbbe518f65a1339d6c62be715da4d77398
symfit/core/models.py
python
BaseModel.__eq__
(self, other)
``Model``'s are considered equal when they have the same dependent variables, and the same expressions for those dependent variables. The same is defined here as passing sympy == for the vars themselves, and as expr1 - expr2 == 0 for the expressions. For more info check the `sympy docs <https://github.com/sympy/sympy/wiki/Faq>`_. :param other: Instance of ``Model``. :return: bool
``Model``'s are considered equal when they have the same dependent variables, and the same expressions for those dependent variables. The same is defined here as passing sympy == for the vars themselves, and as expr1 - expr2 == 0 for the expressions. For more info check the `sympy docs <https://github.com/sympy/sympy/wiki/Faq>`_.
[ "Model", "s", "are", "considered", "equal", "when", "they", "have", "the", "same", "dependent", "variables", "and", "the", "same", "expressions", "for", "those", "dependent", "variables", ".", "The", "same", "is", "defined", "here", "as", "passing", "sympy", ...
def __eq__(self, other): """ ``Model``'s are considered equal when they have the same dependent variables, and the same expressions for those dependent variables. The same is defined here as passing sympy == for the vars themselves, and as expr1 - expr2 == 0 for the expressions. For more info check the `sympy docs <https://github.com/sympy/sympy/wiki/Faq>`_. :param other: Instance of ``Model``. :return: bool """ if len(self) is not len(other): return False else: for var_1, var_2 in zip(self, other): if var_1 != var_2: return False else: if not self[var_1].expand() == other[var_2].expand(): return False else: return True
[ "def", "__eq__", "(", "self", ",", "other", ")", ":", "if", "len", "(", "self", ")", "is", "not", "len", "(", "other", ")", ":", "return", "False", "else", ":", "for", "var_1", ",", "var_2", "in", "zip", "(", "self", ",", "other", ")", ":", "if...
https://github.com/tBuLi/symfit/blob/3bcb66fbbe518f65a1339d6c62be715da4d77398/symfit/core/models.py#L280-L300
abcminiuser/python-elgato-streamdeck
681c7e9c084981e9286a41abb05d85713cd16317
src/StreamDeck/Devices/StreamDeck.py
python
StreamDeck.key_count
(self)
return self.KEY_COUNT
Retrieves number of physical buttons on the attached StreamDeck device. :rtype: int :return: Number of physical buttons.
Retrieves number of physical buttons on the attached StreamDeck device.
[ "Retrieves", "number", "of", "physical", "buttons", "on", "the", "attached", "StreamDeck", "device", "." ]
def key_count(self): """ Retrieves number of physical buttons on the attached StreamDeck device. :rtype: int :return: Number of physical buttons. """ return self.KEY_COUNT
[ "def", "key_count", "(", "self", ")", ":", "return", "self", ".", "KEY_COUNT" ]
https://github.com/abcminiuser/python-elgato-streamdeck/blob/681c7e9c084981e9286a41abb05d85713cd16317/src/StreamDeck/Devices/StreamDeck.py#L195-L202
daler/pybedtools
ffe0d4bd2f32a0a5fc0cea049ee73773c4d57573
pybedtools/contrib/venn_maker.py
python
_dict_to_R_named_list
(d)
return "list(%s)" % ", ".join(items)
Calls _list_to_R_syntax for each item. Returns one big string.
Calls _list_to_R_syntax for each item. Returns one big string.
[ "Calls", "_list_to_R_syntax", "for", "each", "item", ".", "Returns", "one", "big", "string", "." ]
def _dict_to_R_named_list(d): """ Calls _list_to_R_syntax for each item. Returns one big string. """ items = [] for key, val in list(d.items()): items.append('"%s" = %s' % (key, _list_to_R_syntax(val))) return "list(%s)" % ", ".join(items)
[ "def", "_dict_to_R_named_list", "(", "d", ")", ":", "items", "=", "[", "]", "for", "key", ",", "val", "in", "list", "(", "d", ".", "items", "(", ")", ")", ":", "items", ".", "append", "(", "'\"%s\" = %s'", "%", "(", "key", ",", "_list_to_R_syntax", ...
https://github.com/daler/pybedtools/blob/ffe0d4bd2f32a0a5fc0cea049ee73773c4d57573/pybedtools/contrib/venn_maker.py#L45-L52
lesscpy/lesscpy
1172a1693df2f4bc929a88b1bebb920e666c0c9f
lesscpy/lessc/parser.py
python
LessParser.p_string_part_list
(self, p)
string_part_list : string_part
string_part_list : string_part
[ "string_part_list", ":", "string_part" ]
def p_string_part_list(self, p): """ string_part_list : string_part """ p[0] = [p[1]]
[ "def", "p_string_part_list", "(", "self", ",", "p", ")", ":", "p", "[", "0", "]", "=", "[", "p", "[", "1", "]", "]" ]
https://github.com/lesscpy/lesscpy/blob/1172a1693df2f4bc929a88b1bebb920e666c0c9f/lesscpy/lessc/parser.py#L844-L847
IndicoDataSolutions/Passage
af6e100804dfe332c88bd2cd192e93a807377887
passage/utils.py
python
iter_data
(*data, **kwargs)
[]
def iter_data(*data, **kwargs): size = kwargs.get('size', 128) batches = math.ceil(len(data[0]) / size) for b in range(batches): start = b * size end = (b + 1) * size if len(data) == 1: yield data[0][start:end] else: yield tuple([d[start:end] for d in data])
[ "def", "iter_data", "(", "*", "data", ",", "*", "*", "kwargs", ")", ":", "size", "=", "kwargs", ".", "get", "(", "'size'", ",", "128", ")", "batches", "=", "math", ".", "ceil", "(", "len", "(", "data", "[", "0", "]", ")", "/", "size", ")", "f...
https://github.com/IndicoDataSolutions/Passage/blob/af6e100804dfe332c88bd2cd192e93a807377887/passage/utils.py#L8-L18
sideeffects/SideFXLabs
956bc1eef6710882ae8d3a31b4a33dd631a56d5f
scripts/python/labsopui/wedge_tools.py
python
ParmContainer.getWedgeAttribType
(self)
return self.wedgeattribtype
[]
def getWedgeAttribType(self): return self.wedgeattribtype
[ "def", "getWedgeAttribType", "(", "self", ")", ":", "return", "self", ".", "wedgeattribtype" ]
https://github.com/sideeffects/SideFXLabs/blob/956bc1eef6710882ae8d3a31b4a33dd631a56d5f/scripts/python/labsopui/wedge_tools.py#L19-L20
home-assistant/supervisor
69c2517d5211b483fdfe968b0a2b36b672ee7ab2
supervisor/misc/tasks.py
python
Tasks._update_multicast
(self)
Check and run update of multicast.
Check and run update of multicast.
[ "Check", "and", "run", "update", "of", "multicast", "." ]
async def _update_multicast(self): """Check and run update of multicast.""" if not self.sys_plugins.multicast.need_update: return _LOGGER.info( "Found new Multicast version %s, updating", self.sys_plugins.multicast.latest_version, ) await self.sys_plugins.multicast.update()
[ "async", "def", "_update_multicast", "(", "self", ")", ":", "if", "not", "self", ".", "sys_plugins", ".", "multicast", ".", "need_update", ":", "return", "_LOGGER", ".", "info", "(", "\"Found new Multicast version %s, updating\"", ",", "self", ".", "sys_plugins", ...
https://github.com/home-assistant/supervisor/blob/69c2517d5211b483fdfe968b0a2b36b672ee7ab2/supervisor/misc/tasks.py#L290-L299
BEEmod/BEE2.4
02767f3cf476581789425ab308ca1bea978f6a74
src/editoritems_props.py
python
ItemProp.__eq__
(self, other: object)
return NotImplemented
Subclasses do not compare equal.
Subclasses do not compare equal.
[ "Subclasses", "do", "not", "compare", "equal", "." ]
def __eq__(self, other: object) -> bool: """Subclasses do not compare equal.""" if type(self) is type(other): return self.default == cast(ItemProp, other).default return NotImplemented
[ "def", "__eq__", "(", "self", ",", "other", ":", "object", ")", "->", "bool", ":", "if", "type", "(", "self", ")", "is", "type", "(", "other", ")", ":", "return", "self", ".", "default", "==", "cast", "(", "ItemProp", ",", "other", ")", ".", "def...
https://github.com/BEEmod/BEE2.4/blob/02767f3cf476581789425ab308ca1bea978f6a74/src/editoritems_props.py#L31-L35
apple/coremltools
141a83af482fcbdd5179807c9eaff9a7999c2c49
deps/protobuf/python/mox.py
python
MockAnything._Reset
(self)
Reset the state of this mock to record mode with an empty queue.
Reset the state of this mock to record mode with an empty queue.
[ "Reset", "the", "state", "of", "this", "mock", "to", "record", "mode", "with", "an", "empty", "queue", "." ]
def _Reset(self): """Reset the state of this mock to record mode with an empty queue.""" # Maintain a list of method calls we are expecting self._expected_calls_queue = deque() # Make sure we are in setup mode, not replay mode self._replay_mode = False
[ "def", "_Reset", "(", "self", ")", ":", "# Maintain a list of method calls we are expecting", "self", ".", "_expected_calls_queue", "=", "deque", "(", ")", "# Make sure we are in setup mode, not replay mode", "self", ".", "_replay_mode", "=", "False" ]
https://github.com/apple/coremltools/blob/141a83af482fcbdd5179807c9eaff9a7999c2c49/deps/protobuf/python/mox.py#L349-L356
matrix-org/synapse
8e57584a5859a9002759963eb546d523d2498a01
synapse/replication/tcp/protocol.py
python
ClientReplicationStreamProtocol.replicate
(self)
Send the subscription request to the server
Send the subscription request to the server
[ "Send", "the", "subscription", "request", "to", "the", "server" ]
def replicate(self): """Send the subscription request to the server""" logger.info("[%s] Subscribing to replication streams", self.id()) self.send_command(ReplicateCommand())
[ "def", "replicate", "(", "self", ")", ":", "logger", ".", "info", "(", "\"[%s] Subscribing to replication streams\"", ",", "self", ".", "id", "(", ")", ")", "self", ".", "send_command", "(", "ReplicateCommand", "(", ")", ")" ]
https://github.com/matrix-org/synapse/blob/8e57584a5859a9002759963eb546d523d2498a01/synapse/replication/tcp/protocol.py#L515-L519
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/lib/python2.7/site-packages/celery/result.py
python
allow_join_result
()
[]
def allow_join_result(): reset_value = task_join_will_block() _set_task_join_will_block(False) try: yield finally: _set_task_join_will_block(reset_value)
[ "def", "allow_join_result", "(", ")", ":", "reset_value", "=", "task_join_will_block", "(", ")", "_set_task_join_will_block", "(", "False", ")", "try", ":", "yield", "finally", ":", "_set_task_join_will_block", "(", "reset_value", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/lib/python2.7/site-packages/celery/result.py#L48-L54
stopstalk/stopstalk-deployment
10c3ab44c4ece33ae515f6888c15033db2004bb1
aws_lambda/spoj_aws_lambda_function/lambda_code/setuptools/dist.py
python
Distribution.has_contents_for
(self, package)
Return true if 'exclude_package(package)' would do something
Return true if 'exclude_package(package)' would do something
[ "Return", "true", "if", "exclude_package", "(", "package", ")", "would", "do", "something" ]
def has_contents_for(self, package): """Return true if 'exclude_package(package)' would do something""" pfx = package + '.' for p in self.iter_distribution_names(): if p == package or p.startswith(pfx): return True
[ "def", "has_contents_for", "(", "self", ",", "package", ")", ":", "pfx", "=", "package", "+", "'.'", "for", "p", "in", "self", ".", "iter_distribution_names", "(", ")", ":", "if", "p", "==", "package", "or", "p", ".", "startswith", "(", "pfx", ")", "...
https://github.com/stopstalk/stopstalk-deployment/blob/10c3ab44c4ece33ae515f6888c15033db2004bb1/aws_lambda/spoj_aws_lambda_function/lambda_code/setuptools/dist.py#L719-L726
scrapy/scrapy
b04cfa48328d5d5749dca6f50fa34e0cfc664c89
scrapy/commands/parse.py
python
Command.prepare_request
(self, spider, request, opts)
return request
[]
def prepare_request(self, spider, request, opts): def callback(response, **cb_kwargs): # memorize first request if not self.first_response: self.first_response = response # determine real callback cb = response.meta['_callback'] if not cb: if opts.callback: cb = opts.callback elif opts.rules and self.first_response == response: cb = self.get_callback_from_rules(spider, response) if not cb: logger.error('Cannot find a rule that matches %(url)r in spider: %(spider)s', {'url': response.url, 'spider': spider.name}) return else: cb = 'parse' if not callable(cb): cb_method = getattr(spider, cb, None) if callable(cb_method): cb = cb_method else: logger.error('Cannot find callback %(callback)r in spider: %(spider)s', {'callback': cb, 'spider': spider.name}) return # parse items and requests depth = response.meta['_depth'] items, requests = self.run_callback(response, cb, cb_kwargs) if opts.pipelines: itemproc = self.pcrawler.engine.scraper.itemproc for item in items: itemproc.process_item(item, spider) self.add_items(depth, items) self.add_requests(depth, requests) scraped_data = items if opts.output else [] if depth < opts.depth: for req in requests: req.meta['_depth'] = depth + 1 req.meta['_callback'] = req.callback req.callback = callback scraped_data += requests return scraped_data # update request meta if any extra meta was passed through the --meta/-m opts. if opts.meta: request.meta.update(opts.meta) # update cb_kwargs if any extra values were was passed through the --cbkwargs option. if opts.cbkwargs: request.cb_kwargs.update(opts.cbkwargs) request.meta['_depth'] = 1 request.meta['_callback'] = request.callback request.callback = callback return request
[ "def", "prepare_request", "(", "self", ",", "spider", ",", "request", ",", "opts", ")", ":", "def", "callback", "(", "response", ",", "*", "*", "cb_kwargs", ")", ":", "# memorize first request", "if", "not", "self", ".", "first_response", ":", "self", ".",...
https://github.com/scrapy/scrapy/blob/b04cfa48328d5d5749dca6f50fa34e0cfc664c89/scrapy/commands/parse.py#L160-L222
Xinkai/XwareDesktop
408a451b1548864ff5073e60c52e62082d2219cf
src/shared/thirdparty/aiohttp/multidict.py
python
MultiDict.copy
(self)
return cls(self.items(getall=True))
Returns a copy itself.
Returns a copy itself.
[ "Returns", "a", "copy", "itself", "." ]
def copy(self): """Returns a copy itself.""" cls = self.__class__ return cls(self.items(getall=True))
[ "def", "copy", "(", "self", ")", ":", "cls", "=", "self", ".", "__class__", "return", "cls", "(", "self", ".", "items", "(", "getall", "=", "True", ")", ")" ]
https://github.com/Xinkai/XwareDesktop/blob/408a451b1548864ff5073e60c52e62082d2219cf/src/shared/thirdparty/aiohttp/multidict.py#L56-L59
rembo10/headphones
b3199605be1ebc83a7a8feab6b1e99b64014187c
lib/biplist/__init__.py
python
FloatWrapper.__repr__
(self)
return "<FloatWrapper: %s>" % self.value
[]
def __repr__(self): return "<FloatWrapper: %s>" % self.value
[ "def", "__repr__", "(", "self", ")", ":", "return", "\"<FloatWrapper: %s>\"", "%", "self", ".", "value" ]
https://github.com/rembo10/headphones/blob/b3199605be1ebc83a7a8feab6b1e99b64014187c/lib/biplist/__init__.py#L456-L457
espnet/espnet
ea411f3f627b8f101c211e107d0ff7053344ac80
espnet/nets/pytorch_backend/e2e_tts_transformer.py
python
Transformer._integrate_with_spk_embed
(self, hs, spembs)
return hs
Integrate speaker embedding with hidden states. Args: hs (Tensor): Batch of hidden state sequences (B, Tmax, adim). spembs (Tensor): Batch of speaker embeddings (B, spk_embed_dim). Returns: Tensor: Batch of integrated hidden state sequences (B, Tmax, adim)
Integrate speaker embedding with hidden states.
[ "Integrate", "speaker", "embedding", "with", "hidden", "states", "." ]
def _integrate_with_spk_embed(self, hs, spembs): """Integrate speaker embedding with hidden states. Args: hs (Tensor): Batch of hidden state sequences (B, Tmax, adim). spembs (Tensor): Batch of speaker embeddings (B, spk_embed_dim). Returns: Tensor: Batch of integrated hidden state sequences (B, Tmax, adim) """ if self.spk_embed_integration_type == "add": # apply projection and then add to hidden states spembs = self.projection(F.normalize(spembs)) hs = hs + spembs.unsqueeze(1) elif self.spk_embed_integration_type == "concat": # concat hidden states with spk embeds and then apply projection spembs = F.normalize(spembs).unsqueeze(1).expand(-1, hs.size(1), -1) hs = self.projection(torch.cat([hs, spembs], dim=-1)) else: raise NotImplementedError("support only add or concat.") return hs
[ "def", "_integrate_with_spk_embed", "(", "self", ",", "hs", ",", "spembs", ")", ":", "if", "self", ".", "spk_embed_integration_type", "==", "\"add\"", ":", "# apply projection and then add to hidden states", "spembs", "=", "self", ".", "projection", "(", "F", ".", ...
https://github.com/espnet/espnet/blob/ea411f3f627b8f101c211e107d0ff7053344ac80/espnet/nets/pytorch_backend/e2e_tts_transformer.py#L1058-L1080
wistbean/learn_python3_spider
73c873f4845f4385f097e5057407d03dd37a117b
stackoverflow/venv/lib/python3.6/site-packages/hamcrest/library/number/ordering_comparison.py
python
greater_than
(value)
return OrderingComparison(value, operator.gt, 'greater than')
Matches if object is greater than a given value. :param value: The value to compare against.
Matches if object is greater than a given value.
[ "Matches", "if", "object", "is", "greater", "than", "a", "given", "value", "." ]
def greater_than(value): """Matches if object is greater than a given value. :param value: The value to compare against. """ return OrderingComparison(value, operator.gt, 'greater than')
[ "def", "greater_than", "(", "value", ")", ":", "return", "OrderingComparison", "(", "value", ",", "operator", ".", "gt", ",", "'greater than'", ")" ]
https://github.com/wistbean/learn_python3_spider/blob/73c873f4845f4385f097e5057407d03dd37a117b/stackoverflow/venv/lib/python3.6/site-packages/hamcrest/library/number/ordering_comparison.py#L26-L32
PacktPublishing/Mastering-OpenCV-4-with-Python
ea5372c6d8758ebc56ef5c775f9785d4427f81e6
Chapter08/01-chapter-content/contours_introduction.py
python
draw_contour_points
(img, cnts, color)
return img
Draw all points from a list of contours
Draw all points from a list of contours
[ "Draw", "all", "points", "from", "a", "list", "of", "contours" ]
def draw_contour_points(img, cnts, color): """Draw all points from a list of contours""" for cnt in cnts: # print(cnt.shape) # print(cnt) squeeze = np.squeeze(cnt) # print(squeeze.shape) # print(squeeze) for p in squeeze: # print(p) p = array_to_tuple(p) # print(p) cv2.circle(img, p, 10, color, -1) return img
[ "def", "draw_contour_points", "(", "img", ",", "cnts", ",", "color", ")", ":", "for", "cnt", "in", "cnts", ":", "# print(cnt.shape)", "# print(cnt)", "squeeze", "=", "np", ".", "squeeze", "(", "cnt", ")", "# print(squeeze.shape)", "# print(squeeze)", "for", "p...
https://github.com/PacktPublishing/Mastering-OpenCV-4-with-Python/blob/ea5372c6d8758ebc56ef5c775f9785d4427f81e6/Chapter08/01-chapter-content/contours_introduction.py#L26-L42