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
graphcore/examples
46d2b7687b829778369fc6328170a7b14761e5c6
applications/tensorflow/detection/yolov3/core/utils.py
python
postprocess_boxes
(pred_bbox, org_img_shape, input_size, score_threshold)
return np.concatenate([coors, scores[:, np.newaxis], classes[:, np.newaxis]], axis=-1)
Turn predicted boxes to image relative coordinate and remove invalid parts Args: pred_bbox: tensor of predicted boxes org_image_shape: original image shape (h,w) input_size: network input size, one integer, network input is a square image score_threshold: box score threshold, boxes below this threshold will be discarded
Turn predicted boxes to image relative coordinate and remove invalid parts Args: pred_bbox: tensor of predicted boxes org_image_shape: original image shape (h,w) input_size: network input size, one integer, network input is a square image score_threshold: box score threshold, boxes below this threshold will be discarded
[ "Turn", "predicted", "boxes", "to", "image", "relative", "coordinate", "and", "remove", "invalid", "parts", "Args", ":", "pred_bbox", ":", "tensor", "of", "predicted", "boxes", "org_image_shape", ":", "original", "image", "shape", "(", "h", "w", ")", "input_si...
def postprocess_boxes(pred_bbox, org_img_shape, input_size, score_threshold): """Turn predicted boxes to image relative coordinate and remove invalid parts Args: pred_bbox: tensor of predicted boxes org_image_shape: original image shape (h,w) input_size: network input size, one integer, network input is a square image score_threshold: box score threshold, boxes below this threshold will be discarded """ valid_scale = [0, np.inf] pred_bbox = np.array(pred_bbox) pred_xywh = pred_bbox[:, 0:4] pred_conf = pred_bbox[:, 4] pred_prob = pred_bbox[:, 5:] # # (1) (x, y, w, h) --> (xmin, ymin, xmax, ymax) pred_coor = np.concatenate([pred_xywh[:, :2] - pred_xywh[:, 2:] * 0.5, pred_xywh[:, :2] + pred_xywh[:, 2:] * 0.5], axis=-1) # # (2) (xmin, ymin, xmax, ymax) -> (xmin_org, ymin_org, xmax_org, ymax_org) org_h, org_w = org_img_shape resize_ratio = min(input_size / org_w, input_size / org_h) dw = (input_size - resize_ratio * org_w) / 2 dh = (input_size - resize_ratio * org_h) / 2 pred_coor[:, 0::2] = 1.0 * (pred_coor[:, 0::2] - dw) / resize_ratio pred_coor[:, 1::2] = 1.0 * (pred_coor[:, 1::2] - dh) / resize_ratio # # (3) clip some boxes those are out of range pred_coor = np.concatenate([np.maximum(pred_coor[:, :2], [0, 0]), np.minimum(pred_coor[:, 2:], [org_w - 1, org_h - 1])], axis=-1) invalid_mask = np.logical_or( (pred_coor[:, 0] > pred_coor[:, 2]), (pred_coor[:, 1] > pred_coor[:, 3])) pred_coor[invalid_mask] = 0 # # (4) discard some invalid boxes bboxes_scale = np.sqrt(np.multiply.reduce( pred_coor[:, 2:4] - pred_coor[:, 0:2], axis=-1)) scale_mask = np.logical_and( (valid_scale[0] < bboxes_scale), (bboxes_scale < valid_scale[1])) # # (5) discard some boxes with low scores classes = np.argmax(pred_prob, axis=-1) scores = pred_conf * pred_prob[np.arange(len(pred_coor)), classes] score_mask = scores > score_threshold mask = np.logical_and(scale_mask, score_mask) coors, scores, classes = pred_coor[mask], scores[mask], classes[mask] return np.concatenate([coors, scores[:, np.newaxis], classes[:, np.newaxis]], axis=-1)
[ "def", "postprocess_boxes", "(", "pred_bbox", ",", "org_img_shape", ",", "input_size", ",", "score_threshold", ")", ":", "valid_scale", "=", "[", "0", ",", "np", ".", "inf", "]", "pred_bbox", "=", "np", ".", "array", "(", "pred_bbox", ")", "pred_xywh", "="...
https://github.com/graphcore/examples/blob/46d2b7687b829778369fc6328170a7b14761e5c6/applications/tensorflow/detection/yolov3/core/utils.py#L164-L213
XX-net/XX-Net
a9898cfcf0084195fb7e69b6bc834e59aecdf14f
code/default/lib/noarch/hyper/packages/rfc3986/uri.py
python
URIReference.scheme_is_valid
(self, require=False)
return self._is_valid(self.scheme, SCHEME_MATCHER, require)
Determines if the scheme component is valid. :param str require: Set to ``True`` to require the presence of this component. :returns: ``True`` if the scheme is valid. ``False`` otherwise. :rtype: bool
Determines if the scheme component is valid.
[ "Determines", "if", "the", "scheme", "component", "is", "valid", "." ]
def scheme_is_valid(self, require=False): """Determines if the scheme component is valid. :param str require: Set to ``True`` to require the presence of this component. :returns: ``True`` if the scheme is valid. ``False`` otherwise. :rtype: bool """ return self._is_valid(self.scheme, SCHEME_MATCHER, require)
[ "def", "scheme_is_valid", "(", "self", ",", "require", "=", "False", ")", ":", "return", "self", ".", "_is_valid", "(", "self", ".", "scheme", ",", "SCHEME_MATCHER", ",", "require", ")" ]
https://github.com/XX-net/XX-Net/blob/a9898cfcf0084195fb7e69b6bc834e59aecdf14f/code/default/lib/noarch/hyper/packages/rfc3986/uri.py#L212-L220
nadineproject/nadine
c41c8ef7ffe18f1853029c97eecc329039b4af6c
doors/core.py
python
TestDoorController.test_connection
(self)
return True
[]
def test_connection(self): return True
[ "def", "test_connection", "(", "self", ")", ":", "return", "True" ]
https://github.com/nadineproject/nadine/blob/c41c8ef7ffe18f1853029c97eecc329039b4af6c/doors/core.py#L331-L332
21dotco/two1-python
4e833300fd5a58363e3104ed4c097631e5d296d3
two1/bitcoin/coinbase.py
python
CoinbaseTransactionBuilder.build
(self, enonce1, enonce2, bitshare=True)
return tx_type(Transaction.DEFAULT_TRANSACTION_VERSION, [cb_input], self.outputs, self.lock_time)
Builds a coinbase txn and returns it. If bitshare == True, padding is added to the coinbase input script to align the length of the txn without the last output & locktime to a 512-bit boundary. Args: enonce1 (bytes): byte stream to place in the coinbase input script. Must be enonce1_len bytes long. enonce2 (bytes): byte stream to place in the coinbase input script. Must be enonce2_len bytes long. bitshare (bool): True if this will be used for a 21 Bitshare device, False otherwise.
Builds a coinbase txn and returns it. If bitshare == True, padding is added to the coinbase input script to align the length of the txn without the last output & locktime to a 512-bit boundary.
[ "Builds", "a", "coinbase", "txn", "and", "returns", "it", ".", "If", "bitshare", "==", "True", "padding", "is", "added", "to", "the", "coinbase", "input", "script", "to", "align", "the", "length", "of", "the", "txn", "without", "the", "last", "output", "...
def build(self, enonce1, enonce2, bitshare=True): """ Builds a coinbase txn and returns it. If bitshare == True, padding is added to the coinbase input script to align the length of the txn without the last output & locktime to a 512-bit boundary. Args: enonce1 (bytes): byte stream to place in the coinbase input script. Must be enonce1_len bytes long. enonce2 (bytes): byte stream to place in the coinbase input script. Must be enonce2_len bytes long. bitshare (bool): True if this will be used for a 21 Bitshare device, False otherwise. """ if len(enonce1) != self.enonce1_len: raise ValueError("len(enonce1) does not match enonce1_len") if len(enonce2) != self.enonce2_len: raise ValueError("len(enonce2) does not match enonce2_len") padding = self.bitshare_padding if bitshare else None cb_input = self.build_input(enonce1, enonce2, padding) tx_type = BitshareCoinbaseTransaction if bitshare else Transaction return tx_type(Transaction.DEFAULT_TRANSACTION_VERSION, [cb_input], self.outputs, self.lock_time)
[ "def", "build", "(", "self", ",", "enonce1", ",", "enonce2", ",", "bitshare", "=", "True", ")", ":", "if", "len", "(", "enonce1", ")", "!=", "self", ".", "enonce1_len", ":", "raise", "ValueError", "(", "\"len(enonce1) does not match enonce1_len\"", ")", "if"...
https://github.com/21dotco/two1-python/blob/4e833300fd5a58363e3104ed4c097631e5d296d3/two1/bitcoin/coinbase.py#L151-L178
open-cogsci/OpenSesame
c4a3641b097a80a76937edbd8c365f036bcc9705
opensesame_extensions/help/help.py
python
help.populate_help_menu
(self)
desc: Is collected when the sitemap is done loading, and populates the menu.
desc: Is collected when the sitemap is done loading, and populates the menu.
[ "desc", ":", "Is", "collected", "when", "the", "sitemap", "is", "done", "loading", "and", "populates", "the", "menu", "." ]
def populate_help_menu(self): """ desc: Is collected when the sitemap is done loading, and populates the menu. """ if self._get_sitemap_thread.sitemap is None: return try: _dict = safe_yaml_load(self._get_sitemap_thread.sitemap) except yaml.scanner.ScannerError: # If the sitemap was loaded but was not a valid yaml string. This # can happen for example when a captive portal returns something # invalid return if not isinstance(_dict, dict): return self.menu.clear() menu = self.build_menu( self.menu, cfg.online_help_base_url, _(u'Online help'), _dict, sub_menu=cfg.online_help_psychopy ) if menu is not None: self.action_online_help = self.menu.addMenu(menu) if cfg.online_help_psychopy: menu = self.psychopy_help_menu() if menu is not None: self.action_psychopy_help = self.menu.addMenu(menu) self.menu.addSeparator()
[ "def", "populate_help_menu", "(", "self", ")", ":", "if", "self", ".", "_get_sitemap_thread", ".", "sitemap", "is", "None", ":", "return", "try", ":", "_dict", "=", "safe_yaml_load", "(", "self", ".", "_get_sitemap_thread", ".", "sitemap", ")", "except", "ya...
https://github.com/open-cogsci/OpenSesame/blob/c4a3641b097a80a76937edbd8c365f036bcc9705/opensesame_extensions/help/help.py#L139-L172
adonno/Home-AssistantConfig
8038c0143c6a990e409951202bb1bda149fcbaf7
custom_components/hacs/hacsbase/__init__.py
python
Hacs.register_repository
(self, full_name, category, check=True)
Register a repository.
Register a repository.
[ "Register", "a", "repository", "." ]
async def register_repository(self, full_name, category, check=True): """Register a repository.""" from ..repositories.repository import RERPOSITORY_CLASSES if full_name in self.common.skip: self.logger.debug(f"Skipping {full_name}") return if category not in RERPOSITORY_CLASSES: self.logger.error(f"{category} is not a valid repository category.") return False repository = RERPOSITORY_CLASSES[category](full_name) if check: try: await repository.registration() if repository.validate.errors: self.common.skip.append(repository.information.full_name) if not self.system.status.startup: self.logger.error(f"Validation for {full_name} failed.") return repository.validate.errors repository.logger.info("Registration complete") except AIOGitHubException as exception: self.logger.debug(self.github.ratelimits.remaining) self.logger.debug(self.github.ratelimits.reset_utc) self.common.skip.append(repository.information.full_name) if not self.system.status.startup: self.logger.error( f"Validation for {full_name} failed with {exception}." ) return self.repositories.append(repository)
[ "async", "def", "register_repository", "(", "self", ",", "full_name", ",", "category", ",", "check", "=", "True", ")", ":", "from", ".", ".", "repositories", ".", "repository", "import", "RERPOSITORY_CLASSES", "if", "full_name", "in", "self", ".", "common", ...
https://github.com/adonno/Home-AssistantConfig/blob/8038c0143c6a990e409951202bb1bda149fcbaf7/custom_components/hacs/hacsbase/__init__.py#L116-L147
PhoenixDL/rising
6de193375dcaac35605163c35cec259c9a2116d1
rising/utils/affine.py
python
matrix_to_homogeneous
(batch: torch.Tensor)
return torch.cat([batch, missing], dim=-2)
Transforms a given transformation matrix to a homogeneous transformation matrix. Args: batch: the batch of matrices to convert [N, dim, dim] Returns: torch.Tensor: the converted batch of matrices
Transforms a given transformation matrix to a homogeneous transformation matrix.
[ "Transforms", "a", "given", "transformation", "matrix", "to", "a", "homogeneous", "transformation", "matrix", "." ]
def matrix_to_homogeneous(batch: torch.Tensor) -> torch.Tensor: """ Transforms a given transformation matrix to a homogeneous transformation matrix. Args: batch: the batch of matrices to convert [N, dim, dim] Returns: torch.Tensor: the converted batch of matrices """ if batch.size(-1) == batch.size(-2): missing = batch.new_zeros(size=(*batch.shape[:-1], 1)) batch = torch.cat([batch, missing], dim=-1) missing = torch.zeros( (batch.size(0), *[1 for tmp in batch.shape[1:-1]], batch.size(-1)), device=batch.device, dtype=batch.dtype ) missing[..., -1] = 1 return torch.cat([batch, missing], dim=-2)
[ "def", "matrix_to_homogeneous", "(", "batch", ":", "torch", ".", "Tensor", ")", "->", "torch", ".", "Tensor", ":", "if", "batch", ".", "size", "(", "-", "1", ")", "==", "batch", ".", "size", "(", "-", "2", ")", ":", "missing", "=", "batch", ".", ...
https://github.com/PhoenixDL/rising/blob/6de193375dcaac35605163c35cec259c9a2116d1/rising/utils/affine.py#L23-L45
gramps-project/gramps
04d4651a43eb210192f40a9f8c2bad8ee8fa3753
gramps/plugins/db/dbapi/dbapi.py
python
DBAPI._txn_commit
(self)
Lowlevel interface to the backend transaction. Executes a db END;
Lowlevel interface to the backend transaction. Executes a db END;
[ "Lowlevel", "interface", "to", "the", "backend", "transaction", ".", "Executes", "a", "db", "END", ";" ]
def _txn_commit(self): """ Lowlevel interface to the backend transaction. Executes a db END; """ if self.transaction == None: _LOG.debug(" DBAPI %s transaction commit", hex(id(self))) self.dbapi.commit()
[ "def", "_txn_commit", "(", "self", ")", ":", "if", "self", ".", "transaction", "==", "None", ":", "_LOG", ".", "debug", "(", "\" DBAPI %s transaction commit\"", ",", "hex", "(", "id", "(", "self", ")", ")", ")", "self", ".", "dbapi", ".", "commit", ...
https://github.com/gramps-project/gramps/blob/04d4651a43eb210192f40a9f8c2bad8ee8fa3753/gramps/plugins/db/dbapi/dbapi.py#L211-L218
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/geometry/hyperplane_arrangement/hyperplane.py
python
Hyperplane.dimension
(self)
return self.linear_part().dimension()
r""" The dimension of the hyperplane. OUTPUT: An integer. EXAMPLES:: sage: H.<x,y,z> = HyperplaneArrangements(QQ) sage: h = x + y + z - 1 sage: h.dimension() 2
r""" The dimension of the hyperplane.
[ "r", "The", "dimension", "of", "the", "hyperplane", "." ]
def dimension(self): r""" The dimension of the hyperplane. OUTPUT: An integer. EXAMPLES:: sage: H.<x,y,z> = HyperplaneArrangements(QQ) sage: h = x + y + z - 1 sage: h.dimension() 2 """ return self.linear_part().dimension()
[ "def", "dimension", "(", "self", ")", ":", "return", "self", ".", "linear_part", "(", ")", ".", "dimension", "(", ")" ]
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/geometry/hyperplane_arrangement/hyperplane.py#L422-L437
edfungus/Crouton
ada98b3930192938a48909072b45cb84b945f875
clients/esp8266_clients/venv/lib/python2.7/site-packages/setuptools/dist.py
python
Distribution.handle_display_options
(self, option_order)
If there were any non-global "display-only" options (--help-commands or the metadata display options) on the command line, display the requested info and return true; else return false.
If there were any non-global "display-only" options (--help-commands or the metadata display options) on the command line, display the requested info and return true; else return false.
[ "If", "there", "were", "any", "non", "-", "global", "display", "-", "only", "options", "(", "--", "help", "-", "commands", "or", "the", "metadata", "display", "options", ")", "on", "the", "command", "line", "display", "the", "requested", "info", "and", "...
def handle_display_options(self, option_order): """If there were any non-global "display-only" options (--help-commands or the metadata display options) on the command line, display the requested info and return true; else return false. """ import sys if PY2 or self.help_commands: return _Distribution.handle_display_options(self, option_order) # Stdout may be StringIO (e.g. in tests) import io if not isinstance(sys.stdout, io.TextIOWrapper): return _Distribution.handle_display_options(self, option_order) # Don't wrap stdout if utf-8 is already the encoding. Provides # workaround for #334. if sys.stdout.encoding.lower() in ('utf-8', 'utf8'): return _Distribution.handle_display_options(self, option_order) # Print metadata in UTF-8 no matter the platform encoding = sys.stdout.encoding errors = sys.stdout.errors newline = sys.platform != 'win32' and '\n' or None line_buffering = sys.stdout.line_buffering sys.stdout = io.TextIOWrapper( sys.stdout.detach(), 'utf-8', errors, newline, line_buffering) try: return _Distribution.handle_display_options(self, option_order) finally: sys.stdout = io.TextIOWrapper( sys.stdout.detach(), encoding, errors, newline, line_buffering)
[ "def", "handle_display_options", "(", "self", ",", "option_order", ")", ":", "import", "sys", "if", "PY2", "or", "self", ".", "help_commands", ":", "return", "_Distribution", ".", "handle_display_options", "(", "self", ",", "option_order", ")", "# Stdout may be St...
https://github.com/edfungus/Crouton/blob/ada98b3930192938a48909072b45cb84b945f875/clients/esp8266_clients/venv/lib/python2.7/site-packages/setuptools/dist.py#L670-L703
apache/libcloud
90971e17bfd7b6bb97b2489986472c531cc8e140
libcloud/compute/drivers/kamatera.py
python
KamateraNodeDriver.ex_get_node
( self, id=None, name=None, state=NodeState.UNKNOWN, public_ips=None, private_ips=None, size=None, image=None, created_at=None, location=None, dailybackup=None, managed=None, billingcycle=None, generated_password=None, create_command_id=None, poweronaftercreate=None, )
return Node( id=id, name=name, state=state, public_ips=public_ips, private_ips=private_ips, driver=self, size=size, image=image, created_at=created_at, extra=extra, )
Get a Kamatera node object. :param id: Node ID (optional) :type id: ``str`` :param name: Node name (optional) :type name: ``str`` :param state: Node state (optional) :type state: :class:`libcloud.compute.types.NodeState` :param public_ips: Node public IPS. (optional) :type public_ips: ``list`` of :str: :param private_ips: Node private IPS. (optional) :type private_ips: ``list`` of :str: :param size: node size. (optional) :type size: :class:`.NodeSize` :param image: Node OS Image. (optional) :type image: :class:`.NodeImage` :param created_at: Node creation time. (optional) :type created_at: ``datetime.datetime`` :param location: Node datacenter. (optional) :type location: :class:`.NodeLocation` :param dailybackup: create daily backups for the node (optional) :type dailybackup: ``bool`` :param managed: provide managed support for the node (optional) :type managed: ``bool`` :param billingcycle: billing cycle (hourly / monthly) (optional) :type billingcycle: ``str`` :param generated_password: server generated password (optional) :type generated_password: ``str`` :param create_command_id: creation task command ID (optional) :type create_command_id: ``int`` :param poweronaftercreate: power on the node after create (optional) :type poweronaftercreate: ``bool`` :return: The node. :rtype: :class:`.Node`
Get a Kamatera node object.
[ "Get", "a", "Kamatera", "node", "object", "." ]
def ex_get_node( self, id=None, name=None, state=NodeState.UNKNOWN, public_ips=None, private_ips=None, size=None, image=None, created_at=None, location=None, dailybackup=None, managed=None, billingcycle=None, generated_password=None, create_command_id=None, poweronaftercreate=None, ): """ Get a Kamatera node object. :param id: Node ID (optional) :type id: ``str`` :param name: Node name (optional) :type name: ``str`` :param state: Node state (optional) :type state: :class:`libcloud.compute.types.NodeState` :param public_ips: Node public IPS. (optional) :type public_ips: ``list`` of :str: :param private_ips: Node private IPS. (optional) :type private_ips: ``list`` of :str: :param size: node size. (optional) :type size: :class:`.NodeSize` :param image: Node OS Image. (optional) :type image: :class:`.NodeImage` :param created_at: Node creation time. (optional) :type created_at: ``datetime.datetime`` :param location: Node datacenter. (optional) :type location: :class:`.NodeLocation` :param dailybackup: create daily backups for the node (optional) :type dailybackup: ``bool`` :param managed: provide managed support for the node (optional) :type managed: ``bool`` :param billingcycle: billing cycle (hourly / monthly) (optional) :type billingcycle: ``str`` :param generated_password: server generated password (optional) :type generated_password: ``str`` :param create_command_id: creation task command ID (optional) :type create_command_id: ``int`` :param poweronaftercreate: power on the node after create (optional) :type poweronaftercreate: ``bool`` :return: The node. :rtype: :class:`.Node` """ extra = {} if location: extra["location"] = location if dailybackup is not None: extra["dailybackup"] = dailybackup if managed is not None: extra["managed"] = managed if billingcycle is not None: extra["billingcycle"] = billingcycle if generated_password is not None: extra["generated_password"] = generated_password if create_command_id is not None: extra["create_command_id"] = create_command_id if poweronaftercreate is not None: extra["poweronaftercreate"] = poweronaftercreate return Node( id=id, name=name, state=state, public_ips=public_ips, private_ips=private_ips, driver=self, size=size, image=image, created_at=created_at, extra=extra, )
[ "def", "ex_get_node", "(", "self", ",", "id", "=", "None", ",", "name", "=", "None", ",", "state", "=", "NodeState", ".", "UNKNOWN", ",", "public_ips", "=", "None", ",", "private_ips", "=", "None", ",", "size", "=", "None", ",", "image", "=", "None",...
https://github.com/apache/libcloud/blob/90971e17bfd7b6bb97b2489986472c531cc8e140/libcloud/compute/drivers/kamatera.py#L576-L671
voxelmorph/voxelmorph
92641b4808aefd3762bb2680d2b2aa8a491298ac
voxelmorph/py/utils.py
python
vol_to_sdt
(X_label, sdt=True, sdt_vol_resize=1)
return X_dt
Computes the signed distance transform from a volume.
Computes the signed distance transform from a volume.
[ "Computes", "the", "signed", "distance", "transform", "from", "a", "volume", "." ]
def vol_to_sdt(X_label, sdt=True, sdt_vol_resize=1): """ Computes the signed distance transform from a volume. """ X_dt = signed_dist_trf(X_label) if not (sdt_vol_resize == 1): if not isinstance(sdt_vol_resize, (list, tuple)): sdt_vol_resize = [sdt_vol_resize] * X_dt.ndim if any([f != 1 for f in sdt_vol_resize]): X_dt = scipy.ndimage.interpolation.zoom(X_dt, sdt_vol_resize, order=1, mode='reflect') if not sdt: X_dt = np.abs(X_dt) return X_dt
[ "def", "vol_to_sdt", "(", "X_label", ",", "sdt", "=", "True", ",", "sdt_vol_resize", "=", "1", ")", ":", "X_dt", "=", "signed_dist_trf", "(", "X_label", ")", "if", "not", "(", "sdt_vol_resize", "==", "1", ")", ":", "if", "not", "isinstance", "(", "sdt_...
https://github.com/voxelmorph/voxelmorph/blob/92641b4808aefd3762bb2680d2b2aa8a491298ac/voxelmorph/py/utils.py#L385-L401
SanPen/GridCal
d3f4566d2d72c11c7e910c9d162538ef0e60df31
src/GridCal/Gui/GridEditorWidget/transformer2w_graphics.py
python
TransformerGraphicItem.setEndPos
(self, endpos)
Set the starting position @param endpos: @return:
Set the starting position
[ "Set", "the", "starting", "position" ]
def setEndPos(self, endpos): """ Set the starting position @param endpos: @return: """ self.pos2 = endpos self.redraw()
[ "def", "setEndPos", "(", "self", ",", "endpos", ")", ":", "self", ".", "pos2", "=", "endpos", "self", ".", "redraw", "(", ")" ]
https://github.com/SanPen/GridCal/blob/d3f4566d2d72c11c7e910c9d162538ef0e60df31/src/GridCal/Gui/GridEditorWidget/transformer2w_graphics.py#L701-L708
JulianEberius/SublimePythonIDE
d70e40abc0c9f347af3204c7b910e0d6bfd6e459
server/lib/python2/rope/contrib/generate.py
python
create_generate
(kind, project, resource, offset)
return generate(project, resource, offset)
A factory for creating `Generate` objects `kind` can be 'variable', 'function', 'class', 'module' or 'package'.
A factory for creating `Generate` objects
[ "A", "factory", "for", "creating", "Generate", "objects" ]
def create_generate(kind, project, resource, offset): """A factory for creating `Generate` objects `kind` can be 'variable', 'function', 'class', 'module' or 'package'. """ generate = eval('Generate' + kind.title()) return generate(project, resource, offset)
[ "def", "create_generate", "(", "kind", ",", "project", ",", "resource", ",", "offset", ")", ":", "generate", "=", "eval", "(", "'Generate'", "+", "kind", ".", "title", "(", ")", ")", "return", "generate", "(", "project", ",", "resource", ",", "offset", ...
https://github.com/JulianEberius/SublimePythonIDE/blob/d70e40abc0c9f347af3204c7b910e0d6bfd6e459/server/lib/python2/rope/contrib/generate.py#L6-L14
mesonbuild/meson
a22d0f9a0a787df70ce79b05d0c45de90a970048
mesonbuild/build.py
python
Executable.get_import_filename
(self)
return self.import_filename
The name of the import library that will be outputted by the compiler Returns None if there is no import library required for this platform
The name of the import library that will be outputted by the compiler
[ "The", "name", "of", "the", "import", "library", "that", "will", "be", "outputted", "by", "the", "compiler" ]
def get_import_filename(self) -> T.Optional[str]: """ The name of the import library that will be outputted by the compiler Returns None if there is no import library required for this platform """ return self.import_filename
[ "def", "get_import_filename", "(", "self", ")", "->", "T", ".", "Optional", "[", "str", "]", ":", "return", "self", ".", "import_filename" ]
https://github.com/mesonbuild/meson/blob/a22d0f9a0a787df70ce79b05d0c45de90a970048/mesonbuild/build.py#L1854-L1860
grow/grow
97fc21730b6a674d5d33948d94968e79447ce433
grow/documents/document_fields.py
python
DocumentFields.__getitem__
(self, key)
return self._data[key]
[]
def __getitem__(self, key): return self._data[key]
[ "def", "__getitem__", "(", "self", ",", "key", ")", ":", "return", "self", ".", "_data", "[", "key", "]" ]
https://github.com/grow/grow/blob/97fc21730b6a674d5d33948d94968e79447ce433/grow/documents/document_fields.py#L15-L16
googleads/google-ads-python
2a1d6062221f6aad1992a6bcca0e7e4a93d2db86
google/ads/googleads/v9/services/services/topic_constant_service/client.py
python
TopicConstantServiceClient.topic_constant_path
(topic_id: str,)
return "topicConstants/{topic_id}".format(topic_id=topic_id,)
Return a fully-qualified topic_constant string.
Return a fully-qualified topic_constant string.
[ "Return", "a", "fully", "-", "qualified", "topic_constant", "string", "." ]
def topic_constant_path(topic_id: str,) -> str: """Return a fully-qualified topic_constant string.""" return "topicConstants/{topic_id}".format(topic_id=topic_id,)
[ "def", "topic_constant_path", "(", "topic_id", ":", "str", ",", ")", "->", "str", ":", "return", "\"topicConstants/{topic_id}\"", ".", "format", "(", "topic_id", "=", "topic_id", ",", ")" ]
https://github.com/googleads/google-ads-python/blob/2a1d6062221f6aad1992a6bcca0e7e4a93d2db86/google/ads/googleads/v9/services/services/topic_constant_service/client.py#L175-L177
frenetic-lang/pyretic
30462692f3e9675158862755955b44f3a37ea21c
pyretic/core/netkat.py
python
netkat_backend.generate_classifier
(cls, pol, switch_cnt, multistage, print_json=False, return_json=False, server_port=NETKAT_PORT)
Generate JSON or classifier output from compiling an input policy.
Generate JSON or classifier output from compiling an input policy.
[ "Generate", "JSON", "or", "classifier", "output", "from", "compiling", "an", "input", "policy", "." ]
def generate_classifier(cls, pol, switch_cnt, multistage, print_json=False, return_json=False, server_port=NETKAT_PORT): """ Generate JSON or classifier output from compiling an input policy. """ def use_explicit_switches(pol): """ Ensure every switch in the network gets reflected in the policy sent to netkat. This is because netkat generates a separate copy of the policy per switch, and it is necessary for it to know that a switch appears in the policy through the policy itself.""" from pyretic.core.language import match, identity pred_policy = None used_cnt = switch_cnt if switch_cnt else 0 for i in range(1, used_cnt + 1): if pred_policy is None: pred_policy = match(switch = i) else: pred_policy |= match(switch = i) if pred_policy is None: pred_policy = identity return pred_policy >> pol def curl_channel_compilation(pol): """ Communicate with the netKAT compile server through curl. """ import subprocess f = open('/tmp/in.json', 'w') if print_json: cls.log().error("The policy being compiled to netkat is:") cls.log().error(str(pol)) f.write(compile_to_netkat(pol)) f.close() try: output = subprocess.check_output(['curl', '-X', 'POST', 'localhost:%d/compile' % server_port, '--data-binary', '@/tmp/in.json', '-D', '/tmp/header.txt']) f = open('/tmp/out.json', 'w') f.write(output) f.close() except subprocess.CalledProcessError: print "error in calling frenetic" if print_json: cls.log().error("This is the json output:") cls.log().error(str(output)) f = open('/tmp/header.txt') time = 0 for line in f.readlines(): if line.startswith('x-compile-time:'): time = float(line[line.index(":") + 1:-1]) break return (output, time) def httplib_channel_compilation(pol): json_input = compile_to_netkat(pol) write_to_file(json_input, TEMP_INPUT) if print_json: cls.log().error("This is the JSON input:") cls.log().error(str(json_input)) headers = {"Content-Type": "application/x-www-form-urlencoded", "Accept": "*/*"} ctime = '0' try: # TODO: make the connection persist across compilations conn = httplib.HTTPConnection("localhost", server_port) conn.request("POST", NETKAT_DOM, json_input, headers) resp = conn.getresponse() ctime = resp.getheader(NETKAT_TIME_HDR, "-1") netkat_out = resp.read() write_to_file(ctime, TEMP_HEADERS) write_to_file(netkat_out, TEMP_OUTPUT) if print_json: cls.log().error("This is the JSON output:") cls.log().error(netkat_out) conn.close() except Exception as e: cls.log().error(("Compiling with the netkat compilation" + " server failed. (%s, port %d") % ( str(e), server_port)) sys.exit(0) return (netkat_out, ctime) pol = use_explicit_switches(pol) qdict = {str(id(b)) : b for b in get_buckets_list(pol)} vlan_offset_nbits = vlan_preprocess(pol) # return curl_channel_compilation(pol) (cls_json, ctime) = httplib_channel_compilation(pol) if not return_json: classifier = json_to_classifier(cls_json, qdict, multistage, vlan_offset_nbits) return (classifier, ctime) else: return (cls_json, ctime)
[ "def", "generate_classifier", "(", "cls", ",", "pol", ",", "switch_cnt", ",", "multistage", ",", "print_json", "=", "False", ",", "return_json", "=", "False", ",", "server_port", "=", "NETKAT_PORT", ")", ":", "def", "use_explicit_switches", "(", "pol", ")", ...
https://github.com/frenetic-lang/pyretic/blob/30462692f3e9675158862755955b44f3a37ea21c/pyretic/core/netkat.py#L70-L163
Raytone-D/puppet
6212d4306d520c60f5f168aec3b79ee56071ee6b
puppet/util.py
python
go_to_top
(h_root: int, timeout: float = 1.0, interval: float = 0.01)
窗口置顶
窗口置顶
[ "窗口置顶" ]
def go_to_top(h_root: int, timeout: float = 1.0, interval: float = 0.01): """窗口置顶""" keyboard.send('alt') # ! enables calls to SwitchToThisWindow if user32.SwitchToThisWindow(h_root, True) != 0: stop = int(timeout/interval) for _ in range(stop): if user32.GetForegroundWindow() == h_root: return True time.sleep(0.5 if user32.IsIconic(h_root) else interval)
[ "def", "go_to_top", "(", "h_root", ":", "int", ",", "timeout", ":", "float", "=", "1.0", ",", "interval", ":", "float", "=", "0.01", ")", ":", "keyboard", ".", "send", "(", "'alt'", ")", "# ! enables calls to SwitchToThisWindow", "if", "user32", ".", "Swit...
https://github.com/Raytone-D/puppet/blob/6212d4306d520c60f5f168aec3b79ee56071ee6b/puppet/util.py#L250-L259
mysql/mysql-connector-python
c5460bcbb0dff8e4e48bf4af7a971c89bf486d85
lib/mysqlx/statement.py
python
Statement.exec_counter
(self)
return self._exec_counter
int: The number of times this statement was executed.
int: The number of times this statement was executed.
[ "int", ":", "The", "number", "of", "times", "this", "statement", "was", "executed", "." ]
def exec_counter(self): """int: The number of times this statement was executed.""" return self._exec_counter
[ "def", "exec_counter", "(", "self", ")", ":", "return", "self", ".", "_exec_counter" ]
https://github.com/mysql/mysql-connector-python/blob/c5460bcbb0dff8e4e48bf4af7a971c89bf486d85/lib/mysqlx/statement.py#L167-L169
boto/boto
b2a6f08122b2f1b89888d2848e730893595cd001
boto/sts/__init__.py
python
regions
()
return get_regions('sts', connection_cls=STSConnection)
Get all available regions for the STS service. :rtype: list :return: A list of :class:`boto.regioninfo.RegionInfo` instances
Get all available regions for the STS service.
[ "Get", "all", "available", "regions", "for", "the", "STS", "service", "." ]
def regions(): """ Get all available regions for the STS service. :rtype: list :return: A list of :class:`boto.regioninfo.RegionInfo` instances """ return get_regions('sts', connection_cls=STSConnection)
[ "def", "regions", "(", ")", ":", "return", "get_regions", "(", "'sts'", ",", "connection_cls", "=", "STSConnection", ")" ]
https://github.com/boto/boto/blob/b2a6f08122b2f1b89888d2848e730893595cd001/boto/sts/__init__.py#L28-L35
heynemann/pyvows
5b0e2a202603c1fc00d1fa0c6134c92c15b7e2b7
pyvows/reporting/coverage.py
python
VowsCoverageReporter.format_class_coverage
(self, cover_character, klass, space1, progress, coverage, space2, lines, cover_threshold)
return ' {0} {klass}{space1}\t{progress}{coverage}{space2} {lines}'.format( # TODO: # * remove manual spacing, use .format() alignment cover_character, klass=klass, space1=space1, progress=dim('•' * progress), coverage=coverage, space2=space2, lines=lines )
Accepts coverage data for a class and returns a formatted string (intended for humans).
Accepts coverage data for a class and returns a formatted string (intended for humans).
[ "Accepts", "coverage", "data", "for", "a", "class", "and", "returns", "a", "formatted", "string", "(", "intended", "for", "humans", ")", "." ]
def format_class_coverage(self, cover_character, klass, space1, progress, coverage, space2, lines, cover_threshold): '''Accepts coverage data for a class and returns a formatted string (intended for humans). ''' # FIXME: # Doesn't this *actually* print coverage for a module, and not a class? # preprocess raw data... klass = klass.lstrip('.') klass = blue(klass) MET_THRESHOLD = coverage >= cover_threshold coverage = '{prefix}{coverage:.1%}'.format( prefix=' ' if (coverage > 0.000) else '', coverage=coverage ) if MET_THRESHOLD: coverage = bold(coverage) coverage = white(coverage) # ...then format return ' {0} {klass}{space1}\t{progress}{coverage}{space2} {lines}'.format( # TODO: # * remove manual spacing, use .format() alignment cover_character, klass=klass, space1=space1, progress=dim('•' * progress), coverage=coverage, space2=space2, lines=lines )
[ "def", "format_class_coverage", "(", "self", ",", "cover_character", ",", "klass", ",", "space1", ",", "progress", ",", "coverage", ",", "space2", ",", "lines", ",", "cover_threshold", ")", ":", "# FIXME:", "# Doesn't this *actually* print coverage for a module,...
https://github.com/heynemann/pyvows/blob/5b0e2a202603c1fc00d1fa0c6134c92c15b7e2b7/pyvows/reporting/coverage.py#L134-L168
frappe/frappe
b64cab6867dfd860f10ccaf41a4ec04bc890b583
frappe/client.py
python
insert_many
(docs=None)
return out
Insert multiple documents :param docs: JSON or list of dict objects to be inserted in one request
Insert multiple documents
[ "Insert", "multiple", "documents" ]
def insert_many(docs=None): '''Insert multiple documents :param docs: JSON or list of dict objects to be inserted in one request''' if isinstance(docs, str): docs = json.loads(docs) out = [] if len(docs) > 200: frappe.throw(_('Only 200 inserts allowed in one request')) for doc in docs: if doc.get("parent") and doc.get("parenttype"): # inserting a child record parent = frappe.get_doc(doc.get("parenttype"), doc.get("parent")) parent.append(doc.get("parentfield"), doc) parent.save() out.append(parent.name) else: doc = frappe.get_doc(doc).insert() out.append(doc.name) return out
[ "def", "insert_many", "(", "docs", "=", "None", ")", ":", "if", "isinstance", "(", "docs", ",", "str", ")", ":", "docs", "=", "json", ".", "loads", "(", "docs", ")", "out", "=", "[", "]", "if", "len", "(", "docs", ")", ">", "200", ":", "frappe"...
https://github.com/frappe/frappe/blob/b64cab6867dfd860f10ccaf41a4ec04bc890b583/frappe/client.py#L177-L200
PaddlePaddle/PGL
e48545f2814523c777b8a9a9188bf5a7f00d6e52
apps/Graph4KG/dataset/trigraph.py
python
TriGraph.ents
(self)
return np.arange(0, self._num_ents)
All entity ids from 0 to :code:`num_ents - 1` (np.ndarray).
All entity ids from 0 to :code:`num_ents - 1` (np.ndarray).
[ "All", "entity", "ids", "from", "0", "to", ":", "code", ":", "num_ents", "-", "1", "(", "np", ".", "ndarray", ")", "." ]
def ents(self): """All entity ids from 0 to :code:`num_ents - 1` (np.ndarray). """ return np.arange(0, self._num_ents)
[ "def", "ents", "(", "self", ")", ":", "return", "np", ".", "arange", "(", "0", ",", "self", ".", "_num_ents", ")" ]
https://github.com/PaddlePaddle/PGL/blob/e48545f2814523c777b8a9a9188bf5a7f00d6e52/apps/Graph4KG/dataset/trigraph.py#L320-L323
uqfoundation/mystic
154e6302d1f2f94e8f13e88ecc5f24241cc28ac7
mystic/math/discrete.py
python
product_measure.flatten
(self)
return params
convert a product measure to a single list of parameters Args: None Returns: a list of parameters Notes: Given ``product_measure.pts = (M, N, ...)``, then the returned list is ``params = [wx1, ..., wxM, x1, ..., xM, wy1, ..., wyN, y1, ..., yN, ...]``. Thus, *params* will have ``M`` weights and ``M`` corresponding positions, followed by ``N`` weights and ``N`` corresponding positions, with this pattern followed for each new dimension of the desired product measure.
convert a product measure to a single list of parameters
[ "convert", "a", "product", "measure", "to", "a", "single", "list", "of", "parameters" ]
def flatten(self): """convert a product measure to a single list of parameters Args: None Returns: a list of parameters Notes: Given ``product_measure.pts = (M, N, ...)``, then the returned list is ``params = [wx1, ..., wxM, x1, ..., xM, wy1, ..., wyN, y1, ..., yN, ...]``. Thus, *params* will have ``M`` weights and ``M`` corresponding positions, followed by ``N`` weights and ``N`` corresponding positions, with this pattern followed for each new dimension of the desired product measure. """ params = flatten(self) return params
[ "def", "flatten", "(", "self", ")", ":", "params", "=", "flatten", "(", "self", ")", "return", "params" ]
https://github.com/uqfoundation/mystic/blob/154e6302d1f2f94e8f13e88ecc5f24241cc28ac7/mystic/math/discrete.py#L944-L961
DSE-MSU/DeepRobust
2bcde200a5969dae32cddece66206a52c87c43e8
deeprobust/graph/utils.py
python
tensor2onehot
(labels)
return onehot_mx.to(labels.device)
Convert label tensor to label onehot tensor. Parameters ---------- labels : torch.LongTensor node labels Returns ------- torch.LongTensor onehot labels tensor
Convert label tensor to label onehot tensor.
[ "Convert", "label", "tensor", "to", "label", "onehot", "tensor", "." ]
def tensor2onehot(labels): """Convert label tensor to label onehot tensor. Parameters ---------- labels : torch.LongTensor node labels Returns ------- torch.LongTensor onehot labels tensor """ eye = torch.eye(labels.max() + 1) onehot_mx = eye[labels] return onehot_mx.to(labels.device)
[ "def", "tensor2onehot", "(", "labels", ")", ":", "eye", "=", "torch", ".", "eye", "(", "labels", ".", "max", "(", ")", "+", "1", ")", "onehot_mx", "=", "eye", "[", "labels", "]", "return", "onehot_mx", ".", "to", "(", "labels", ".", "device", ")" ]
https://github.com/DSE-MSU/DeepRobust/blob/2bcde200a5969dae32cddece66206a52c87c43e8/deeprobust/graph/utils.py#L26-L43
Dozed12/df-style-worldgen
937455d54f4b02df9c4b10ae6418f4c932fd97bf
libtcodpy.py
python
console_put_char
(con, x, y, c, flag=BKGND_DEFAULT)
[]
def console_put_char(con, x, y, c, flag=BKGND_DEFAULT): if type(c) == str or type(c) == bytes: _lib.TCOD_console_put_char(con, x, y, ord(c), flag) else: _lib.TCOD_console_put_char(con, x, y, c, flag)
[ "def", "console_put_char", "(", "con", ",", "x", ",", "y", ",", "c", ",", "flag", "=", "BKGND_DEFAULT", ")", ":", "if", "type", "(", "c", ")", "==", "str", "or", "type", "(", "c", ")", "==", "bytes", ":", "_lib", ".", "TCOD_console_put_char", "(", ...
https://github.com/Dozed12/df-style-worldgen/blob/937455d54f4b02df9c4b10ae6418f4c932fd97bf/libtcodpy.py#L763-L767
sethmlarson/virtualbox-python
984a6e2cb0e8996f4df40f4444c1528849f1c70d
virtualbox/library.py
python
ISystemProperties.max_guest_vram
(self)
return ret
Get int value for 'maxGuestVRAM' Maximum guest video memory in Megabytes.
Get int value for 'maxGuestVRAM' Maximum guest video memory in Megabytes.
[ "Get", "int", "value", "for", "maxGuestVRAM", "Maximum", "guest", "video", "memory", "in", "Megabytes", "." ]
def max_guest_vram(self): """Get int value for 'maxGuestVRAM' Maximum guest video memory in Megabytes. """ ret = self._get_attr("maxGuestVRAM") return ret
[ "def", "max_guest_vram", "(", "self", ")", ":", "ret", "=", "self", ".", "_get_attr", "(", "\"maxGuestVRAM\"", ")", "return", "ret" ]
https://github.com/sethmlarson/virtualbox-python/blob/984a6e2cb0e8996f4df40f4444c1528849f1c70d/virtualbox/library.py#L20137-L20142
akamai-threat-research/mqtt-pwn
40368e531660339fca1562a6c609c35f7ae4f989
mqtt_pwn/connection/brute_forcer.py
python
ConnectionResult.set_return_code
(self, return_code)
Sets the return code field
Sets the return code field
[ "Sets", "the", "return", "code", "field" ]
def set_return_code(self, return_code): """Sets the return code field""" self._return_code = return_code
[ "def", "set_return_code", "(", "self", ",", "return_code", ")", ":", "self", ".", "_return_code", "=", "return_code" ]
https://github.com/akamai-threat-research/mqtt-pwn/blob/40368e531660339fca1562a6c609c35f7ae4f989/mqtt_pwn/connection/brute_forcer.py#L17-L19
hatRiot/zarp
2e772350a01c2aeed3f4da9685cd0cc5d6b3ecad
src/lib/scapy/layers/sctp.py
python
_SCTPChunkGuessPayload.default_payload_class
(self,p)
[]
def default_payload_class(self,p): if len(p) < 4: return conf.padding_layer else: t = ord(p[0]) return globals().get(sctpchunktypescls.get(t, "Raw"), conf.raw_layer)
[ "def", "default_payload_class", "(", "self", ",", "p", ")", ":", "if", "len", "(", "p", ")", "<", "4", ":", "return", "conf", ".", "padding_layer", "else", ":", "t", "=", "ord", "(", "p", "[", "0", "]", ")", "return", "globals", "(", ")", ".", ...
https://github.com/hatRiot/zarp/blob/2e772350a01c2aeed3f4da9685cd0cc5d6b3ecad/src/lib/scapy/layers/sctp.py#L179-L184
LinkedInAttic/naarad
261e2c0760fd6a6b0ee59064180bd8e3674311fe
src/naarad/metrics/metric.py
python
Metric.calc_key_stats
(self, metric_store)
Calculate stats such as percentile and mean :param dict metric_store: The metric store used to store all the parsed log data :return: None
Calculate stats such as percentile and mean
[ "Calculate", "stats", "such", "as", "percentile", "and", "mean" ]
def calc_key_stats(self, metric_store): """ Calculate stats such as percentile and mean :param dict metric_store: The metric store used to store all the parsed log data :return: None """ stats_to_calculate = ['mean', 'std', 'min', 'max'] # TODO: get input from user percentiles_to_calculate = range(0, 100, 1) # TODO: get input from user for column, groups_store in metric_store.items(): for group, time_store in groups_store.items(): data = metric_store[column][group].values() if self.groupby: column_name = group + '.' + column else: column_name = column if column.startswith('qps'): self.calculated_stats[column_name], self.calculated_percentiles[column_name] = naarad.utils.calculate_stats(data, stats_to_calculate, percentiles_to_calculate) else: self.calculated_stats[column_name], self.calculated_percentiles[column_name] = naarad.utils.calculate_stats(list(heapq.merge(*data)), stats_to_calculate, percentiles_to_calculate) self.update_summary_stats(column_name)
[ "def", "calc_key_stats", "(", "self", ",", "metric_store", ")", ":", "stats_to_calculate", "=", "[", "'mean'", ",", "'std'", ",", "'min'", ",", "'max'", "]", "# TODO: get input from user", "percentiles_to_calculate", "=", "range", "(", "0", ",", "100", ",", "1...
https://github.com/LinkedInAttic/naarad/blob/261e2c0760fd6a6b0ee59064180bd8e3674311fe/src/naarad/metrics/metric.py#L322-L343
enthought/mayavi
2103a273568b8f0bd62328801aafbd6252543ae8
mayavi/sources/array_source.py
python
ArraySource.remove_attribute
(self, name, category='point')
Remove an attribute by its name and optional category (point and cell). Returns the removed array.
Remove an attribute by its name and optional category (point and cell). Returns the removed array.
[ "Remove", "an", "attribute", "by", "its", "name", "and", "optional", "category", "(", "point", "and", "cell", ")", ".", "Returns", "the", "removed", "array", "." ]
def remove_attribute(self, name, category='point'): """Remove an attribute by its name and optional category (point and cell). Returns the removed array. """ data = getattr(self.image_data, '%s_data' % category) data.remove_array(name)
[ "def", "remove_attribute", "(", "self", ",", "name", ",", "category", "=", "'point'", ")", ":", "data", "=", "getattr", "(", "self", ".", "image_data", ",", "'%s_data'", "%", "category", ")", "data", ".", "remove_array", "(", "name", ")" ]
https://github.com/enthought/mayavi/blob/2103a273568b8f0bd62328801aafbd6252543ae8/mayavi/sources/array_source.py#L215-L220
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/alexa/capabilities.py
python
AlexaPowerController.properties_proactively_reported
(self)
return True
Return True if properties asynchronously reported.
Return True if properties asynchronously reported.
[ "Return", "True", "if", "properties", "asynchronously", "reported", "." ]
def properties_proactively_reported(self): """Return True if properties asynchronously reported.""" return True
[ "def", "properties_proactively_reported", "(", "self", ")", ":", "return", "True" ]
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/alexa/capabilities.py#L380-L382
GoogleCloudPlatform/professional-services
0c707aa97437f3d154035ef8548109b7882f71da
examples/vertex_pipeline/components/component_base/src/preprocess.py
python
executor_main
()
Main executor.
Main executor.
[ "Main", "executor", "." ]
def executor_main(): """Main executor.""" parser = argparse.ArgumentParser() parser.add_argument('--executor_input', type=str) parser.add_argument('--function_to_execute', type=str) args, _ = parser.parse_known_args() executor_input = json.loads(args.executor_input) function_to_execute = globals()[args.function_to_execute] executor.Executor( executor_input=executor_input, function_to_execute=function_to_execute).execute()
[ "def", "executor_main", "(", ")", ":", "parser", "=", "argparse", ".", "ArgumentParser", "(", ")", "parser", ".", "add_argument", "(", "'--executor_input'", ",", "type", "=", "str", ")", "parser", ".", "add_argument", "(", "'--function_to_execute'", ",", "type...
https://github.com/GoogleCloudPlatform/professional-services/blob/0c707aa97437f3d154035ef8548109b7882f71da/examples/vertex_pipeline/components/component_base/src/preprocess.py#L95-L108
kuri65536/python-for-android
26402a08fc46b09ef94e8d7a6bbc3a54ff9d0891
python-modules/twisted/twisted/internet/selectreactor.py
python
SelectReactor.addReader
(self, reader)
Add a FileDescriptor for notification of data available to read.
Add a FileDescriptor for notification of data available to read.
[ "Add", "a", "FileDescriptor", "for", "notification", "of", "data", "available", "to", "read", "." ]
def addReader(self, reader): """ Add a FileDescriptor for notification of data available to read. """ self._reads[reader] = 1
[ "def", "addReader", "(", "self", ",", "reader", ")", ":", "self", ".", "_reads", "[", "reader", "]", "=", "1" ]
https://github.com/kuri65536/python-for-android/blob/26402a08fc46b09ef94e8d7a6bbc3a54ff9d0891/python-modules/twisted/twisted/internet/selectreactor.py#L158-L162
fuzzbunch/fuzzbunch
4b60a6c7cf9f84cf389d3fcdb9281de84ffb5802
fuzzbunch/plugin.py
python
Plugin.execute
(self, session, mode)
Execute the plugin
Execute the plugin
[ "Execute", "the", "plugin" ]
def execute(self, session, mode): """Execute the plugin""" pass
[ "def", "execute", "(", "self", ",", "session", ",", "mode", ")", ":", "pass" ]
https://github.com/fuzzbunch/fuzzbunch/blob/4b60a6c7cf9f84cf389d3fcdb9281de84ffb5802/fuzzbunch/plugin.py#L308-L310
SebKuzminsky/pycam
55e3129f518e470040e79bb00515b4bfcf36c172
pycam/Plugins/ParallelProcessing.py
python
ParallelProcessing.setup
(self)
return True
[]
def setup(self): if self.gui and self._gtk: box = self.gui.get_object("MultiprocessingFrame") box.unparent() self.core.register_ui("preferences", "Parallel processing", box, 60) # "process pool" window self.process_pool_window = self.gui.get_object("ProcessPoolWindow") self.process_pool_window.set_default_size(500, 400) self._gtk_handlers = [] self._gtk_handlers.extend(( (self.process_pool_window, "delete-event", self.toggle_process_pool_window, False), (self.process_pool_window, "destroy", self.toggle_process_pool_window, False))) self._gtk_handlers.append(( self.gui.get_object("ProcessPoolWindowClose"), "clicked", self.toggle_process_pool_window, False)) self.gui.get_object("ProcessPoolRefreshInterval").set_value(3) self.process_pool_model = self.gui.get_object("ProcessPoolStatisticsModel") # show/hide controls self.enable_parallel_processes = self.gui.get_object("EnableParallelProcesses") if pycam.Utils.threading.is_multiprocessing_available(): self.gui.get_object("ParallelProcessingDisabledLabel").hide() if pycam.Utils.threading.is_server_mode_available(): self.gui.get_object("ServerModeDisabledLabel").hide() else: self.gui.get_object("ServerModeSettingsFrame").hide() else: self.gui.get_object("ParallelProcessSettingsBox").hide() self.gui.get_object("EnableParallelProcesses").hide() self._gtk_handlers.append((self.enable_parallel_processes, "toggled", self.handle_parallel_processes_settings)) self.number_of_processes = self.gui.get_object("NumberOfProcesses") self.number_of_processes.set_value(pycam.Utils.threading.get_number_of_processes()) self.server_port_local_obj = self.gui.get_object("ServerPortLocal") self.server_port_remote_obj = self.gui.get_object("RemoteServerPort") self.auth_key_obj = self.gui.get_object("ServerPassword") self._gtk_handlers.extend(( (self.number_of_processes, "value-changed", self.handle_parallel_processes_settings), (self.gui.get_object("EnableServerMode"), "toggled", self.initialize_multiprocessing), (self.gui.get_object("ServerPasswordGenerate"), "clicked", self.generate_random_server_password), (self.gui.get_object("ServerPasswordShow"), "toggled", self.update_parallel_processes_settings))) cpu_cores = pycam.Utils.threading.get_number_of_cores() if cpu_cores is None: cpu_cores = "unknown" self.gui.get_object("AvailableCores").set_label(str(cpu_cores)) toggle_button = self.gui.get_object("ToggleProcessPoolWindow") self._gtk_handlers.append((toggle_button, "toggled", self.toggle_process_pool_window)) self.register_gtk_accelerator("processes", toggle_button, None, "ToggleProcessPoolWindow") self.core.register_ui("view_menu", "ToggleProcessPoolWindow", toggle_button, 40) self.register_gtk_handlers(self._gtk_handlers) self.enable_parallel_processes.set_active( pycam.Utils.threading.is_multiprocessing_enabled()) self.update_parallel_processes_settings() return True
[ "def", "setup", "(", "self", ")", ":", "if", "self", ".", "gui", "and", "self", ".", "_gtk", ":", "box", "=", "self", ".", "gui", ".", "get_object", "(", "\"MultiprocessingFrame\"", ")", "box", ".", "unparent", "(", ")", "self", ".", "core", ".", "...
https://github.com/SebKuzminsky/pycam/blob/55e3129f518e470040e79bb00515b4bfcf36c172/pycam/Plugins/ParallelProcessing.py#L35-L92
pyg-team/pytorch_geometric
b920e9a3a64e22c8356be55301c88444ff051cae
benchmark/citation/gat.py
python
Net.forward
(self, data)
return F.log_softmax(x, dim=1)
[]
def forward(self, data): x, edge_index = data.x, data.edge_index x = F.dropout(x, p=args.dropout, training=self.training) x = F.elu(self.conv1(x, edge_index)) x = F.dropout(x, p=args.dropout, training=self.training) x = self.conv2(x, edge_index) return F.log_softmax(x, dim=1)
[ "def", "forward", "(", "self", ",", "data", ")", ":", "x", ",", "edge_index", "=", "data", ".", "x", ",", "data", ".", "edge_index", "x", "=", "F", ".", "dropout", "(", "x", ",", "p", "=", "args", ".", "dropout", ",", "training", "=", "self", "...
https://github.com/pyg-team/pytorch_geometric/blob/b920e9a3a64e22c8356be55301c88444ff051cae/benchmark/citation/gat.py#L37-L43
tjweir/liftbook
e977a7face13ade1a4558e1909a6951d2f8928dd
elyxer.py
python
FormulaFactory.clearany
(self, pos)
return None
Cleary any ignored type.
Cleary any ignored type.
[ "Cleary", "any", "ignored", "type", "." ]
def clearany(self, pos): "Cleary any ignored type." for type in self.ignoredtypes: if self.instance(type).detect(pos): return self.parsetype(type, pos) return None
[ "def", "clearany", "(", "self", ",", "pos", ")", ":", "for", "type", "in", "self", ".", "ignoredtypes", ":", "if", "self", ".", "instance", "(", "type", ")", ".", "detect", "(", "pos", ")", ":", "return", "self", ".", "parsetype", "(", "type", ",",...
https://github.com/tjweir/liftbook/blob/e977a7face13ade1a4558e1909a6951d2f8928dd/elyxer.py#L4389-L4394
Source-Python-Dev-Team/Source.Python
d0ffd8ccbd1e9923c9bc44936f20613c1c76b7fb
addons/source-python/Python3/configparser.py
python
RawConfigParser._unify_values
(self, section, vars)
return _ChainMap(vardict, sectiondict, self._defaults)
Create a sequence of lookups with 'vars' taking priority over the 'section' which takes priority over the DEFAULTSECT.
Create a sequence of lookups with 'vars' taking priority over the 'section' which takes priority over the DEFAULTSECT.
[ "Create", "a", "sequence", "of", "lookups", "with", "vars", "taking", "priority", "over", "the", "section", "which", "takes", "priority", "over", "the", "DEFAULTSECT", "." ]
def _unify_values(self, section, vars): """Create a sequence of lookups with 'vars' taking priority over the 'section' which takes priority over the DEFAULTSECT. """ sectiondict = {} try: sectiondict = self._sections[section] except KeyError: if section != self.default_section: raise NoSectionError(section) # Update with the entry specific variables vardict = {} if vars: for key, value in vars.items(): if value is not None: value = str(value) vardict[self.optionxform(key)] = value return _ChainMap(vardict, sectiondict, self._defaults)
[ "def", "_unify_values", "(", "self", ",", "section", ",", "vars", ")", ":", "sectiondict", "=", "{", "}", "try", ":", "sectiondict", "=", "self", ".", "_sections", "[", "section", "]", "except", "KeyError", ":", "if", "section", "!=", "self", ".", "def...
https://github.com/Source-Python-Dev-Team/Source.Python/blob/d0ffd8ccbd1e9923c9bc44936f20613c1c76b7fb/addons/source-python/Python3/configparser.py#L1131-L1149
openstack/tempest
fe0ac89a5a1c43fa908a76759cd99eea3b1f9853
tempest/lib/common/rest_client.py
python
RestClient.put
(self, url, body, headers=None, extra_headers=False, chunked=False)
return self.request('PUT', url, extra_headers, headers, body, chunked)
Send a HTTP PUT request using keystone service catalog and auth :param str url: the relative url to send the put request to :param dict body: the request body :param dict headers: The headers to use for the request :param bool extra_headers: Boolean value than indicates if the headers returned by the get_headers() method are to be used but additional headers are needed in the request pass them in as a dict. :param bool chunked: sends the body with chunked encoding :return: a tuple with the first entry containing the response headers and the second the response body :rtype: tuple
Send a HTTP PUT request using keystone service catalog and auth
[ "Send", "a", "HTTP", "PUT", "request", "using", "keystone", "service", "catalog", "and", "auth" ]
def put(self, url, body, headers=None, extra_headers=False, chunked=False): """Send a HTTP PUT request using keystone service catalog and auth :param str url: the relative url to send the put request to :param dict body: the request body :param dict headers: The headers to use for the request :param bool extra_headers: Boolean value than indicates if the headers returned by the get_headers() method are to be used but additional headers are needed in the request pass them in as a dict. :param bool chunked: sends the body with chunked encoding :return: a tuple with the first entry containing the response headers and the second the response body :rtype: tuple """ return self.request('PUT', url, extra_headers, headers, body, chunked)
[ "def", "put", "(", "self", ",", "url", ",", "body", ",", "headers", "=", "None", ",", "extra_headers", "=", "False", ",", "chunked", "=", "False", ")", ":", "return", "self", ".", "request", "(", "'PUT'", ",", "url", ",", "extra_headers", ",", "heade...
https://github.com/openstack/tempest/blob/fe0ac89a5a1c43fa908a76759cd99eea3b1f9853/tempest/lib/common/rest_client.py#L348-L363
InvestmentSystems/static-frame
0b19d6969bf6c17fb0599871aca79eb3b52cf2ed
static_frame/core/bus.py
python
Bus.to_series
(self)
return Series(self.values, index=self._index, own_index=True, name=self._name, )
Return a :obj:`Series` with the :obj:`Frame` contained in this :obj:`Bus`. If the :obj:`Bus` is associated with a :obj:`Store`, all :obj:`Frame` will be loaded into memory and the returned :obj:`Bus` will no longer be associated with the :obj:`Store`.
Return a :obj:`Series` with the :obj:`Frame` contained in this :obj:`Bus`. If the :obj:`Bus` is associated with a :obj:`Store`, all :obj:`Frame` will be loaded into memory and the returned :obj:`Bus` will no longer be associated with the :obj:`Store`.
[ "Return", "a", ":", "obj", ":", "Series", "with", "the", ":", "obj", ":", "Frame", "contained", "in", "this", ":", "obj", ":", "Bus", ".", "If", "the", ":", "obj", ":", "Bus", "is", "associated", "with", "a", ":", "obj", ":", "Store", "all", ":",...
def to_series(self) -> Series: '''Return a :obj:`Series` with the :obj:`Frame` contained in this :obj:`Bus`. If the :obj:`Bus` is associated with a :obj:`Store`, all :obj:`Frame` will be loaded into memory and the returned :obj:`Bus` will no longer be associated with the :obj:`Store`. ''' # values returns an immutable array and will fully realize from Store return Series(self.values, index=self._index, own_index=True, name=self._name, )
[ "def", "to_series", "(", "self", ")", "->", "Series", ":", "# values returns an immutable array and will fully realize from Store", "return", "Series", "(", "self", ".", "values", ",", "index", "=", "self", ".", "_index", ",", "own_index", "=", "True", ",", "name"...
https://github.com/InvestmentSystems/static-frame/blob/0b19d6969bf6c17fb0599871aca79eb3b52cf2ed/static_frame/core/bus.py#L1323-L1331
pret/pokemon-reverse-engineering-tools
5e0715f2579adcfeb683448c9a7826cfd3afa57d
pokemontools/map_editor.py
python
MapRenderer.__init__
(self, config=config, **kwargs)
[]
def __init__(self, config=config, **kwargs): self.config = config self.__dict__.update(kwargs) self.map = Map(**kwargs)
[ "def", "__init__", "(", "self", ",", "config", "=", "config", ",", "*", "*", "kwargs", ")", ":", "self", ".", "config", "=", "config", "self", ".", "__dict__", ".", "update", "(", "kwargs", ")", "self", ".", "map", "=", "Map", "(", "*", "*", "kwa...
https://github.com/pret/pokemon-reverse-engineering-tools/blob/5e0715f2579adcfeb683448c9a7826cfd3afa57d/pokemontools/map_editor.py#L398-L401
rucio/rucio
6d0d358e04f5431f0b9a98ae40f31af0ddff4833
lib/rucio/db/sqla/migrate_repo/versions/2af3291ec4c_added_replicas_history_table.py
python
upgrade
()
Upgrade the database to this revision
Upgrade the database to this revision
[ "Upgrade", "the", "database", "to", "this", "revision" ]
def upgrade(): ''' Upgrade the database to this revision ''' if context.get_context().dialect.name in ['oracle', 'mysql', 'postgresql']: create_table('replicas_history', sa.Column('rse_id', GUID()), sa.Column('scope', sa.String(25)), sa.Column('name', sa.String(255)), sa.Column('bytes', sa.BigInteger)) create_primary_key('REPLICAS_HIST_PK', 'replicas_history', ['rse_id', 'scope', 'name']) create_foreign_key('REPLICAS_HIST_RSE_ID_FK', 'replicas_history', 'rses', ['rse_id'], ['id']) create_check_constraint('REPLICAS_HIST_SIZE_NN', 'replicas_history', 'bytes IS NOT NULL')
[ "def", "upgrade", "(", ")", ":", "if", "context", ".", "get_context", "(", ")", ".", "dialect", ".", "name", "in", "[", "'oracle'", ",", "'mysql'", ",", "'postgresql'", "]", ":", "create_table", "(", "'replicas_history'", ",", "sa", ".", "Column", "(", ...
https://github.com/rucio/rucio/blob/6d0d358e04f5431f0b9a98ae40f31af0ddff4833/lib/rucio/db/sqla/migrate_repo/versions/2af3291ec4c_added_replicas_history_table.py#L35-L49
LGE-ARC-AdvancedAI/auptimizer
50f6e3b4e0cb9146ca90fd74b9b24ca97ae22617
src/aup/Proposer/hyperopt/mongoexp.py
python
MongoJobs.set_attachment
(self, doc, blob, name, collection=None)
Attach potentially large data string `blob` to `doc` by name `name` blob must be a string doc must have been saved in some collection (must have an _id), but not necessarily the jobs collection. name must be a string Returns None
Attach potentially large data string `blob` to `doc` by name `name`
[ "Attach", "potentially", "large", "data", "string", "blob", "to", "doc", "by", "name", "name" ]
def set_attachment(self, doc, blob, name, collection=None): """Attach potentially large data string `blob` to `doc` by name `name` blob must be a string doc must have been saved in some collection (must have an _id), but not necessarily the jobs collection. name must be a string Returns None """ # If there is already a file with the given name for this doc, then we will delete it # after writing the new file attachments = doc.get('_attachments', []) name_matches = [a for a in attachments if a[0] == name] # the filename is set to something so that fs.list() will display the file new_file_id = self.gfs.put(blob, filename='%s_%s' % (doc['_id'], name)) logger.info('stored blob of %i bytes with id=%s and filename %s_%s' % ( len(blob), str(new_file_id), doc['_id'], name)) new_attachments = ([a for a in attachments if a[0] != name] + [(name, new_file_id)]) try: ii = 0 doc = self.update(doc, {'_attachments': new_attachments}, collection=collection) # there is a database leak until we actually delete the files that # are no longer pointed to by new_attachments while ii < len(name_matches): self.gfs.delete(name_matches[ii][1]) ii += 1 except: while ii < len(name_matches): logger.warning("Leak during set_attachment: old_file_id=%s" % ( name_matches[ii][1])) ii += 1 raise assert len([n for n in self.attachment_names(doc) if n == name]) == 1
[ "def", "set_attachment", "(", "self", ",", "doc", ",", "blob", ",", "name", ",", "collection", "=", "None", ")", ":", "# If there is already a file with the given name for this doc, then we will delete it", "# after writing the new file", "attachments", "=", "doc", ".", "...
https://github.com/LGE-ARC-AdvancedAI/auptimizer/blob/50f6e3b4e0cb9146ca90fd74b9b24ca97ae22617/src/aup/Proposer/hyperopt/mongoexp.py#L570-L611
exercism/python
f79d44ef6c9cf68d8c76cb94017a590f04391635
exercises/practice/run-length-encoding/.meta/example.py
python
encode
(string)
return ''.join(single_helper(key, group) for key, group in groupby(string))
[]
def encode(string): def single_helper(key, group): size = len(list(group)) return key if size == 1 else str(size) + key return ''.join(single_helper(key, group) for key, group in groupby(string))
[ "def", "encode", "(", "string", ")", ":", "def", "single_helper", "(", "key", ",", "group", ")", ":", "size", "=", "len", "(", "list", "(", "group", ")", ")", "return", "key", "if", "size", "==", "1", "else", "str", "(", "size", ")", "+", "key", ...
https://github.com/exercism/python/blob/f79d44ef6c9cf68d8c76cb94017a590f04391635/exercises/practice/run-length-encoding/.meta/example.py#L9-L13
replit-archive/empythoned
977ec10ced29a3541a4973dc2b59910805695752
cpython/Lib/plat-mac/lib-scriptpackages/StdSuites/AppleScript_Suite.py
python
AppleScript_Suite_Events.ends_with
(self, _object, _attributes={}, **_arguments)
ends with: Ends with Required argument: an AE object reference Keyword argument _attributes: AppleEvent attribute dictionary Returns: anything
ends with: Ends with Required argument: an AE object reference Keyword argument _attributes: AppleEvent attribute dictionary Returns: anything
[ "ends", "with", ":", "Ends", "with", "Required", "argument", ":", "an", "AE", "object", "reference", "Keyword", "argument", "_attributes", ":", "AppleEvent", "attribute", "dictionary", "Returns", ":", "anything" ]
def ends_with(self, _object, _attributes={}, **_arguments): """ends with: Ends with Required argument: an AE object reference Keyword argument _attributes: AppleEvent attribute dictionary Returns: anything """ _code = 'ascr' _subcode = 'ends' if _arguments: raise TypeError, 'No optional args expected' _arguments['----'] = _object _reply, _arguments, _attributes = self.send(_code, _subcode, _arguments, _attributes) if _arguments.get('errn', 0): raise aetools.Error, aetools.decodeerror(_arguments) # XXXX Optionally decode result if _arguments.has_key('----'): return _arguments['----']
[ "def", "ends_with", "(", "self", ",", "_object", ",", "_attributes", "=", "{", "}", ",", "*", "*", "_arguments", ")", ":", "_code", "=", "'ascr'", "_subcode", "=", "'ends'", "if", "_arguments", ":", "raise", "TypeError", ",", "'No optional args expected'", ...
https://github.com/replit-archive/empythoned/blob/977ec10ced29a3541a4973dc2b59910805695752/cpython/Lib/plat-mac/lib-scriptpackages/StdSuites/AppleScript_Suite.py#L385-L404
danecjensen/subscribely
4d6ac60358b5fe26f0c01be68f1ba063df3b1ea0
src/flask/app.py
python
Flask.try_trigger_before_first_request_functions
(self)
Called before each request and will ensure that it triggers the :attr:`before_first_request_funcs` and only exactly once per application instance (which means process usually). :internal:
Called before each request and will ensure that it triggers the :attr:`before_first_request_funcs` and only exactly once per application instance (which means process usually).
[ "Called", "before", "each", "request", "and", "will", "ensure", "that", "it", "triggers", "the", ":", "attr", ":", "before_first_request_funcs", "and", "only", "exactly", "once", "per", "application", "instance", "(", "which", "means", "process", "usually", ")",...
def try_trigger_before_first_request_functions(self): """Called before each request and will ensure that it triggers the :attr:`before_first_request_funcs` and only exactly once per application instance (which means process usually). :internal: """ if self._got_first_request: return with self._before_request_lock: if self._got_first_request: return self._got_first_request = True for func in self.before_first_request_funcs: func()
[ "def", "try_trigger_before_first_request_functions", "(", "self", ")", ":", "if", "self", ".", "_got_first_request", ":", "return", "with", "self", ".", "_before_request_lock", ":", "if", "self", ".", "_got_first_request", ":", "return", "self", ".", "_got_first_req...
https://github.com/danecjensen/subscribely/blob/4d6ac60358b5fe26f0c01be68f1ba063df3b1ea0/src/flask/app.py#L1270-L1284
cooelf/SemBERT
f849452f864b5dd47f94e2911cffc15e9f6a5a2a
run_classifier.py
python
QnliProcessor.get_train_examples
(self, data_dir)
return self._create_examples( self._read_tsv(os.path.join(data_dir, "train.tsv_tag")), "train")
See base class.
See base class.
[ "See", "base", "class", "." ]
def get_train_examples(self, data_dir): """See base class.""" return self._create_examples( self._read_tsv(os.path.join(data_dir, "train.tsv_tag")), "train")
[ "def", "get_train_examples", "(", "self", ",", "data_dir", ")", ":", "return", "self", ".", "_create_examples", "(", "self", ".", "_read_tsv", "(", "os", ".", "path", ".", "join", "(", "data_dir", ",", "\"train.tsv_tag\"", ")", ")", ",", "\"train\"", ")" ]
https://github.com/cooelf/SemBERT/blob/f849452f864b5dd47f94e2911cffc15e9f6a5a2a/run_classifier.py#L321-L324
Cadene/tensorflow-model-zoo.torch
990b10ffc22d4c8eacb2a502f20415b4f70c74c2
models/research/cognitive_mapping_and_planning/tfcode/tf_utils.py
python
add_value_to_summary
(metric_summary, tag, val, log=True, tag_str=None)
Adds a scalar summary to the summary object. Optionally also logs to logging.
Adds a scalar summary to the summary object. Optionally also logs to logging.
[ "Adds", "a", "scalar", "summary", "to", "the", "summary", "object", ".", "Optionally", "also", "logs", "to", "logging", "." ]
def add_value_to_summary(metric_summary, tag, val, log=True, tag_str=None): """Adds a scalar summary to the summary object. Optionally also logs to logging.""" new_value = metric_summary.value.add(); new_value.tag = tag new_value.simple_value = val if log: if tag_str is None: tag_str = tag + '%f' logging.info(tag_str, val)
[ "def", "add_value_to_summary", "(", "metric_summary", ",", "tag", ",", "val", ",", "log", "=", "True", ",", "tag_str", "=", "None", ")", ":", "new_value", "=", "metric_summary", ".", "value", ".", "add", "(", ")", "new_value", ".", "tag", "=", "tag", "...
https://github.com/Cadene/tensorflow-model-zoo.torch/blob/990b10ffc22d4c8eacb2a502f20415b4f70c74c2/models/research/cognitive_mapping_and_planning/tfcode/tf_utils.py#L688-L697
pypa/flit
a4524758604107bde8c77b5816612edb76a604aa
flit_core/flit_core/vendor/tomli/_re.py
python
match_to_datetime
(match: "re.Match")
return datetime(year, month, day, hour, minute, sec, micros, tzinfo=tz)
Convert a `RE_DATETIME` match to `datetime.datetime` or `datetime.date`. Raises ValueError if the match does not correspond to a valid date or datetime.
Convert a `RE_DATETIME` match to `datetime.datetime` or `datetime.date`.
[ "Convert", "a", "RE_DATETIME", "match", "to", "datetime", ".", "datetime", "or", "datetime", ".", "date", "." ]
def match_to_datetime(match: "re.Match") -> Union[datetime, date]: """Convert a `RE_DATETIME` match to `datetime.datetime` or `datetime.date`. Raises ValueError if the match does not correspond to a valid date or datetime. """ ( year_str, month_str, day_str, hour_str, minute_str, sec_str, micros_str, zulu_time, offset_sign_str, offset_hour_str, offset_minute_str, ) = match.groups() year, month, day = int(year_str), int(month_str), int(day_str) if hour_str is None: return date(year, month, day) hour, minute, sec = int(hour_str), int(minute_str), int(sec_str) micros = int(micros_str.ljust(6, "0")) if micros_str else 0 if offset_sign_str: tz: Optional[tzinfo] = cached_tz( offset_hour_str, offset_minute_str, offset_sign_str ) elif zulu_time: tz = timezone.utc else: # local date-time tz = None return datetime(year, month, day, hour, minute, sec, micros, tzinfo=tz)
[ "def", "match_to_datetime", "(", "match", ":", "\"re.Match\"", ")", "->", "Union", "[", "datetime", ",", "date", "]", ":", "(", "year_str", ",", "month_str", ",", "day_str", ",", "hour_str", ",", "minute_str", ",", "sec_str", ",", "micros_str", ",", "zulu_...
https://github.com/pypa/flit/blob/a4524758604107bde8c77b5816612edb76a604aa/flit_core/flit_core/vendor/tomli/_re.py#L46-L78
fake-name/ChromeController
6c70d855e33e06463516b263bf9e6f34c48e29e8
ChromeController/Generator/Generated.py
python
ChromeRemoteDebugInterface.Database_disable
(self)
return subdom_funcs
Function path: Database.disable Domain: Database Method name: disable No return value. Description: Disables database tracking, prevents database events from being sent to the client.
Function path: Database.disable Domain: Database Method name: disable No return value. Description: Disables database tracking, prevents database events from being sent to the client.
[ "Function", "path", ":", "Database", ".", "disable", "Domain", ":", "Database", "Method", "name", ":", "disable", "No", "return", "value", ".", "Description", ":", "Disables", "database", "tracking", "prevents", "database", "events", "from", "being", "sent", "...
def Database_disable(self): """ Function path: Database.disable Domain: Database Method name: disable No return value. Description: Disables database tracking, prevents database events from being sent to the client. """ subdom_funcs = self.synchronous_command('Database.disable') return subdom_funcs
[ "def", "Database_disable", "(", "self", ")", ":", "subdom_funcs", "=", "self", ".", "synchronous_command", "(", "'Database.disable'", ")", "return", "subdom_funcs" ]
https://github.com/fake-name/ChromeController/blob/6c70d855e33e06463516b263bf9e6f34c48e29e8/ChromeController/Generator/Generated.py#L3333-L3344
aliyun/aliyun-odps-python-sdk
20b391c8d6eb1a689eedf950c2fc702be5f057c9
odps/lib/six.py
python
_SixMetaPathImporter.get_code
(self, fullname)
return None
Return None Required, if is_package is implemented
Return None
[ "Return", "None" ]
def get_code(self, fullname): """Return None Required, if is_package is implemented""" self.__get_module(fullname) # eventually raises ImportError return None
[ "def", "get_code", "(", "self", ",", "fullname", ")", ":", "self", ".", "__get_module", "(", "fullname", ")", "# eventually raises ImportError", "return", "None" ]
https://github.com/aliyun/aliyun-odps-python-sdk/blob/20b391c8d6eb1a689eedf950c2fc702be5f057c9/odps/lib/six.py#L233-L238
alshedivat/keras-gp
742019c428948673920284215058a0c284491b80
kgp/backend/gpml.py
python
GPML.get_dlik_dx
(self, which_set, verbose=0)
return dlik_dx
Get derivative of the log marginal likelihood w.r.t. the kernel.
Get derivative of the log marginal likelihood w.r.t. the kernel.
[ "Get", "derivative", "of", "the", "log", "marginal", "likelihood", "w", ".", "r", ".", "t", ".", "the", "kernel", "." ]
def get_dlik_dx(self, which_set, verbose=0): """Get derivative of the log marginal likelihood w.r.t. the kernel. """ assert which_set in {'tr', 'tst', 'val', 'tmp'} X_name, y_name = 'X_' + which_set, 'y_' + which_set self.config.update({'X': X_name, 'y': y_name}) self.eng.eval(_gp_dlik.format(**self.config), verbose=verbose) dlik_dx = self.eng.pull('dlik_dx') return dlik_dx
[ "def", "get_dlik_dx", "(", "self", ",", "which_set", ",", "verbose", "=", "0", ")", ":", "assert", "which_set", "in", "{", "'tr'", ",", "'tst'", ",", "'val'", ",", "'tmp'", "}", "X_name", ",", "y_name", "=", "'X_'", "+", "which_set", ",", "'y_'", "+"...
https://github.com/alshedivat/keras-gp/blob/742019c428948673920284215058a0c284491b80/kgp/backend/gpml.py#L207-L215
openelections/openelections-core
3c516d8c4cf1166b1868b738a248d48f3378c525
openelex/us/wa/transform/__init__.py
python
CreateResultsTransform._parse_winner
(self, raw_result)
Converts raw winner value into boolean
Converts raw winner value into boolean
[ "Converts", "raw", "winner", "value", "into", "boolean" ]
def _parse_winner(self, raw_result): """ Converts raw winner value into boolean """ if raw_result.winner == 'Y': # Winner in post-2002 contest return True elif raw_result.winner == 1: # Winner in 2002 contest return True else: return False
[ "def", "_parse_winner", "(", "self", ",", "raw_result", ")", ":", "if", "raw_result", ".", "winner", "==", "'Y'", ":", "# Winner in post-2002 contest", "return", "True", "elif", "raw_result", ".", "winner", "==", "1", ":", "# Winner in 2002 contest", "return", "...
https://github.com/openelections/openelections-core/blob/3c516d8c4cf1166b1868b738a248d48f3378c525/openelex/us/wa/transform/__init__.py#L491-L502
williballenthin/INDXParse
454d70645b2d01f75ac4346bc2410fbe047d090c
INDXParse.py
python
NTATTR_STANDARD_INDEX_HEADER.deleted_entries
(self)
A generator that yields INDX entries found in the slack space associated with this header.
A generator that yields INDX entries found in the slack space associated with this header.
[ "A", "generator", "that", "yields", "INDX", "entries", "found", "in", "the", "slack", "space", "associated", "with", "this", "header", "." ]
def deleted_entries(self): """ A generator that yields INDX entries found in the slack space associated with this header. """ off = self.offset() + self.entry_size() # NTATTR_STANDARD_INDEX_ENTRY is at least 0x52 bytes # long, so don't overrun # but if we do, then we're done try: while off < self.offset() + self.entry_allocated_size() - 0x52: try: g_logger.debug("Trying to find slack entry at %x.", off) e = NTATTR_DIRECTORY_INDEX_SLACK_ENTRY(self._buf, off, self) if e.is_valid(): g_logger.debug("Slack entry is valid.") off = e.end_offset() yield e else: g_logger.debug("Slack entry is invalid.") raise ParseException("Not a deleted entry") except ParseException: g_logger.debug("Scanning one byte forward.") off += 1 except struct.error: g_logger.debug("Slack entry parsing overran buffer.") pass
[ "def", "deleted_entries", "(", "self", ")", ":", "off", "=", "self", ".", "offset", "(", ")", "+", "self", ".", "entry_size", "(", ")", "# NTATTR_STANDARD_INDEX_ENTRY is at least 0x52 bytes", "# long, so don't overrun", "# but if we do, then we're done", "try", ":", "...
https://github.com/williballenthin/INDXParse/blob/454d70645b2d01f75ac4346bc2410fbe047d090c/INDXParse.py#L403-L431
bowenbaker/metaqnn
a25847f635e9545455f83405453e740646038f7a
libs/input_modules/get_datasets.py
python
get_mnist
(save_dir=None, root_path=None)
return Xtr, Ytr, Xte, Yte
If root_path is None, we download the data set from internet. Either save path or root path must not be None and not both. Returns Xtr, Ytr, Xte, Yte as numpy arrays
If root_path is None, we download the data set from internet.
[ "If", "root_path", "is", "None", "we", "download", "the", "data", "set", "from", "internet", "." ]
def get_mnist(save_dir=None, root_path=None): ''' If root_path is None, we download the data set from internet. Either save path or root path must not be None and not both. Returns Xtr, Ytr, Xte, Yte as numpy arrays ''' assert((save_dir is not None and root_path is None) or (save_dir is None and root_path is not None)) mnist_files = ['train-images-idx3-ubyte', 'train-labels-idx1-ubyte', 't10k-images-idx3-ubyte','t10k-labels-idx1-ubyte'] out_mnist_files = [] if root_path is None: print 'Downloading MNIST dataset...' for fname in mnist_files: out_file = os.path.join(save_dir, "%s" % fname) tar_path = os.path.join(save_dir, "%s.gz" % fname) out_mnist_files.append(out_file) url = urllib.URLopener() url.retrieve("http://yann.lecun.com/exdb/mnist/%s.gz" % fname, tar_path) print 'Download Done, Extracting... [%s]' % tar_path os.system('gunzip -f %s' % tar_path) Xtr, Ytr = load_mnist(out_mnist_files[0], out_mnist_files[1]) print 'Xtrain shape', Xtr.shape print 'Ytrain shape', Ytr.shape # Testing data Xte, Yte = load_mnist(out_mnist_files[2], out_mnist_files[3]) print 'Xtest shape', Xte.shape print 'Ytest shape', Yte.shape return Xtr, Ytr, Xte, Yte
[ "def", "get_mnist", "(", "save_dir", "=", "None", ",", "root_path", "=", "None", ")", ":", "assert", "(", "(", "save_dir", "is", "not", "None", "and", "root_path", "is", "None", ")", "or", "(", "save_dir", "is", "None", "and", "root_path", "is", "not",...
https://github.com/bowenbaker/metaqnn/blob/a25847f635e9545455f83405453e740646038f7a/libs/input_modules/get_datasets.py#L345-L379
cisco-sas/kitty
cb0760989dcdfe079e43ac574d872d0b18953a32
kitty/model/low_level/aliases.py
python
BitMaskNotSet
(field, comp_value)
return Compare(field, '&=0', comp_value)
Condition applies if the given bitmask is equal to 0 in the value of the field :rtype: :class:`~kitty.model.low_level.condition.Compare`
Condition applies if the given bitmask is equal to 0 in the value of the field
[ "Condition", "applies", "if", "the", "given", "bitmask", "is", "equal", "to", "0", "in", "the", "value", "of", "the", "field" ]
def BitMaskNotSet(field, comp_value): ''' Condition applies if the given bitmask is equal to 0 in the value of the field :rtype: :class:`~kitty.model.low_level.condition.Compare` ''' return Compare(field, '&=0', comp_value)
[ "def", "BitMaskNotSet", "(", "field", ",", "comp_value", ")", ":", "return", "Compare", "(", "field", ",", "'&=0'", ",", "comp_value", ")" ]
https://github.com/cisco-sas/kitty/blob/cb0760989dcdfe079e43ac574d872d0b18953a32/kitty/model/low_level/aliases.py#L327-L333
ambakick/Person-Detection-and-Tracking
f925394ac29b5cf321f1ce89a71b193381519a0b
utils/np_box_mask_list_ops.py
python
iou
(box_mask_list1, box_mask_list2)
return np_mask_ops.iou(box_mask_list1.get_masks(), box_mask_list2.get_masks())
Computes pairwise intersection-over-union between box and mask collections. Args: box_mask_list1: BoxMaskList holding N boxes and masks box_mask_list2: BoxMaskList holding M boxes and masks Returns: a numpy array with shape [N, M] representing pairwise iou scores.
Computes pairwise intersection-over-union between box and mask collections.
[ "Computes", "pairwise", "intersection", "-", "over", "-", "union", "between", "box", "and", "mask", "collections", "." ]
def iou(box_mask_list1, box_mask_list2): """Computes pairwise intersection-over-union between box and mask collections. Args: box_mask_list1: BoxMaskList holding N boxes and masks box_mask_list2: BoxMaskList holding M boxes and masks Returns: a numpy array with shape [N, M] representing pairwise iou scores. """ return np_mask_ops.iou(box_mask_list1.get_masks(), box_mask_list2.get_masks())
[ "def", "iou", "(", "box_mask_list1", ",", "box_mask_list2", ")", ":", "return", "np_mask_ops", ".", "iou", "(", "box_mask_list1", ".", "get_masks", "(", ")", ",", "box_mask_list2", ".", "get_masks", "(", ")", ")" ]
https://github.com/ambakick/Person-Detection-and-Tracking/blob/f925394ac29b5cf321f1ce89a71b193381519a0b/utils/np_box_mask_list_ops.py#L79-L90
horazont/aioxmpp
c701e6399c90a6bb9bec0349018a03bd7b644cde
aioxmpp/security_layer.py
python
make
( password_provider, *, pin_store=None, pin_type=PinType.PUBLIC_KEY, post_handshake_deferred_failure=None, anonymous=False, ssl_context_factory=default_ssl_context, no_verify=False)
return SecurityLayer( ssl_context_factory, certificate_verifier_factory, True, tuple(sasl_providers), )
Construct a :class:`SecurityLayer`. Depending on the arguments passed, different features are enabled or disabled. .. warning:: When using any argument except `password_provider`, be sure to read its documentation below the following overview **carefully**. Many arguments can be used to shoot yourself in the foot easily, while violating all security expectations. Args: password_provider (:class:`str` or coroutine function): Password source to authenticate with. Keyword Args: pin_store (:class:`dict` or :class:`AbstractPinStore`): Enable use of certificate/public key pinning. `pin_type` controls the type of store used when a dict is passed instead of a pin store object. pin_type (:class:`~aioxmpp.security_layer.PinType`): Type of pin store to create when `pin_store` is a dict. post_handshake_deferred_failure (coroutine function): Coroutine callback to invoke when using certificate pinning and the verification of the certificate was not possible using either PKIX or the pin store. anonymous (:class:`str`, :data:`None` or :data:`False`): trace token for SASL ANONYMOUS (:rfc:`4505`); passing a non-:data:`False` value enables ANONYMOUS authentication. ssl_context_factory (function): Factory function to create the SSL context used to establish transport layer security. Defaults to :func:`aioxmpp.security_layer.default_ssl_context`. no_verify (:class:`bool`): *Disable* all certificate verification. Usage is **strongly discouraged** outside controlled test environments. See below for alternatives. Raises: RuntimeError: if `anonymous` is not :data:`False` and the version of :mod:`aiosasl` does not support ANONYMOUS authentication. Returns: :class:`SecurityLayer`: object holding the entire security layer configuration `password_provider` must either be a coroutine function or a :class:`str`. As a coroutine function, it is called during authentication with the JID we are trying to authenticate against as the first, and the sequence number of the authentication attempt as second argument. The sequence number starts at 0. The coroutine is expected to return :data:`None` or a password. See :class:`PasswordSASLProvider` for details. If `password_provider` is a :class:`str`, a coroutine which returns the string on the first and :data:`None` on subsequent attempts is created and used. If `pin_store` is not :data:`None`, :class:`PinningPKIXCertificateVerifier` is used instead of the default :class:`PKIXCertificateVerifier`. The `pin_store` argument determines the pinned certificates: if it is a dictionary, a :class:`AbstractPinStore` according to the :class:`PinType` passed as `pin_type` argument is created and initialised with the data from the dictionary using its :meth:`~AbstractPinStore.import_from_json` method. Otherwise, `pin_store` must be a :class:`AbstractPinStore` instance which is passed to the verifier. `post_handshake_deferred_callback` is used only if `pin_store` is not :data:`None`. It is passed to the equally-named argument of :class:`PinningPKIXCertificateVerifier`, see the documentation there for details on the semantics. If `post_handshake_deferred_callback` is :data:`None` while `pin_store` is not, a coroutine which returns :data:`False` is substituted. `ssl_context_factory` can be a callable taking no arguments and returning a :class:`OpenSSL.SSL.Context` object. If given, the factory will be used to obtain an SSL context when the stream negotiates transport layer security via TLS. By default, :func:`aioxmpp.security_layer.default_ssl_context` is used, which should be fine for most applications. .. warning:: The :func:`~.default_ssl_context` implementation sets important defaults. It is **strongly recommended** to use the context returned by :func:`~.default_ssl_context` and modify it, instead of creating a new context from scratch when implementing your own factory. If `no_verify` is true, none of the above regarding certificate verifiers matters. The internal null verifier is used, which **disables certificate verification completely**. .. warning:: Disabling certificate verification makes your application vulnerable to trivial Man-in-the-Middle attacks. Do **not** use this outside controlled test environments or when you know **exactly** what you’re doing! If you need to handle certificates which cannot be verified using the public key infrastructure, consider making use of the `pin_store` argument instead. `anonymous` may be a string or :data:`False`. If it is not :data:`False`, :class:`AnonymousSASLProvider` is used before password based authentication is attempted. In addition, it is allowed to set `password_provider` to :data:`None`. `anonymous` is the trace token to use, and SHOULD be the empty string (as specified by :xep:`175`). This requires :mod:`aiosasl` 0.3 or newer. .. note:: :data:`False` and ``""`` are treated differently for the `anonymous` argument, despite both being false-y values! .. note:: If `anonymous` is not :data:`False` and `password_provider` is not :data:`None`, both authentication types are attempted. Anonymous authentication is, in that case, preferred over password-based authentication. If you need to reverse the order, you have to construct your own :class:`SecurityLayer` object. .. warning:: Take the security and privacy considerations from :rfc:`4505` (which specifies the ANONYMOUS SASL mechanism) and :xep:`175` (which discusses the ANONYMOUS SASL mechanism in the XMPP context) into account before using `anonymous`. The versatility and simplicity of use of this function make (pun intended) it the preferred way to construct :class:`SecurityLayer` instances. .. versionadded:: 0.8 Support for SASL ANONYMOUS was added. .. versionadded:: 0.11 Support for `ssl_context_factory`.
Construct a :class:`SecurityLayer`. Depending on the arguments passed, different features are enabled or disabled.
[ "Construct", "a", ":", "class", ":", "SecurityLayer", ".", "Depending", "on", "the", "arguments", "passed", "different", "features", "are", "enabled", "or", "disabled", "." ]
def make( password_provider, *, pin_store=None, pin_type=PinType.PUBLIC_KEY, post_handshake_deferred_failure=None, anonymous=False, ssl_context_factory=default_ssl_context, no_verify=False): """ Construct a :class:`SecurityLayer`. Depending on the arguments passed, different features are enabled or disabled. .. warning:: When using any argument except `password_provider`, be sure to read its documentation below the following overview **carefully**. Many arguments can be used to shoot yourself in the foot easily, while violating all security expectations. Args: password_provider (:class:`str` or coroutine function): Password source to authenticate with. Keyword Args: pin_store (:class:`dict` or :class:`AbstractPinStore`): Enable use of certificate/public key pinning. `pin_type` controls the type of store used when a dict is passed instead of a pin store object. pin_type (:class:`~aioxmpp.security_layer.PinType`): Type of pin store to create when `pin_store` is a dict. post_handshake_deferred_failure (coroutine function): Coroutine callback to invoke when using certificate pinning and the verification of the certificate was not possible using either PKIX or the pin store. anonymous (:class:`str`, :data:`None` or :data:`False`): trace token for SASL ANONYMOUS (:rfc:`4505`); passing a non-:data:`False` value enables ANONYMOUS authentication. ssl_context_factory (function): Factory function to create the SSL context used to establish transport layer security. Defaults to :func:`aioxmpp.security_layer.default_ssl_context`. no_verify (:class:`bool`): *Disable* all certificate verification. Usage is **strongly discouraged** outside controlled test environments. See below for alternatives. Raises: RuntimeError: if `anonymous` is not :data:`False` and the version of :mod:`aiosasl` does not support ANONYMOUS authentication. Returns: :class:`SecurityLayer`: object holding the entire security layer configuration `password_provider` must either be a coroutine function or a :class:`str`. As a coroutine function, it is called during authentication with the JID we are trying to authenticate against as the first, and the sequence number of the authentication attempt as second argument. The sequence number starts at 0. The coroutine is expected to return :data:`None` or a password. See :class:`PasswordSASLProvider` for details. If `password_provider` is a :class:`str`, a coroutine which returns the string on the first and :data:`None` on subsequent attempts is created and used. If `pin_store` is not :data:`None`, :class:`PinningPKIXCertificateVerifier` is used instead of the default :class:`PKIXCertificateVerifier`. The `pin_store` argument determines the pinned certificates: if it is a dictionary, a :class:`AbstractPinStore` according to the :class:`PinType` passed as `pin_type` argument is created and initialised with the data from the dictionary using its :meth:`~AbstractPinStore.import_from_json` method. Otherwise, `pin_store` must be a :class:`AbstractPinStore` instance which is passed to the verifier. `post_handshake_deferred_callback` is used only if `pin_store` is not :data:`None`. It is passed to the equally-named argument of :class:`PinningPKIXCertificateVerifier`, see the documentation there for details on the semantics. If `post_handshake_deferred_callback` is :data:`None` while `pin_store` is not, a coroutine which returns :data:`False` is substituted. `ssl_context_factory` can be a callable taking no arguments and returning a :class:`OpenSSL.SSL.Context` object. If given, the factory will be used to obtain an SSL context when the stream negotiates transport layer security via TLS. By default, :func:`aioxmpp.security_layer.default_ssl_context` is used, which should be fine for most applications. .. warning:: The :func:`~.default_ssl_context` implementation sets important defaults. It is **strongly recommended** to use the context returned by :func:`~.default_ssl_context` and modify it, instead of creating a new context from scratch when implementing your own factory. If `no_verify` is true, none of the above regarding certificate verifiers matters. The internal null verifier is used, which **disables certificate verification completely**. .. warning:: Disabling certificate verification makes your application vulnerable to trivial Man-in-the-Middle attacks. Do **not** use this outside controlled test environments or when you know **exactly** what you’re doing! If you need to handle certificates which cannot be verified using the public key infrastructure, consider making use of the `pin_store` argument instead. `anonymous` may be a string or :data:`False`. If it is not :data:`False`, :class:`AnonymousSASLProvider` is used before password based authentication is attempted. In addition, it is allowed to set `password_provider` to :data:`None`. `anonymous` is the trace token to use, and SHOULD be the empty string (as specified by :xep:`175`). This requires :mod:`aiosasl` 0.3 or newer. .. note:: :data:`False` and ``""`` are treated differently for the `anonymous` argument, despite both being false-y values! .. note:: If `anonymous` is not :data:`False` and `password_provider` is not :data:`None`, both authentication types are attempted. Anonymous authentication is, in that case, preferred over password-based authentication. If you need to reverse the order, you have to construct your own :class:`SecurityLayer` object. .. warning:: Take the security and privacy considerations from :rfc:`4505` (which specifies the ANONYMOUS SASL mechanism) and :xep:`175` (which discusses the ANONYMOUS SASL mechanism in the XMPP context) into account before using `anonymous`. The versatility and simplicity of use of this function make (pun intended) it the preferred way to construct :class:`SecurityLayer` instances. .. versionadded:: 0.8 Support for SASL ANONYMOUS was added. .. versionadded:: 0.11 Support for `ssl_context_factory`. """ if isinstance(password_provider, str): static_password = password_provider async def password_provider(jid, nattempt): if nattempt == 0: return static_password return None if pin_store is not None: if post_handshake_deferred_failure is None: async def post_handshake_deferred_failure(verifier): return False if not isinstance(pin_store, AbstractPinStore): pin_data = pin_store if pin_type == PinType.PUBLIC_KEY: logger.debug("using PublicKeyPinStore") pin_store = PublicKeyPinStore() else: logger.debug("using CertificatePinStore") pin_store = CertificatePinStore() pin_store.import_from_json(pin_data) def certificate_verifier_factory(): return PinningPKIXCertificateVerifier( pin_store.query, post_handshake_deferred_failure, ) elif no_verify: certificate_verifier_factory = _NullVerifier else: certificate_verifier_factory = PKIXCertificateVerifier sasl_providers = [] if anonymous is not False: if AnonymousSASLProvider is None: raise RuntimeError( "aiosasl does not support ANONYMOUS, please upgrade" ) sasl_providers.append( AnonymousSASLProvider(anonymous) ) if password_provider is not None: sasl_providers.append( PasswordSASLProvider( password_provider, ), ) return SecurityLayer( ssl_context_factory, certificate_verifier_factory, True, tuple(sasl_providers), )
[ "def", "make", "(", "password_provider", ",", "*", ",", "pin_store", "=", "None", ",", "pin_type", "=", "PinType", ".", "PUBLIC_KEY", ",", "post_handshake_deferred_failure", "=", "None", ",", "anonymous", "=", "False", ",", "ssl_context_factory", "=", "default_s...
https://github.com/horazont/aioxmpp/blob/c701e6399c90a6bb9bec0349018a03bd7b644cde/aioxmpp/security_layer.py#L1292-L1497
MozillaSecurity/grizzly
1c41478e32f323189a2c322ec041c3e0902a158a
grizzly/replay/crash.py
python
modify_args
(args, crash, bucket)
return args
Arguments: args (argparse.Namespace): Result from `ReplayArgs.parse_args`. Returns: args (argparse.Namespace): Modified arguments.
[]
def modify_args(args, crash, bucket): """ Arguments: args (argparse.Namespace): Result from `ReplayArgs.parse_args`. Returns: args (argparse.Namespace): Modified arguments. """ args.original_crash_id = args.input args.input = str(crash.testcase_path()) if args.tool is None: LOG.info("Setting default --tool=%s from CrashEntry", crash.tool) args.tool = crash.tool # load signature if needed if bucket is not None: args.sig = str(bucket.signature_path()) return args
[ "def", "modify_args", "(", "args", ",", "crash", ",", "bucket", ")", ":", "args", ".", "original_crash_id", "=", "args", ".", "input", "args", ".", "input", "=", "str", "(", "crash", ".", "testcase_path", "(", ")", ")", "if", "args", ".", "tool", "is...
https://github.com/MozillaSecurity/grizzly/blob/1c41478e32f323189a2c322ec041c3e0902a158a/grizzly/replay/crash.py#L32-L53
mandarjoshi90/coref
bd04f2e19b9dcc0b8bba848a335e4af3be50741c
bert/modeling.py
python
reshape_to_matrix
(input_tensor)
return output_tensor
Reshapes a >= rank 2 tensor to a rank 2 tensor (i.e., a matrix).
Reshapes a >= rank 2 tensor to a rank 2 tensor (i.e., a matrix).
[ "Reshapes", "a", ">", "=", "rank", "2", "tensor", "to", "a", "rank", "2", "tensor", "(", "i", ".", "e", ".", "a", "matrix", ")", "." ]
def reshape_to_matrix(input_tensor): """Reshapes a >= rank 2 tensor to a rank 2 tensor (i.e., a matrix).""" ndims = input_tensor.shape.ndims if ndims < 2: raise ValueError("Input tensor must have at least rank 2. Shape = %s" % (input_tensor.shape)) if ndims == 2: return input_tensor width = input_tensor.shape[-1] output_tensor = tf.reshape(input_tensor, [-1, width]) return output_tensor
[ "def", "reshape_to_matrix", "(", "input_tensor", ")", ":", "ndims", "=", "input_tensor", ".", "shape", ".", "ndims", "if", "ndims", "<", "2", ":", "raise", "ValueError", "(", "\"Input tensor must have at least rank 2. Shape = %s\"", "%", "(", "input_tensor", ".", ...
https://github.com/mandarjoshi90/coref/blob/bd04f2e19b9dcc0b8bba848a335e4af3be50741c/bert/modeling.py#L937-L948
replit-archive/empythoned
977ec10ced29a3541a4973dc2b59910805695752
dist/lib/python2.7/imaplib.py
python
Time2Internaldate
(date_time)
return '"' + dt + " %+03d%02d" % divmod(zone//60, 60) + '"'
Convert date_time to IMAP4 INTERNALDATE representation. Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'. The date_time argument can be a number (int or float) representing seconds since epoch (as returned by time.time()), a 9-tuple representing local time (as returned by time.localtime()), or a double-quoted string. In the last case, it is assumed to already be in the correct format.
Convert date_time to IMAP4 INTERNALDATE representation.
[ "Convert", "date_time", "to", "IMAP4", "INTERNALDATE", "representation", "." ]
def Time2Internaldate(date_time): """Convert date_time to IMAP4 INTERNALDATE representation. Return string in form: '"DD-Mmm-YYYY HH:MM:SS +HHMM"'. The date_time argument can be a number (int or float) representing seconds since epoch (as returned by time.time()), a 9-tuple representing local time (as returned by time.localtime()), or a double-quoted string. In the last case, it is assumed to already be in the correct format. """ if isinstance(date_time, (int, float)): tt = time.localtime(date_time) elif isinstance(date_time, (tuple, time.struct_time)): tt = date_time elif isinstance(date_time, str) and (date_time[0],date_time[-1]) == ('"','"'): return date_time # Assume in correct format else: raise ValueError("date_time not of a known type") dt = time.strftime("%d-%b-%Y %H:%M:%S", tt) if dt[0] == '0': dt = ' ' + dt[1:] if time.daylight and tt[-1]: zone = -time.altzone else: zone = -time.timezone return '"' + dt + " %+03d%02d" % divmod(zone//60, 60) + '"'
[ "def", "Time2Internaldate", "(", "date_time", ")", ":", "if", "isinstance", "(", "date_time", ",", "(", "int", ",", "float", ")", ")", ":", "tt", "=", "time", ".", "localtime", "(", "date_time", ")", "elif", "isinstance", "(", "date_time", ",", "(", "t...
https://github.com/replit-archive/empythoned/blob/977ec10ced29a3541a4973dc2b59910805695752/dist/lib/python2.7/imaplib.py#L1382-L1410
tdamdouni/Pythonista
3e082d53b6b9b501a3c8cf3251a8ad4c8be9c2ad
stash/autopep8.py
python
standard_deviation
(numbers)
return (sum((n - mean) ** 2 for n in numbers) / len(numbers)) ** .5
Return standard devation.
Return standard devation.
[ "Return", "standard", "devation", "." ]
def standard_deviation(numbers): """Return standard devation.""" numbers = list(numbers) if not numbers: return 0 mean = sum(numbers) / len(numbers) return (sum((n - mean) ** 2 for n in numbers) / len(numbers)) ** .5
[ "def", "standard_deviation", "(", "numbers", ")", ":", "numbers", "=", "list", "(", "numbers", ")", "if", "not", "numbers", ":", "return", "0", "mean", "=", "sum", "(", "numbers", ")", "/", "len", "(", "numbers", ")", "return", "(", "sum", "(", "(", ...
https://github.com/tdamdouni/Pythonista/blob/3e082d53b6b9b501a3c8cf3251a8ad4c8be9c2ad/stash/autopep8.py#L3445-L3452
google/grr
8ad8a4d2c5a93c92729206b7771af19d92d4f915
grr/server/grr_response_server/gui/api_call_router_with_approval_checks.py
python
ApiCallRouterWithApprovalChecks.GetFleetspeakPendingMessageCount
( self, args: api_client.ApiGetFleetspeakPendingMessageCountArgs, context: Optional[api_call_context.ApiCallContext] = None )
return self.delegate.GetFleetspeakPendingMessageCount(args, context=context)
[]
def GetFleetspeakPendingMessageCount( self, args: api_client.ApiGetFleetspeakPendingMessageCountArgs, context: Optional[api_call_context.ApiCallContext] = None ) -> api_client.ApiGetFleetspeakPendingMessageCountHandler: self.access_checker.CheckClientAccess(context, args.client_id) return self.delegate.GetFleetspeakPendingMessageCount(args, context=context)
[ "def", "GetFleetspeakPendingMessageCount", "(", "self", ",", "args", ":", "api_client", ".", "ApiGetFleetspeakPendingMessageCountArgs", ",", "context", ":", "Optional", "[", "api_call_context", ".", "ApiCallContext", "]", "=", "None", ")", "->", "api_client", ".", "...
https://github.com/google/grr/blob/8ad8a4d2c5a93c92729206b7771af19d92d4f915/grr/server/grr_response_server/gui/api_call_router_with_approval_checks.py#L253-L259
awslabs/deeplearning-benchmark
3e9a906422b402869537f91056ae771b66487a8e
word_language_model/lstm_bucketing.py
python
tokenize_text
(fname, vocab=None, invalid_label=-1, start_label=0)
return sentences, vocab
[]
def tokenize_text(fname, vocab=None, invalid_label=-1, start_label=0): try: assert os.path.exists(fname) except AssertionError: subprocess.call(['{}/get_ptb_data.sh'.format(os.path.dirname(__file__))]) assert os.path.exists(fname) lines = open(fname).readlines() lines = [filter(None, i.split(' ')) for i in lines] sentences, vocab = mx.rnn.encode_sentences(lines, vocab=vocab, invalid_label=invalid_label, start_label=start_label) return sentences, vocab
[ "def", "tokenize_text", "(", "fname", ",", "vocab", "=", "None", ",", "invalid_label", "=", "-", "1", ",", "start_label", "=", "0", ")", ":", "try", ":", "assert", "os", ".", "path", ".", "exists", "(", "fname", ")", "except", "AssertionError", ":", ...
https://github.com/awslabs/deeplearning-benchmark/blob/3e9a906422b402869537f91056ae771b66487a8e/word_language_model/lstm_bucketing.py#L51-L61
scipy/scipy
e0a749f01e79046642ccfdc419edbf9e7ca141ad
scipy/_lib/_uarray/_backend.py
python
generate_multimethod
( argument_extractor: ArgumentExtractorType, argument_replacer: ArgumentReplacerType, domain: str, default: typing.Optional[typing.Callable] = None, )
return functools.update_wrapper(ua_func, argument_extractor)
Generates a multimethod. Parameters ---------- argument_extractor : ArgumentExtractorType A callable which extracts the dispatchable arguments. Extracted arguments should be marked by the :obj:`Dispatchable` class. It has the same signature as the desired multimethod. argument_replacer : ArgumentReplacerType A callable with the signature (args, kwargs, dispatchables), which should also return an (args, kwargs) pair with the dispatchables replaced inside the args/kwargs. domain : str A string value indicating the domain of this multimethod. default : Optional[Callable], optional The default implementation of this multimethod, where ``None`` (the default) specifies there is no default implementation. Examples -------- In this example, ``a`` is to be dispatched over, so we return it, while marking it as an ``int``. The trailing comma is needed because the args have to be returned as an iterable. >>> def override_me(a, b): ... return Dispatchable(a, int), Next, we define the argument replacer that replaces the dispatchables inside args/kwargs with the supplied ones. >>> def override_replacer(args, kwargs, dispatchables): ... return (dispatchables[0], args[1]), {} Next, we define the multimethod. >>> overridden_me = generate_multimethod( ... override_me, override_replacer, "ua_examples" ... ) Notice that there's no default implementation, unless you supply one. >>> overridden_me(1, "a") Traceback (most recent call last): ... uarray.BackendNotImplementedError: ... >>> overridden_me2 = generate_multimethod( ... override_me, override_replacer, "ua_examples", default=lambda x, y: (x, y) ... ) >>> overridden_me2(1, "a") (1, 'a') See Also -------- uarray : See the module documentation for how to override the method by creating backends.
Generates a multimethod.
[ "Generates", "a", "multimethod", "." ]
def generate_multimethod( argument_extractor: ArgumentExtractorType, argument_replacer: ArgumentReplacerType, domain: str, default: typing.Optional[typing.Callable] = None, ): """ Generates a multimethod. Parameters ---------- argument_extractor : ArgumentExtractorType A callable which extracts the dispatchable arguments. Extracted arguments should be marked by the :obj:`Dispatchable` class. It has the same signature as the desired multimethod. argument_replacer : ArgumentReplacerType A callable with the signature (args, kwargs, dispatchables), which should also return an (args, kwargs) pair with the dispatchables replaced inside the args/kwargs. domain : str A string value indicating the domain of this multimethod. default : Optional[Callable], optional The default implementation of this multimethod, where ``None`` (the default) specifies there is no default implementation. Examples -------- In this example, ``a`` is to be dispatched over, so we return it, while marking it as an ``int``. The trailing comma is needed because the args have to be returned as an iterable. >>> def override_me(a, b): ... return Dispatchable(a, int), Next, we define the argument replacer that replaces the dispatchables inside args/kwargs with the supplied ones. >>> def override_replacer(args, kwargs, dispatchables): ... return (dispatchables[0], args[1]), {} Next, we define the multimethod. >>> overridden_me = generate_multimethod( ... override_me, override_replacer, "ua_examples" ... ) Notice that there's no default implementation, unless you supply one. >>> overridden_me(1, "a") Traceback (most recent call last): ... uarray.BackendNotImplementedError: ... >>> overridden_me2 = generate_multimethod( ... override_me, override_replacer, "ua_examples", default=lambda x, y: (x, y) ... ) >>> overridden_me2(1, "a") (1, 'a') See Also -------- uarray : See the module documentation for how to override the method by creating backends. """ kw_defaults, arg_defaults, opts = get_defaults(argument_extractor) ua_func = _Function( argument_extractor, argument_replacer, domain, arg_defaults, kw_defaults, default, ) return functools.update_wrapper(ua_func, argument_extractor)
[ "def", "generate_multimethod", "(", "argument_extractor", ":", "ArgumentExtractorType", ",", "argument_replacer", ":", "ArgumentReplacerType", ",", "domain", ":", "str", ",", "default", ":", "typing", ".", "Optional", "[", "typing", ".", "Callable", "]", "=", "Non...
https://github.com/scipy/scipy/blob/e0a749f01e79046642ccfdc419edbf9e7ca141ad/scipy/_lib/_uarray/_backend.py#L169-L241
akfamily/akshare
590e50eece9ec067da3538c7059fd660b71f1339
akshare/futures/cons.py
python
get_json_path
(name, module_file)
return module_json_path
获取 JSON 配置文件的路径(从模块所在目录查找) :param name: 文件名 :param module_file: filename :return: str json_file_path
获取 JSON 配置文件的路径(从模块所在目录查找) :param name: 文件名 :param module_file: filename :return: str json_file_path
[ "获取", "JSON", "配置文件的路径", "(", "从模块所在目录查找", ")", ":", "param", "name", ":", "文件名", ":", "param", "module_file", ":", "filename", ":", "return", ":", "str", "json_file_path" ]
def get_json_path(name, module_file): """ 获取 JSON 配置文件的路径(从模块所在目录查找) :param name: 文件名 :param module_file: filename :return: str json_file_path """ module_folder = os.path.abspath(os.path.dirname(os.path.dirname(module_file))) module_json_path = os.path.join(module_folder, "file_fold", name) return module_json_path
[ "def", "get_json_path", "(", "name", ",", "module_file", ")", ":", "module_folder", "=", "os", ".", "path", ".", "abspath", "(", "os", ".", "path", ".", "dirname", "(", "os", ".", "path", ".", "dirname", "(", "module_file", ")", ")", ")", "module_json_...
https://github.com/akfamily/akshare/blob/590e50eece9ec067da3538c7059fd660b71f1339/akshare/futures/cons.py#L436-L445
YichenGong/Densely-Interactive-Inference-Network
cb2c23bc1aca7cafb523104b0db07df2332a877a
python/my/tensorflow/rnn_cell.py
python
TreeRNNCell.__call__
(self, inputs, state, scope=None)
:param inputs: [N*B, I + B] :param state: [N*B, d] :param scope: :return: [N*B, d]
:param inputs: [N*B, I + B] :param state: [N*B, d] :param scope: :return: [N*B, d]
[ ":", "param", "inputs", ":", "[", "N", "*", "B", "I", "+", "B", "]", ":", "param", "state", ":", "[", "N", "*", "B", "d", "]", ":", "param", "scope", ":", ":", "return", ":", "[", "N", "*", "B", "d", "]" ]
def __call__(self, inputs, state, scope=None): """ :param inputs: [N*B, I + B] :param state: [N*B, d] :param scope: :return: [N*B, d] """ with tf.variable_scope(scope or self.__class__.__name__): d = self.state_size x = tf.slice(inputs, [0, 0], [-1, self._input_size]) # [N*B, I] mask = tf.slice(inputs, [0, self._input_size], [-1, -1]) # [N*B, B] B = tf.shape(mask)[1] prev_state = tf.expand_dims(tf.reshape(state, [-1, B, d]), 1) # [N, B, d] -> [N, 1, B, d] mask = tf.tile(tf.expand_dims(tf.reshape(mask, [-1, B, B]), -1), [1, 1, 1, d]) # [N, B, B, d] # prev_state = self._reduce_func(tf.tile(prev_state, [1, B, 1, 1]), 2) prev_state = self._reduce_func(exp_mask(prev_state, mask), 2) # [N, B, d] prev_state = tf.reshape(prev_state, [-1, d]) # [N*B, d] return self._cell(x, prev_state)
[ "def", "__call__", "(", "self", ",", "inputs", ",", "state", ",", "scope", "=", "None", ")", ":", "with", "tf", ".", "variable_scope", "(", "scope", "or", "self", ".", "__class__", ".", "__name__", ")", ":", "d", "=", "self", ".", "state_size", "x", ...
https://github.com/YichenGong/Densely-Interactive-Inference-Network/blob/cb2c23bc1aca7cafb523104b0db07df2332a877a/python/my/tensorflow/rnn_cell.py#L34-L51
numenta/nupic
b9ebedaf54f49a33de22d8d44dff7c765cdb5548
external/linux32/lib/python2.6/site-packages/matplotlib/axes.py
python
Axes.__pick
(self, x, y, trans=None, among=None)
return ds[0][1]
Return the artist under point that is closest to the *x*, *y*. If *trans* is *None*, *x*, and *y* are in window coords, (0,0 = lower left). Otherwise, *trans* is a :class:`~matplotlib.transforms.Transform` that specifies the coordinate system of *x*, *y*. The selection of artists from amongst which the pick function finds an artist can be narrowed using the optional keyword argument *among*. If provided, this should be either a sequence of permitted artists or a function taking an artist as its argument and returning a true value if and only if that artist can be selected. Note this algorithm calculates distance to the vertices of the polygon, so if you want to pick a patch, click on the edge!
Return the artist under point that is closest to the *x*, *y*. If *trans* is *None*, *x*, and *y* are in window coords, (0,0 = lower left). Otherwise, *trans* is a :class:`~matplotlib.transforms.Transform` that specifies the coordinate system of *x*, *y*.
[ "Return", "the", "artist", "under", "point", "that", "is", "closest", "to", "the", "*", "x", "*", "*", "y", "*", ".", "If", "*", "trans", "*", "is", "*", "None", "*", "*", "x", "*", "and", "*", "y", "*", "are", "in", "window", "coords", "(", ...
def __pick(self, x, y, trans=None, among=None): """ Return the artist under point that is closest to the *x*, *y*. If *trans* is *None*, *x*, and *y* are in window coords, (0,0 = lower left). Otherwise, *trans* is a :class:`~matplotlib.transforms.Transform` that specifies the coordinate system of *x*, *y*. The selection of artists from amongst which the pick function finds an artist can be narrowed using the optional keyword argument *among*. If provided, this should be either a sequence of permitted artists or a function taking an artist as its argument and returning a true value if and only if that artist can be selected. Note this algorithm calculates distance to the vertices of the polygon, so if you want to pick a patch, click on the edge! """ # MGDTODO: Needs updating if trans is not None: xywin = trans.transform_point((x,y)) else: xywin = x,y def dist_points(p1, p2): 'return the distance between two points' x1, y1 = p1 x2, y2 = p2 return math.sqrt((x1-x2)**2+(y1-y2)**2) def dist_x_y(p1, x, y): '*x* and *y* are arrays; return the distance to the closest point' x1, y1 = p1 return min(np.sqrt((x-x1)**2+(y-y1)**2)) def dist(a): if isinstance(a, Text): bbox = a.get_window_extent() l,b,w,h = bbox.bounds verts = (l,b), (l,b+h), (l+w,b+h), (l+w, b) xt, yt = zip(*verts) elif isinstance(a, Patch): path = a.get_path() tverts = a.get_transform().transform_path(path) xt, yt = zip(*tverts) elif isinstance(a, mlines.Line2D): xdata = a.get_xdata(orig=False) ydata = a.get_ydata(orig=False) xt, yt = a.get_transform().numerix_x_y(xdata, ydata) return dist_x_y(xywin, np.asarray(xt), np.asarray(yt)) artists = self.lines + self.patches + self.texts if callable(among): artists = filter(test, artists) elif iterable(among): amongd = dict([(k,1) for k in among]) artists = [a for a in artists if a in amongd] elif among is None: pass else: raise ValueError('among must be callable or iterable') if not len(artists): return None ds = [ (dist(a),a) for a in artists] ds.sort() return ds[0][1]
[ "def", "__pick", "(", "self", ",", "x", ",", "y", ",", "trans", "=", "None", ",", "among", "=", "None", ")", ":", "# MGDTODO: Needs updating", "if", "trans", "is", "not", "None", ":", "xywin", "=", "trans", ".", "transform_point", "(", "(", "x", ",",...
https://github.com/numenta/nupic/blob/b9ebedaf54f49a33de22d8d44dff7c765cdb5548/external/linux32/lib/python2.6/site-packages/matplotlib/axes.py#L2487-L2552
deluge-torrent/deluge
2316088f5c0dd6cb044d9d4832fa7d56dcc79cdc
deluge/maketorrent.py
python
TorrentMetadata.set_pad_files
(self, pad)
Enable padding files for the torrent. Args: private (bool): True adds padding files to align files on piece boundaries.
Enable padding files for the torrent.
[ "Enable", "padding", "files", "for", "the", "torrent", "." ]
def set_pad_files(self, pad): """Enable padding files for the torrent. Args: private (bool): True adds padding files to align files on piece boundaries. """ self.__pad_files = pad
[ "def", "set_pad_files", "(", "self", ",", "pad", ")", ":", "self", ".", "__pad_files", "=", "pad" ]
https://github.com/deluge-torrent/deluge/blob/2316088f5c0dd6cb044d9d4832fa7d56dcc79cdc/deluge/maketorrent.py#L361-L368
shunyaoshih/TPA-LSTM
598cfc90f778856084f0ca80b463894e7ea26481
lib/data_generator.py
python
DataGenerator._float_list_feature
(self, value)
return tf.train.Feature(float_list=tf.train.FloatList(value=value))
[]
def _float_list_feature(self, value): return tf.train.Feature(float_list=tf.train.FloatList(value=value))
[ "def", "_float_list_feature", "(", "self", ",", "value", ")", ":", "return", "tf", ".", "train", ".", "Feature", "(", "float_list", "=", "tf", ".", "train", ".", "FloatList", "(", "value", "=", "value", ")", ")" ]
https://github.com/shunyaoshih/TPA-LSTM/blob/598cfc90f778856084f0ca80b463894e7ea26481/lib/data_generator.py#L89-L90
IntelPython/sdc
1ebf55c00ef38dfbd401a70b3945e352a5a38b87
sdc/utilities/utils.py
python
gen_getitem
(out_var, in_var, ind, calltypes, nodes)
[]
def gen_getitem(out_var, in_var, ind, calltypes, nodes): loc = out_var.loc getitem = ir.Expr.static_getitem(in_var, ind, None, loc) calltypes[getitem] = None nodes.append(ir.Assign(getitem, out_var, loc))
[ "def", "gen_getitem", "(", "out_var", ",", "in_var", ",", "ind", ",", "calltypes", ",", "nodes", ")", ":", "loc", "=", "out_var", ".", "loc", "getitem", "=", "ir", ".", "Expr", ".", "static_getitem", "(", "in_var", ",", "ind", ",", "None", ",", "loc"...
https://github.com/IntelPython/sdc/blob/1ebf55c00ef38dfbd401a70b3945e352a5a38b87/sdc/utilities/utils.py#L525-L529
dowjones/hammer
674028a067cad91ce1a84577d30afe7b895f2a6a
hammer/reporting-remediation/reporting/create_s3bucket_acl_issue_tickets.py
python
CreateS3BucketsTickets.create_tickets_s3buckets
(self)
Class method to create jira tickets
Class method to create jira tickets
[ "Class", "method", "to", "create", "jira", "tickets" ]
def create_tickets_s3buckets(self): """ Class method to create jira tickets """ table_name = self.config.s3acl.ddb_table_name main_account = Account(region=self.config.aws.region) ddb_table = main_account.resource("dynamodb").Table(table_name) jira = JiraReporting(self.config) slack = SlackNotification(self.config) for account_id, account_name in self.config.s3acl.accounts.items(): logging.debug(f"Checking '{account_name} / {account_id}'") issues = IssueOperations.get_account_not_closed_issues(ddb_table, account_id, S3AclIssue) for issue in issues: bucket_name = issue.issue_id tags = issue.issue_details.tags # issue has been already reported if issue.timestamps.reported is not None: owner = issue.issue_details.owner bu = issue.jira_details.business_unit product = issue.jira_details.product if issue.status in [IssueStatus.Resolved, IssueStatus.Whitelisted]: logging.debug(f"Closing {issue.status.value} S3 bucket '{bucket_name}' public ACL issue") comment = (f"Closing {issue.status.value} S3 bucket '{bucket_name}' public ACL issue " f"in '{account_name} / {account_id}' account") if issue.status == IssueStatus.Whitelisted: # Adding label with "whitelisted" to jira ticket. jira.add_label( ticket_id=issue.jira_details.ticket, label=IssueStatus.Whitelisted.value ) jira.close_issue( ticket_id=issue.jira_details.ticket, comment=comment ) slack.report_issue( msg=f"{comment}" f"{' (' + jira.ticket_url(issue.jira_details.ticket) + ')' if issue.jira_details.ticket else ''}", owner=owner, account_id=account_id, bu=bu, product=product, ) IssueOperations.set_status_closed(ddb_table, issue) # issue.status != IssueStatus.Closed (should be IssueStatus.Open) elif issue.timestamps.updated > issue.timestamps.reported: logging.debug(f"Updating S3 bucket '{bucket_name}' public ACL issue") comment = "Issue details are changed, please check again.\n" comment += self.build_permissions_table(issue.issue_details.public_acls) comment += JiraOperations.build_tags_table(tags) jira.update_issue( ticket_id=issue.jira_details.ticket, comment=comment ) slack.report_issue( msg=f"S3 bucket '{bucket_name}' pubic ACL issue is changed " f"in '{account_name} / {account_id}' account" f"{' (' + jira.ticket_url(issue.jira_details.ticket) + ')' if issue.jira_details.ticket else ''}", owner=owner, account_id=account_id, bu=bu, product=product, ) IssueOperations.set_status_updated(ddb_table, issue) else: logging.debug(f"No changes for '{bucket_name}'") # issue has not been reported yet else: logging.debug(f"Reporting S3 bucket '{bucket_name}' public ACL issue") owner = tags.get("owner", None) bu = tags.get("bu", None) product = tags.get("product", None) if bu is None: bu = self.config.get_bu_by_name(bucket_name) issue_summary = (f"S3 bucket '{bucket_name}' with public acl " f"in '{account_name} / {account_id}' account{' [' + bu + ']' if bu else ''}") issue_description = ( f"Bucket ACL allows unrestricted public access.\n\n" f"*Threat*: " f"This creates potential security vulnerabilities by allowing anyone to add, modify, or remove items in a bucket.\n\n" f"*Risk*: High\n\n" f"*Account Name*: {account_name}\n" f"*Account ID*: {account_id}\n" f"*S3 Bucket name*: {bucket_name}\n" f"*Bucket Owner*: {owner}\n" f"\n") auto_remediation_date = (self.config.now + self.config.s3acl.issue_retention_date).date() issue_description += f"\n{{color:red}}*Auto-Remediation Date*: {auto_remediation_date}{{color}}\n\n" issue_description += JiraOperations.build_tags_table(tags) issue_description += self.build_permissions_table(issue.issue_details.public_acls) issue_description += f"\n" issue_description += ( f"*Recommendation*: " f"Update bucket permissions to restrict access to the owner or specific users " f"or grant CloudFront OAI applicable permissions on each object that CloudFront distribution serves. " ) if self.config.whitelisting_procedure_url: issue_description += (f"For any other exceptions, please follow the [whitelisting procedure|{self.config.whitelisting_procedure_url}] " f"and provide a strong business reasoning. ") try: response = jira.add_issue( issue_summary=issue_summary, issue_description=issue_description, priority="Major", labels=["publics3"], owner=owner, account_id=account_id, bu=bu, product=product, ) except Exception: logging.exception("Failed to create jira ticket") continue if response is not None: issue.jira_details.ticket = response.ticket_id issue.jira_details.ticket_assignee_id = response.ticket_assignee_id issue.jira_details.owner = owner issue.jira_details.business_unit = bu issue.jira_details.product = product slack.report_issue( msg=f"Discovered {issue_summary}" f"{' (' + jira.ticket_url(issue.jira_details.ticket) + ')' if issue.jira_details.ticket else ''}", owner=owner, account_id=account_id, bu=bu, product=product, ) IssueOperations.set_status_reported(ddb_table, issue)
[ "def", "create_tickets_s3buckets", "(", "self", ")", ":", "table_name", "=", "self", ".", "config", ".", "s3acl", ".", "ddb_table_name", "main_account", "=", "Account", "(", "region", "=", "self", ".", "config", ".", "aws", ".", "region", ")", "ddb_table", ...
https://github.com/dowjones/hammer/blob/674028a067cad91ce1a84577d30afe7b895f2a6a/hammer/reporting-remediation/reporting/create_s3bucket_acl_issue_tickets.py#L30-L167
mdiazcl/fuzzbunch-debian
2b76c2249ade83a389ae3badb12a1bd09901fd2c
windows/Resources/Python/Core/Lib/email/feedparser.py
python
FeedParser.__init__
(self, _factory=message.Message)
return
_factory is called with no arguments to create a new message obj
_factory is called with no arguments to create a new message obj
[ "_factory", "is", "called", "with", "no", "arguments", "to", "create", "a", "new", "message", "obj" ]
def __init__(self, _factory=message.Message): """_factory is called with no arguments to create a new message obj""" self._factory = _factory self._input = BufferedSubFile() self._msgstack = [] self._parse = self._parsegen().next self._cur = None self._last = None self._headersonly = False return
[ "def", "__init__", "(", "self", ",", "_factory", "=", "message", ".", "Message", ")", ":", "self", ".", "_factory", "=", "_factory", "self", ".", "_input", "=", "BufferedSubFile", "(", ")", "self", ".", "_msgstack", "=", "[", "]", "self", ".", "_parse"...
https://github.com/mdiazcl/fuzzbunch-debian/blob/2b76c2249ade83a389ae3badb12a1bd09901fd2c/windows/Resources/Python/Core/Lib/email/feedparser.py#L110-L119
suavecode/SUAVE
4f83c467c5662b6cc611ce2ab6c0bdd25fd5c0a5
trunk/SUAVE/Plots/Performance/Mission_Plots.py
python
plot_battery_pack_conditions
(results, line_color = 'bo-', line_color2 = 'rs--', save_figure = False, save_filename = "Battery_Pack_Conditions", file_type = ".png")
return
This plots the battery pack conditions of the network Assumptions: None Source: None Inputs: results.segments.conditions.propulsion battery_power_draw battery_energy battery_voltage_under_load battery_voltage_open_circuit current Outputs: Plots Properties Used: N/A
This plots the battery pack conditions of the network
[ "This", "plots", "the", "battery", "pack", "conditions", "of", "the", "network" ]
def plot_battery_pack_conditions(results, line_color = 'bo-', line_color2 = 'rs--', save_figure = False, save_filename = "Battery_Pack_Conditions", file_type = ".png"): """This plots the battery pack conditions of the network Assumptions: None Source: None Inputs: results.segments.conditions.propulsion battery_power_draw battery_energy battery_voltage_under_load battery_voltage_open_circuit current Outputs: Plots Properties Used: N/A """ axis_font = {'size':'14'} fig = plt.figure(save_filename) fig.set_size_inches(12, 10) fig.suptitle('Battery Pack Conditions') for i in range(len(results.segments)): time = results.segments[i].conditions.frames.inertial.time[:,0] / Units.min pack_power = results.segments[i].conditions.propulsion.battery_power_draw[:,0] pack_energy = results.segments[i].conditions.propulsion.battery_energy[:,0] pack_volts = results.segments[i].conditions.propulsion.battery_voltage_under_load[:,0] pack_volts_oc = results.segments[i].conditions.propulsion.battery_voltage_open_circuit[:,0] pack_current = results.segments[i].conditions.propulsion.battery_current[:,0] pack_SOC = results.segments[i].conditions.propulsion.battery_state_of_charge[:,0] pack_current = results.segments[i].conditions.propulsion.battery_current[:,0] pack_battery_amp_hr = (pack_energy/ Units.Wh )/pack_volts pack_C_instant = pack_current/pack_battery_amp_hr pack_C_nominal = pack_current/np.max(pack_battery_amp_hr) axes = plt.subplot(3,3,1) axes.plot(time, pack_SOC , line_color) axes.set_ylabel('SOC',axis_font) set_axes(axes) axes = plt.subplot(3,3,2) axes.plot(time, (pack_energy/Units.Wh)/1000, line_color) axes.set_ylabel('Energy (kW-hr)',axis_font) set_axes(axes) axes = plt.subplot(3,3,3) axes.plot(time, -pack_power/1000, line_color) axes.set_ylabel('Power (kW)',axis_font) set_axes(axes) axes = plt.subplot(3,3,4) axes.set_ylabel('Voltage (V)',axis_font) set_axes(axes) if i == 0: axes.plot(time, pack_volts, line_color,label='Under Load') axes.plot(time,pack_volts_oc, line_color2,label='Open Circuit') else: axes.plot(time, pack_volts, line_color) axes.plot(time,pack_volts_oc,line_color2) axes.legend(loc='upper right') axes = plt.subplot(3,3,5) axes.set_xlabel('Time (mins)',axis_font) axes.set_ylabel('C-Rate (C)',axis_font) set_axes(axes) if i == 0: axes.plot(time, pack_C_instant, line_color,label='Instantaneous') axes.plot(time, pack_C_nominal, line_color2,label='Nominal') else: axes.plot(time, pack_C_instant, line_color) axes.plot(time, pack_C_nominal, line_color2) axes.legend(loc='upper right') axes = plt.subplot(3,3,6) axes.plot(time, pack_current, line_color) axes.set_xlabel('Time (mins)',axis_font) axes.set_ylabel('Current (A)',axis_font) set_axes(axes) # Set limits for i in range(1,7): ax = plt.subplot(3,3,i) y_lo, y_hi = ax.get_ylim() if y_lo>0: y_lo = 0 y_hi = y_hi*1.1 ax.set_ylim(y_lo,y_hi) plt.tight_layout() if save_figure: fig.savefig(save_filename + file_type) return
[ "def", "plot_battery_pack_conditions", "(", "results", ",", "line_color", "=", "'bo-'", ",", "line_color2", "=", "'rs--'", ",", "save_figure", "=", "False", ",", "save_filename", "=", "\"Battery_Pack_Conditions\"", ",", "file_type", "=", "\".png\"", ")", ":", "axi...
https://github.com/suavecode/SUAVE/blob/4f83c467c5662b6cc611ce2ab6c0bdd25fd5c0a5/trunk/SUAVE/Plots/Performance/Mission_Plots.py#L383-L485
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/lib/python2.7/site-packages/jinja2/environment.py
python
TemplateExpression.__init__
(self, template, undefined_to_none)
[]
def __init__(self, template, undefined_to_none): self._template = template self._undefined_to_none = undefined_to_none
[ "def", "__init__", "(", "self", ",", "template", ",", "undefined_to_none", ")", ":", "self", ".", "_template", "=", "template", "self", ".", "_undefined_to_none", "=", "undefined_to_none" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/lib/python2.7/site-packages/jinja2/environment.py#L1177-L1179
tobegit3hub/deep_image_model
8a53edecd9e00678b278bb10f6fb4bdb1e4ee25e
java_predict_client/src/main/proto/tensorflow/python/ops/rnn.py
python
_reverse_seq
(input_seq, lengths)
return results
Reverse a list of Tensors up to specified lengths. Args: input_seq: Sequence of seq_len tensors of dimension (batch_size, n_features) or nested tuples of tensors. lengths: A `Tensor` of dimension batch_size, containing lengths for each sequence in the batch. If "None" is specified, simply reverses the list. Returns: time-reversed sequence
Reverse a list of Tensors up to specified lengths.
[ "Reverse", "a", "list", "of", "Tensors", "up", "to", "specified", "lengths", "." ]
def _reverse_seq(input_seq, lengths): """Reverse a list of Tensors up to specified lengths. Args: input_seq: Sequence of seq_len tensors of dimension (batch_size, n_features) or nested tuples of tensors. lengths: A `Tensor` of dimension batch_size, containing lengths for each sequence in the batch. If "None" is specified, simply reverses the list. Returns: time-reversed sequence """ if lengths is None: return list(reversed(input_seq)) flat_input_seq = tuple(nest.flatten(input_) for input_ in input_seq) flat_results = [[] for _ in range(len(input_seq))] for sequence in zip(*flat_input_seq): input_shape = tensor_shape.unknown_shape( ndims=sequence[0].get_shape().ndims) for input_ in sequence: input_shape.merge_with(input_.get_shape()) input_.set_shape(input_shape) # Join into (time, batch_size, depth) s_joined = array_ops.pack(sequence) # TODO(schuster, ebrevdo): Remove cast when reverse_sequence takes int32 if lengths is not None: lengths = math_ops.to_int64(lengths) # Reverse along dimension 0 s_reversed = array_ops.reverse_sequence(s_joined, lengths, 0, 1) # Split again into list result = array_ops.unpack(s_reversed) for r, flat_result in zip(result, flat_results): r.set_shape(input_shape) flat_result.append(r) results = [nest.pack_sequence_as(structure=input_, flat_sequence=flat_result) for input_, flat_result in zip(input_seq, flat_results)] return results
[ "def", "_reverse_seq", "(", "input_seq", ",", "lengths", ")", ":", "if", "lengths", "is", "None", ":", "return", "list", "(", "reversed", "(", "input_seq", ")", ")", "flat_input_seq", "=", "tuple", "(", "nest", ".", "flatten", "(", "input_", ")", "for", ...
https://github.com/tobegit3hub/deep_image_model/blob/8a53edecd9e00678b278bb10f6fb4bdb1e4ee25e/java_predict_client/src/main/proto/tensorflow/python/ops/rnn.py#L435-L478
IronLanguages/ironpython3
7a7bb2a872eeab0d1009fc8a6e24dca43f65b693
Src/StdLib/Lib/encodings/charmap.py
python
StreamWriter.__init__
(self,stream,errors='strict',mapping=None)
[]
def __init__(self,stream,errors='strict',mapping=None): codecs.StreamWriter.__init__(self,stream,errors) self.mapping = mapping
[ "def", "__init__", "(", "self", ",", "stream", ",", "errors", "=", "'strict'", ",", "mapping", "=", "None", ")", ":", "codecs", ".", "StreamWriter", ".", "__init__", "(", "self", ",", "stream", ",", "errors", ")", "self", ".", "mapping", "=", "mapping"...
https://github.com/IronLanguages/ironpython3/blob/7a7bb2a872eeab0d1009fc8a6e24dca43f65b693/Src/StdLib/Lib/encodings/charmap.py#L42-L44
GMvandeVen/continual-learning
a02db26d3b10754abdc4a549bdcde6af488c94e0
callbacks.py
python
_sample_cb
(log, config, visdom=None, test_datasets=None, sample_size=64, iters_per_task=None)
return sample_cb if (visdom is not None) else None
Initiates function for evaluating samples of generative model. [test_datasets] None or <list> of <Datasets> (if provided, also reconstructions are shown)
Initiates function for evaluating samples of generative model.
[ "Initiates", "function", "for", "evaluating", "samples", "of", "generative", "model", "." ]
def _sample_cb(log, config, visdom=None, test_datasets=None, sample_size=64, iters_per_task=None): '''Initiates function for evaluating samples of generative model. [test_datasets] None or <list> of <Datasets> (if provided, also reconstructions are shown)''' def sample_cb(generator, batch, task=1): '''Callback-function, to evaluate sample (and reconstruction) ability of the model.''' iteration = batch if task==1 else (task-1)*iters_per_task + batch if iteration % log == 0: # Evaluate reconstruction-ability of model on [test_dataset] if test_datasets is not None: # Reconstruct samples from current task evaluate.show_reconstruction(generator, test_datasets[task-1], config, size=int(sample_size/2), visdom=visdom, task=task) # Generate samples evaluate.show_samples(generator, config, visdom=visdom, size=sample_size, title="Generated images after {} iters in task {}".format(batch, task)) # Return the callback-function (except if neither visdom or pdf is selected!) return sample_cb if (visdom is not None) else None
[ "def", "_sample_cb", "(", "log", ",", "config", ",", "visdom", "=", "None", ",", "test_datasets", "=", "None", ",", "sample_size", "=", "64", ",", "iters_per_task", "=", "None", ")", ":", "def", "sample_cb", "(", "generator", ",", "batch", ",", "task", ...
https://github.com/GMvandeVen/continual-learning/blob/a02db26d3b10754abdc4a549bdcde6af488c94e0/callbacks.py#L9-L32
sagemath/sage
f9b2db94f675ff16963ccdefba4f1a3393b3fe0d
src/sage/combinat/root_system/type_relabel.py
python
CartanType.ascii_art
(self, label=lambda i: i, node=None)
return self._type.ascii_art(lambda i: label(self._relabelling[i]), node)
Return an ascii art representation of this Cartan type. EXAMPLES:: sage: print(CartanType(["G", 2]).relabel({1:2,2:1}).ascii_art()) 3 O=<=O 2 1 sage: print(CartanType(["B", 3, 1]).relabel([1,3,2,0]).ascii_art()) O 1 | | O---O=>=O 3 2 0 sage: print(CartanType(["F", 4, 1]).relabel(lambda n: 4-n).ascii_art()) O---O---O=>=O---O 4 3 2 1 0
Return an ascii art representation of this Cartan type.
[ "Return", "an", "ascii", "art", "representation", "of", "this", "Cartan", "type", "." ]
def ascii_art(self, label=lambda i: i, node=None): """ Return an ascii art representation of this Cartan type. EXAMPLES:: sage: print(CartanType(["G", 2]).relabel({1:2,2:1}).ascii_art()) 3 O=<=O 2 1 sage: print(CartanType(["B", 3, 1]).relabel([1,3,2,0]).ascii_art()) O 1 | | O---O=>=O 3 2 0 sage: print(CartanType(["F", 4, 1]).relabel(lambda n: 4-n).ascii_art()) O---O---O=>=O---O 4 3 2 1 0 """ if node is None: node = self._ascii_art_node return self._type.ascii_art(lambda i: label(self._relabelling[i]), node)
[ "def", "ascii_art", "(", "self", ",", "label", "=", "lambda", "i", ":", "i", ",", "node", "=", "None", ")", ":", "if", "node", "is", "None", ":", "node", "=", "self", ".", "_ascii_art_node", "return", "self", ".", "_type", ".", "ascii_art", "(", "l...
https://github.com/sagemath/sage/blob/f9b2db94f675ff16963ccdefba4f1a3393b3fe0d/src/sage/combinat/root_system/type_relabel.py#L289-L311
hyperledger/aries-cloudagent-python
2f36776e99f6053ae92eed8123b5b1b2e891c02a
aries_cloudagent/utils/classloader.py
python
ClassLoader.load_subclass_of
(cls, base_class: Type, mod_path: str, package: str = None)
return imported_class
Resolve an implementation of a base path within a module. Args: base_class: the base class being implemented mod_path: the absolute module path package: the parent package to search for the module Returns: The resolved class Raises: ClassNotFoundError: If the module or class implementation could not be found ModuleLoadError: If there was an error loading the module
Resolve an implementation of a base path within a module.
[ "Resolve", "an", "implementation", "of", "a", "base", "path", "within", "a", "module", "." ]
def load_subclass_of(cls, base_class: Type, mod_path: str, package: str = None): """ Resolve an implementation of a base path within a module. Args: base_class: the base class being implemented mod_path: the absolute module path package: the parent package to search for the module Returns: The resolved class Raises: ClassNotFoundError: If the module or class implementation could not be found ModuleLoadError: If there was an error loading the module """ mod = cls.load_module(mod_path, package) if not mod: raise ClassNotFoundError(f"Module '{mod_path}' not found") # Find an the first declared class that inherits from try: imported_class = next( obj for name, obj in inspect.getmembers(mod, inspect.isclass) if issubclass(obj, base_class) and obj is not base_class ) except StopIteration: raise ClassNotFoundError( f"Could not resolve a class that inherits from {base_class}" ) from None return imported_class
[ "def", "load_subclass_of", "(", "cls", ",", "base_class", ":", "Type", ",", "mod_path", ":", "str", ",", "package", ":", "str", "=", "None", ")", ":", "mod", "=", "cls", ".", "load_module", "(", "mod_path", ",", "package", ")", "if", "not", "mod", ":...
https://github.com/hyperledger/aries-cloudagent-python/blob/2f36776e99f6053ae92eed8123b5b1b2e891c02a/aries_cloudagent/utils/classloader.py#L123-L156
zhl2008/awd-platform
0416b31abea29743387b10b3914581fbe8e7da5e
web_flaskbb/lib/python2.7/site-packages/dateutil/tz/win.py
python
tzwin.__repr__
(self)
return "tzwin(%s)" % repr(self._name)
[]
def __repr__(self): return "tzwin(%s)" % repr(self._name)
[ "def", "__repr__", "(", "self", ")", ":", "return", "\"tzwin(%s)\"", "%", "repr", "(", "self", ".", "_name", ")" ]
https://github.com/zhl2008/awd-platform/blob/0416b31abea29743387b10b3914581fbe8e7da5e/web_flaskbb/lib/python2.7/site-packages/dateutil/tz/win.py#L229-L230
andabi/music-source-separation
ba9aa531ccca08437f1efe5dec1871faebf5c840
mir_eval/hierarchy.py
python
_hierarchy_bounds
(intervals_hier)
return min(boundaries), max(boundaries)
Compute the covered time range of a hierarchical segmentation. Parameters ---------- intervals_hier : list of ndarray A hierarchical segmentation, encoded as a list of arrays of segment intervals. Returns ------- t_min : float t_max : float The minimum and maximum times spanned by the annotation
Compute the covered time range of a hierarchical segmentation.
[ "Compute", "the", "covered", "time", "range", "of", "a", "hierarchical", "segmentation", "." ]
def _hierarchy_bounds(intervals_hier): '''Compute the covered time range of a hierarchical segmentation. Parameters ---------- intervals_hier : list of ndarray A hierarchical segmentation, encoded as a list of arrays of segment intervals. Returns ------- t_min : float t_max : float The minimum and maximum times spanned by the annotation ''' boundaries = list(itertools.chain(*list(itertools.chain(*intervals_hier)))) return min(boundaries), max(boundaries)
[ "def", "_hierarchy_bounds", "(", "intervals_hier", ")", ":", "boundaries", "=", "list", "(", "itertools", ".", "chain", "(", "*", "list", "(", "itertools", ".", "chain", "(", "*", "intervals_hier", ")", ")", ")", ")", "return", "min", "(", "boundaries", ...
https://github.com/andabi/music-source-separation/blob/ba9aa531ccca08437f1efe5dec1871faebf5c840/mir_eval/hierarchy.py#L81-L98
PySimpleGUI/PySimpleGUI
6c0d1fb54f493d45e90180b322fbbe70f7a5af3c
PySimpleGUIQt/PySimpleGUIQt.py
python
Output.write
(self, m)
MUST be called write. Don't mess with. It's called by Python itself because of reroute :param m: :return:
MUST be called write. Don't mess with. It's called by Python itself because of reroute :param m: :return:
[ "MUST", "be", "called", "write", ".", "Don", "t", "mess", "with", ".", "It", "s", "called", "by", "Python", "itself", "because", "of", "reroute", ":", "param", "m", ":", ":", "return", ":" ]
def write(self, m): """ MUST be called write. Don't mess with. It's called by Python itself because of reroute :param m: :return: """ self.QT_TextBrowser.moveCursor(QtGui.QTextCursor.End) self.QT_TextBrowser.insertPlainText( str(m))
[ "def", "write", "(", "self", ",", "m", ")", ":", "self", ".", "QT_TextBrowser", ".", "moveCursor", "(", "QtGui", ".", "QTextCursor", ".", "End", ")", "self", ".", "QT_TextBrowser", ".", "insertPlainText", "(", "str", "(", "m", ")", ")" ]
https://github.com/PySimpleGUI/PySimpleGUI/blob/6c0d1fb54f493d45e90180b322fbbe70f7a5af3c/PySimpleGUIQt/PySimpleGUIQt.py#L1694-L1701
linxid/Machine_Learning_Study_Path
558e82d13237114bbb8152483977806fc0c222af
Machine Learning In Action/Chapter5-LogisticRegression/venv/Lib/_dummy_thread.py
python
LockType.__init__
(self)
[]
def __init__(self): self.locked_status = False
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "locked_status", "=", "False" ]
https://github.com/linxid/Machine_Learning_Study_Path/blob/558e82d13237114bbb8152483977806fc0c222af/Machine Learning In Action/Chapter5-LogisticRegression/venv/Lib/_dummy_thread.py#L99-L100
IronLanguages/main
a949455434b1fda8c783289e897e78a9a0caabb5
External.LCA_RESTRICTED/Languages/IronPython/repackage/pip/pip/_vendor/requests/utils.py
python
default_user_agent
(name="python-requests")
return '%s/%s' % (name, __version__)
Return a string representing the default user agent.
Return a string representing the default user agent.
[ "Return", "a", "string", "representing", "the", "default", "user", "agent", "." ]
def default_user_agent(name="python-requests"): """Return a string representing the default user agent.""" return '%s/%s' % (name, __version__)
[ "def", "default_user_agent", "(", "name", "=", "\"python-requests\"", ")", ":", "return", "'%s/%s'", "%", "(", "name", ",", "__version__", ")" ]
https://github.com/IronLanguages/main/blob/a949455434b1fda8c783289e897e78a9a0caabb5/External.LCA_RESTRICTED/Languages/IronPython/repackage/pip/pip/_vendor/requests/utils.py#L580-L582
enthought/comtypes
8f3abc93c213fccdf9cae54aa88bfc1dfc17b8e9
comtypes/client/dynamic.py
python
_Dispatch.QueryInterface
(self, *args)
return self._comobj.QueryInterface(*args)
QueryInterface is forwarded to the real com object.
QueryInterface is forwarded to the real com object.
[ "QueryInterface", "is", "forwarded", "to", "the", "real", "com", "object", "." ]
def QueryInterface(self, *args): "QueryInterface is forwarded to the real com object." return self._comobj.QueryInterface(*args)
[ "def", "QueryInterface", "(", "self", ",", "*", "args", ")", ":", "return", "self", ".", "_comobj", ".", "QueryInterface", "(", "*", "args", ")" ]
https://github.com/enthought/comtypes/blob/8f3abc93c213fccdf9cae54aa88bfc1dfc17b8e9/comtypes/client/dynamic.py#L85-L87
home-assistant/core
265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1
homeassistant/components/panasonic_viera/media_player.py
python
PanasonicVieraTVEntity.device_class
(self)
return MediaPlayerDeviceClass.TV
Return the device class of the device.
Return the device class of the device.
[ "Return", "the", "device", "class", "of", "the", "device", "." ]
def device_class(self): """Return the device class of the device.""" return MediaPlayerDeviceClass.TV
[ "def", "device_class", "(", "self", ")", ":", "return", "MediaPlayerDeviceClass", ".", "TV" ]
https://github.com/home-assistant/core/blob/265ebd17a3f17ed8dc1e9bdede03ac8e323f1ab1/homeassistant/components/panasonic_viera/media_player.py#L106-L108
tebelorg/RPA-Python
9e8b2b417777a0780a0d19c9f880a9bb8ac2e976
tagui.py
python
_tagui_output
()
return tagui_output_text
function to wait for tagui output file to read and delete it
function to wait for tagui output file to read and delete it
[ "function", "to", "wait", "for", "tagui", "output", "file", "to", "read", "and", "delete", "it" ]
def _tagui_output(): """function to wait for tagui output file to read and delete it""" global _tagui_delay, _tagui_init_directory # to handle user changing current directory after init() is called init_directory_output_file = os.path.join(_tagui_init_directory, 'rpa_python.txt') # sleep to not splurge cpu cycles in while loop while not os.path.isfile('rpa_python.txt'): if os.path.isfile(init_directory_output_file): break time.sleep(_tagui_delay) # roundabout implementation to ensure backward compatibility if os.path.isfile('rpa_python.txt'): tagui_output_file = _py23_open('rpa_python.txt', 'r') tagui_output_text = _py23_read(tagui_output_file.read()) tagui_output_file.close() os.remove('rpa_python.txt') else: tagui_output_file = _py23_open(init_directory_output_file, 'r') tagui_output_text = _py23_read(tagui_output_file.read()) tagui_output_file.close() os.remove(init_directory_output_file) return tagui_output_text
[ "def", "_tagui_output", "(", ")", ":", "global", "_tagui_delay", ",", "_tagui_init_directory", "# to handle user changing current directory after init() is called", "init_directory_output_file", "=", "os", ".", "path", ".", "join", "(", "_tagui_init_directory", ",", "'rpa_pyt...
https://github.com/tebelorg/RPA-Python/blob/9e8b2b417777a0780a0d19c9f880a9bb8ac2e976/tagui.py#L134-L158
upyun/python-sdk
dabff535df78d5beba4c989a6b8a046977079cdc
examples/upload.py
python
rest_upload
()
rest文件上传
rest文件上传
[ "rest文件上传" ]
def rest_upload(): """ rest文件上传 """ with open(local_file, "rb") as f: # headers 可选,见rest上传参数 headers = None up.put(remote_file, f, headers=headers)
[ "def", "rest_upload", "(", ")", ":", "with", "open", "(", "local_file", ",", "\"rb\"", ")", "as", "f", ":", "# headers 可选,见rest上传参数", "headers", "=", "None", "up", ".", "put", "(", "remote_file", ",", "f", ",", "headers", "=", "headers", ")" ]
https://github.com/upyun/python-sdk/blob/dabff535df78d5beba4c989a6b8a046977079cdc/examples/upload.py#L19-L26
evennia/evennia
fa79110ba6b219932f22297838e8ac72ebc0be0e
evennia/comms/comms.py
python
DefaultChannel.at_channel_creation
(self)
Called once, when the channel is first created.
Called once, when the channel is first created.
[ "Called", "once", "when", "the", "channel", "is", "first", "created", "." ]
def at_channel_creation(self): """ Called once, when the channel is first created. """ pass
[ "def", "at_channel_creation", "(", "self", ")", ":", "pass" ]
https://github.com/evennia/evennia/blob/fa79110ba6b219932f22297838e8ac72ebc0be0e/evennia/comms/comms.py#L67-L72
edisonlz/fastor
342078a18363ac41d3c6b1ab29dbdd44fdb0b7b3
base/site-packages/debug_toolbar/views.py
python
sql_profile
(request)
Returns the output of running the SQL and getting the profiling statistics. Expected GET variables: sql: urlencoded sql with positional arguments params: JSON encoded parameter values duration: time for SQL to execute passed in from toolbar just for redisplay hash: the hash of (secret + sql + params) for tamper checking
Returns the output of running the SQL and getting the profiling statistics.
[ "Returns", "the", "output", "of", "running", "the", "SQL", "and", "getting", "the", "profiling", "statistics", "." ]
def sql_profile(request): """ Returns the output of running the SQL and getting the profiling statistics. Expected GET variables: sql: urlencoded sql with positional arguments params: JSON encoded parameter values duration: time for SQL to execute passed in from toolbar just for redisplay hash: the hash of (secret + sql + params) for tamper checking """ from debug_toolbar.panels.sql import reformat_sql sql = request.GET.get('sql', '') params = request.GET.get('params', '') alias = request.GET.get('alias', 'default') hash = sha_constructor(settings.SECRET_KEY + sql + params).hexdigest() if hash != request.GET.get('hash', ''): return HttpResponseBadRequest('Tamper alert') # SQL Tampering alert if sql.lower().strip().startswith('select'): params = simplejson.loads(params) cursor = connections[alias].cursor() result = None headers = None result_error = None try: cursor.execute("SET PROFILING=1") # Enable profiling cursor.execute(sql, params) # Execute SELECT cursor.execute("SET PROFILING=0") # Disable profiling # The Query ID should always be 1 here but I'll subselect to get the last one just in case... cursor.execute("SELECT * FROM information_schema.profiling WHERE query_id=(SELECT query_id FROM information_schema.profiling ORDER BY query_id DESC LIMIT 1)") headers = [d[0] for d in cursor.description] result = cursor.fetchall() except: result_error = "Profiling is either not available or not supported by your database." cursor.close() context = { 'result': result, 'result_error': result_error, 'sql': reformat_sql(cursor.db.ops.last_executed_query(cursor, sql, params)), 'duration': request.GET.get('duration', 0.0), 'headers': headers, 'alias': alias, } return render_to_response('debug_toolbar/panels/sql_profile.html', context) raise InvalidSQLError("Only 'select' queries are allowed.")
[ "def", "sql_profile", "(", "request", ")", ":", "from", "debug_toolbar", ".", "panels", ".", "sql", "import", "reformat_sql", "sql", "=", "request", ".", "GET", ".", "get", "(", "'sql'", ",", "''", ")", "params", "=", "request", ".", "GET", ".", "get",...
https://github.com/edisonlz/fastor/blob/342078a18363ac41d3c6b1ab29dbdd44fdb0b7b3/base/site-packages/debug_toolbar/views.py#L115-L158
mrlesmithjr/Ansible
d44f0dc0d942bdf3bf7334b307e6048f0ee16e36
roles/ansible-vsphere-management/scripts/pdns/lib/python2.7/site-packages/pip/download.py
python
get_file_content
(url, comes_from=None, session=None)
return url, content
Gets the content of a file; it may be a filename, file: URL, or http: URL. Returns (location, content). Content is unicode.
Gets the content of a file; it may be a filename, file: URL, or http: URL. Returns (location, content). Content is unicode.
[ "Gets", "the", "content", "of", "a", "file", ";", "it", "may", "be", "a", "filename", "file", ":", "URL", "or", "http", ":", "URL", ".", "Returns", "(", "location", "content", ")", ".", "Content", "is", "unicode", "." ]
def get_file_content(url, comes_from=None, session=None): """Gets the content of a file; it may be a filename, file: URL, or http: URL. Returns (location, content). Content is unicode.""" if session is None: raise TypeError( "get_file_content() missing 1 required keyword argument: 'session'" ) match = _scheme_re.search(url) if match: scheme = match.group(1).lower() if (scheme == 'file' and comes_from and comes_from.startswith('http')): raise InstallationError( 'Requirements file %s references URL %s, which is local' % (comes_from, url)) if scheme == 'file': path = url.split(':', 1)[1] path = path.replace('\\', '/') match = _url_slash_drive_re.match(path) if match: path = match.group(1) + ':' + path.split('|', 1)[1] path = urllib_parse.unquote(path) if path.startswith('/'): path = '/' + path.lstrip('/') url = path else: # FIXME: catch some errors resp = session.get(url) resp.raise_for_status() return resp.url, resp.text try: with open(url, 'rb') as f: content = auto_decode(f.read()) except IOError as exc: raise InstallationError( 'Could not open requirements file: %s' % str(exc) ) return url, content
[ "def", "get_file_content", "(", "url", ",", "comes_from", "=", "None", ",", "session", "=", "None", ")", ":", "if", "session", "is", "None", ":", "raise", "TypeError", "(", "\"get_file_content() missing 1 required keyword argument: 'session'\"", ")", "match", "=", ...
https://github.com/mrlesmithjr/Ansible/blob/d44f0dc0d942bdf3bf7334b307e6048f0ee16e36/roles/ansible-vsphere-management/scripts/pdns/lib/python2.7/site-packages/pip/download.py#L389-L427
cgat-developers/ruffus
fc8fa8dcf7b5f4b877e5bb712146e87abd26d046
ruffus/task.py
python
Pipeline.set_tail_tasks
(self, tail_tasks)
Specifies tasks at the tail of the pipeline, i.e. with only descendants/dependants
Specifies tasks at the tail of the pipeline, i.e. with only descendants/dependants
[ "Specifies", "tasks", "at", "the", "tail", "of", "the", "pipeline", "i", ".", "e", ".", "with", "only", "descendants", "/", "dependants" ]
def set_tail_tasks(self, tail_tasks): """ Specifies tasks at the tail of the pipeline, i.e. with only descendants/dependants """ self.tail_tasks = tail_tasks
[ "def", "set_tail_tasks", "(", "self", ",", "tail_tasks", ")", ":", "self", ".", "tail_tasks", "=", "tail_tasks" ]
https://github.com/cgat-developers/ruffus/blob/fc8fa8dcf7b5f4b877e5bb712146e87abd26d046/ruffus/task.py#L992-L997
fabtools/fabtools
5fdc7174c3fae5e93a16d677d0466f41dc2be175
fabtools/python.py
python
is_installed
(package, python_cmd='python', pip_cmd='pip')
return (package.lower() in packages)
Check if a Python package is installed (using pip). Package names are case insensitive. Example:: from fabtools.python import virtualenv import fabtools with virtualenv('/path/to/venv'): fabtools.python.install('Flask') assert fabtools.python.is_installed('flask') .. _pip: http://www.pip-installer.org/
Check if a Python package is installed (using pip).
[ "Check", "if", "a", "Python", "package", "is", "installed", "(", "using", "pip", ")", "." ]
def is_installed(package, python_cmd='python', pip_cmd='pip'): """ Check if a Python package is installed (using pip). Package names are case insensitive. Example:: from fabtools.python import virtualenv import fabtools with virtualenv('/path/to/venv'): fabtools.python.install('Flask') assert fabtools.python.is_installed('flask') .. _pip: http://www.pip-installer.org/ """ with settings( hide('running', 'stdout', 'stderr', 'warnings'), warn_only=True): res = run('%(python_cmd)s -m %(pip_cmd)s freeze' % locals()) packages = [line.split('==')[0].lower() for line in res.splitlines()] return (package.lower() in packages)
[ "def", "is_installed", "(", "package", ",", "python_cmd", "=", "'python'", ",", "pip_cmd", "=", "'pip'", ")", ":", "with", "settings", "(", "hide", "(", "'running'", ",", "'stdout'", ",", "'stderr'", ",", "'warnings'", ")", ",", "warn_only", "=", "True", ...
https://github.com/fabtools/fabtools/blob/5fdc7174c3fae5e93a16d677d0466f41dc2be175/fabtools/python.py#L89-L110
awslabs/aws-data-wrangler
548f5197bacd91bd50ebc66a0173eff9c56f69b1
awswrangler/_config.py
python
_Config.concurrent_partitioning
(self)
return cast(bool, self["concurrent_partitioning"])
Property concurrent_partitioning.
Property concurrent_partitioning.
[ "Property", "concurrent_partitioning", "." ]
def concurrent_partitioning(self) -> bool: """Property concurrent_partitioning.""" return cast(bool, self["concurrent_partitioning"])
[ "def", "concurrent_partitioning", "(", "self", ")", "->", "bool", ":", "return", "cast", "(", "bool", ",", "self", "[", "\"concurrent_partitioning\"", "]", ")" ]
https://github.com/awslabs/aws-data-wrangler/blob/548f5197bacd91bd50ebc66a0173eff9c56f69b1/awswrangler/_config.py#L198-L200
andresriancho/w3af
cd22e5252243a87aaa6d0ddea47cf58dacfe00a9
w3af/plugins/attack/db/sqlmap/lib/core/option.py
python
_adjustLoggingFormatter
()
Solves problem of line deletition caused by overlapping logging messages and retrieved data info in inference mode
Solves problem of line deletition caused by overlapping logging messages and retrieved data info in inference mode
[ "Solves", "problem", "of", "line", "deletition", "caused", "by", "overlapping", "logging", "messages", "and", "retrieved", "data", "info", "in", "inference", "mode" ]
def _adjustLoggingFormatter(): """ Solves problem of line deletition caused by overlapping logging messages and retrieved data info in inference mode """ if hasattr(FORMATTER, '_format'): return def format(record): message = FORMATTER._format(record) message = boldifyMessage(message) if kb.get("prependFlag"): message = "\n%s" % message kb.prependFlag = False return message FORMATTER._format = FORMATTER.format FORMATTER.format = format
[ "def", "_adjustLoggingFormatter", "(", ")", ":", "if", "hasattr", "(", "FORMATTER", ",", "'_format'", ")", ":", "return", "def", "format", "(", "record", ")", ":", "message", "=", "FORMATTER", ".", "_format", "(", "record", ")", "message", "=", "boldifyMes...
https://github.com/andresriancho/w3af/blob/cd22e5252243a87aaa6d0ddea47cf58dacfe00a9/w3af/plugins/attack/db/sqlmap/lib/core/option.py#L455-L473
llSourcell/AI_Artist
3038c06c2e389b9c919c881c9a169efe2fd7810e
lib/python2.7/site-packages/pip/_vendor/pkg_resources/__init__.py
python
_SetuptoolsVersionMixin.__getitem__
(self, key)
return tuple(self)[key]
[]
def __getitem__(self, key): return tuple(self)[key]
[ "def", "__getitem__", "(", "self", ",", "key", ")", ":", "return", "tuple", "(", "self", ")", "[", "key", "]" ]
https://github.com/llSourcell/AI_Artist/blob/3038c06c2e389b9c919c881c9a169efe2fd7810e/lib/python2.7/site-packages/pip/_vendor/pkg_resources/__init__.py#L136-L137
tensorflow/tensor2tensor
2a33b152d7835af66a6d20afe7961751047e28dd
tensor2tensor/utils/metrics.py
python
padded_sequence_accuracy
(predictions, labels, weights_fn=common_layers.weights_nonzero)
Percentage of times that predictions matches labels everywhere (non-0).
Percentage of times that predictions matches labels everywhere (non-0).
[ "Percentage", "of", "times", "that", "predictions", "matches", "labels", "everywhere", "(", "non", "-", "0", ")", "." ]
def padded_sequence_accuracy(predictions, labels, weights_fn=common_layers.weights_nonzero): """Percentage of times that predictions matches labels everywhere (non-0).""" # If the last dimension is 1 then we're using L1/L2 loss. if common_layers.shape_list(predictions)[-1] == 1: return rounding_sequence_accuracy( predictions, labels, weights_fn=weights_fn) with tf.variable_scope( "padded_sequence_accuracy", values=[predictions, labels]): padded_predictions, padded_labels = common_layers.pad_with_zeros( predictions, labels) weights = weights_fn(padded_labels) # Flatten, keeping batch dim (and num_classes dim for predictions) # TPU argmax can only deal with a limited number of dimensions predictions_shape = common_layers.shape_list(padded_predictions) batch_size = predictions_shape[0] num_classes = predictions_shape[-1] flat_size = common_layers.list_product( common_layers.shape_list(padded_labels)[1:]) padded_predictions = tf.reshape( padded_predictions, [batch_size, common_layers.list_product(predictions_shape[1:-1]), num_classes]) padded_labels = tf.reshape(padded_labels, [batch_size, flat_size]) weights = tf.reshape(weights, [batch_size, flat_size]) outputs = tf.to_int32(tf.argmax(padded_predictions, axis=-1)) padded_labels = tf.to_int32(padded_labels) not_correct = tf.to_float(tf.not_equal(outputs, padded_labels)) * weights axis = list(range(1, len(outputs.get_shape()))) correct_seq = 1.0 - tf.minimum(1.0, tf.reduce_sum(not_correct, axis=axis)) return correct_seq, tf.constant(1.0)
[ "def", "padded_sequence_accuracy", "(", "predictions", ",", "labels", ",", "weights_fn", "=", "common_layers", ".", "weights_nonzero", ")", ":", "# If the last dimension is 1 then we're using L1/L2 loss.", "if", "common_layers", ".", "shape_list", "(", "predictions", ")", ...
https://github.com/tensorflow/tensor2tensor/blob/2a33b152d7835af66a6d20afe7961751047e28dd/tensor2tensor/utils/metrics.py#L212-L245