sequence stringlengths 546 16.2k | code stringlengths 108 19.3k |
|---|---|
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 30; 2, function_name:send_array; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 3, 20; 3, 23; 4, identifier:socket; 5, default_parameter; 5, 6; 5, 7; 6, identifier:A; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:metadata; 10, None; 11, default_... | def send_array(
socket, A=None, metadata=None, flags=0,
copy=False, track=False, compress=None,
chunksize=50 * 1000 * 1000
):
"""send a numpy array with metadata over zmq
message is mostly multipart:
metadata | array part 1 | array part 2, etc
only metadata:
metadata
t... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:recv_array; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:socket; 5, default_parameter; 5, 6; 5, 7; 6, identifier:flags; 7, integer:0; 8, default_parameter; 8, 9; 8, 10; 9, identifier:copy; 10, False; 11, default_paramete... | def recv_array(
socket,
flags=0,
copy=False,
track=False,
poll=None,
poll_timeout=10000
):
"""recv a metadata and an optional numpy array from a zmq socket
Optionally provide poll object to use recv_array with timeout
poll_timeout is in millis
"""
if... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:reduce_fit; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:interface; 5, identifier:state; 6, identifier:label; 7, identifier:inp; 8, block; 8, 9; 8, 11; 8, 17; 8, 18; 8, 23; 8, 32; 8, 33; 8, 34; 8, 35; 8, 50; 8, 54; 8, 55; 8, 63; 8, 67; ... | def reduce_fit(interface, state, label, inp):
"""
Function separates aggregation of continuous and discrete features.
For continuous features it aggregates partially calculated means and variances and returns them. For discrete
features it aggregates pairs and returns them. Pairs with label occurrences ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:map_predict; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:interface; 5, identifier:state; 6, identifier:label; 7, identifier:inp; 8, block; 8, 9; 8, 11; 8, 16; 8, 25; 8, 48; 8, 49; 8, 72; 8, 73; 8, 85; 8, 86; 8, 98; 8, 99; 9, expression... | def map_predict(interface, state, label, inp):
"""
Function makes a predictions of samples with given model. It calculates probabilities with multinomial and Gaussian distribution.
"""
import numpy as np
out = interface.output(0)
continuous = [j for i, j in enumerate(state["X_indices"]) if
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:json_dumps; 3, parameters; 3, 4; 4, identifier:obj; 5, block; 5, 6; 5, 8; 5, 30; 5, 31; 5, 32; 5, 33; 5, 34; 5, 52; 5, 61; 5, 172; 6, expression_statement; 6, 7; 7, comment; 8, try_statement; 8, 9; 8, 26; 9, block; 9, 10; 10, return_statement; ... | def json_dumps(obj):
"""A safe JSON dump function that provides correct diverging numbers for a
ECMAscript consumer.
"""
try:
return json.dumps(obj, indent=2, sort_keys=True, allow_nan=False)
except ValueError:
pass
# we don't want to call do_map on the original object since i... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:add_json_mask; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:start; 6, identifier:method_str; 7, identifier:json_producer; 8, block; 8, 9; 8, 11; 8, 277; 9, expression_statement; 9, 10; 10, comment; 11, function_defin... | def add_json_mask(self, start, method_str, json_producer):
"""Adds a handler that produces a JSON response.
Parameters
----------
start : string
The URL prefix that must be matched to perform this request.
method_str : string
The HTTP method for which to... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:add_text_mask; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:start; 6, identifier:method_str; 7, identifier:text_producer; 8, block; 8, 9; 8, 11; 8, 270; 9, expression_statement; 9, 10; 10, comment; 11, function_defin... | def add_text_mask(self, start, method_str, text_producer):
"""Adds a handler that produces a plain text response.
Parameters
----------
start : string
The URL prefix that must be matched to perform this request.
method_str : string
The HTTP method for wh... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:get_token_obj; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:token; 6, default_parameter; 6, 7; 6, 8; 7, identifier:expire; 8, identifier:_token_default; 9, block; 9, 10; 9, 12; 9, 25; 9, 31; 9, 42; 10, expression_statement... | def get_token_obj(self, token, expire=_token_default):
"""Returns or creates the object associaten with the given token.
Parameters
----------
token : string
The token for the object as returned by `create_token`.
expire : number or None
The number of se... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:handle_cmd; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:cmd; 6, block; 6, 7; 6, 9; 6, 17; 6, 21; 6, 47; 6, 51; 6, 59; 6, 60; 6, 138; 6, 139; 6, 150; 6, 172; 6, 179; 6, 231; 7, expression_statement; 7, 8; 8, comment; 9, expressi... | def handle_cmd(self, cmd):
"""Handles a single server command."""
cmd = cmd.strip()
segments = []
for s in cmd.split():
# remove bash-like comments
if s.startswith('#'):
break
# TODO implement escape sequences (also for \#)
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:handle_request; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 18; 5, 46; 5, 52; 5, 56; 5, 62; 5, 81; 5, 175; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifi... | def handle_request(self):
"""Handles an HTTP request.The actual HTTP request is handled using a
different thread.
"""
timeout = self.socket.gettimeout()
if timeout is None:
timeout = self.timeout
elif self.timeout is not None:
timeout = min(time... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:info_gain_nominal; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:x; 5, identifier:y; 6, identifier:separate_max; 7, block; 7, 8; 7, 10; 7, 19; 7, 20; 7, 31; 7, 38; 7, 39; 7, 50; 7, 51; 7, 52; 7, 65; 7, 103; 7, 112; 7, 122; 7, 322; 7, 323; 8, e... | def info_gain_nominal(x, y, separate_max):
"""
Function calculates information gain for discrete features. If feature is continuous it is firstly discretized.
x: numpy array - numerical or discrete feature
y: numpy array - labels
ft: string - feature type ("c" - continuous, "d" - discrete)
spli... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_endpoints_using_catalog_api; 3, parameters; 3, 4; 3, 5; 4, identifier:domain; 5, identifier:token; 6, block; 6, 7; 6, 9; 6, 10; 6, 17; 6, 18; 6, 19; 6, 20; 6, 21; 6, 22; 6, 23; 6, 24; 6, 25; 6, 26; 6, 27; 6, 31; 6, 35; 6, 41; 6, 45; 6, 173;... | def get_endpoints_using_catalog_api(domain, token):
"""
Implements a raw HTTP GET against the entire Socrata portal for the domain in question. This method uses the
second of the two ways of getting this information, the catalog API.
Parameters
----------
domain: str
A Socrata data port... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:stratify_by_scores; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:scores; 5, default_parameter; 5, 6; 5, 7; 6, identifier:goal_n_strata; 7, string:'auto'; 8, default_parameter; 8, 9; 8, 10; 9, identifier:method; 10, string:'cum_sqrt_F'... | def stratify_by_scores(scores, goal_n_strata='auto', method='cum_sqrt_F',
n_bins = 'auto'):
"""Stratify by binning the items based on their scores
Parameters
----------
scores : array-like, shape=(n_items,)
ordered array of scores which quantify the classifier confidence ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_get_target; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:target; 6, block; 6, 7; 6, 9; 6, 20; 6, 30; 6, 52; 6, 104; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, ... | def _get_target(self, target):
"""
Get the Package or Module related to given target.
Args:
target (str): target to find.
Returns:
Package/Module: package containing target or corresponding module.
"""
depth = target.count('.') + 1
parts ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:by_user; 3, parameters; 3, 4; 4, identifier:config; 5, block; 5, 6; 5, 8; 5, 14; 5, 20; 5, 27; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:client; 11, call; 11, 12; 11, 1... | def by_user(config):
"""Display LDAP group membership sorted by user."""
client = Client()
client.prepare_connection()
audit_api = API(client)
CLI.parse_membership('Groups by User', audit_api.by_user()) |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:get_sortkey; 3, parameters; 3, 4; 4, identifier:table; 5, block; 5, 6; 5, 8; 5, 9; 5, 10; 5, 11; 5, 25; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, comment; 10, comment; 11, expression_statement; 11, 12; 12, assignment; 12, 13; 12... | def get_sortkey(table):
"""Get a field to sort by
"""
# Just pick the first column in the table in alphabetical order.
# Ideally we would get the primary key from bcdc api, but it doesn't
# seem to be available
wfs = WebFeatureService(url=bcdata.OWS_URL, version="2.0.0")
return sorted(wfs.ge... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 20; 2, function_name:define_request; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 3, 17; 4, identifier:dataset; 5, default_parameter; 5, 6; 5, 7; 6, identifier:query; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:crs; 10, string:"epsg:4326"; 11, defa... | def define_request(
dataset, query=None, crs="epsg:4326", bounds=None, sortby=None, pagesize=10000
):
"""Define the getfeature request parameters required to download a dataset
References:
- http://www.opengeospatial.org/standards/wfs
- http://docs.geoserver.org/stable/en/user/services/wfs/vendor.h... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_get_sorted; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:resources; 6, block; 6, 7; 6, 9; 6, 13; 6, 51; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier:t... | def _get_sorted(self, resources):
"""Order the resources by priority - the most specific paths come
first.
:param resources: List of :class:`wsgiservice.resource.Resource`
classes to be served by this application.
"""
tmp = []
for resource in re... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:find_new_posts_and_pages; 3, parameters; 3, 4; 4, identifier:db; 5, block; 5, 6; 5, 8; 5, 14; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:Q; 11, call; 11, 12; 11, 13; 12,... | def find_new_posts_and_pages(db):
"""Walk content dir, put each post and page in the database"""
Q = Query()
for root, dirs, files in os.walk(CONFIG['content_root']):
for filename in sorted([f for f in files if
f.endswith(('md', 'markdown'))]):
fullpath = ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:get_locations; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:filter_to_my_group; 7, False; 8, block; 8, 9; 8, 11; 8, 21; 8, 25; 8, 62; 8, 66; 8, 201; 9, expression_statement; 9, 10; 10, comment; ... | def get_locations(self, filter_to_my_group=False):
"""Retrieve Locations listed in ChemInventory"""
resp = self._post('general-retrievelocations', 'locations')
groups = {}
if resp['groupinfo']:
for group in resp['groupinfo']:
groups[group['id']] = Group(
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:_image_url; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:image; 5, default_parameter; 5, 6; 5, 7; 6, identifier:dst_color; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:src_color; 10, None; 11, block; 11, 12; 11, 14; 11, 28; 11, ... | def _image_url(image, dst_color=None, src_color=None):
"""
Generates a path to an asset found relative to the project's images
directory.
"""
if src_color and dst_color:
if not Image:
raise Exception("Images manipulation require PIL")
file = StringValue(image).value
path ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:normalize_selectors; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:_selectors; 6, default_parameter; 6, 7; 6, 8; 7, identifier:extra_selectors; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:extra_parent... | def normalize_selectors(self, _selectors, extra_selectors=None, extra_parents=None):
"""
Normalizes or extends selectors in a string.
An optional extra parameter that can be a list of extra selectors to be
added to the final normalized selectors string.
"""
# Fixe tabs an... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:_get_properties; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 12; 3, 13; 4, identifier:self; 5, identifier:rule; 6, identifier:p_selectors; 7, identifier:p_parents; 8, identifier:p_children; 9, identifier:scope; 10, iden... | def _get_properties(self, rule, p_selectors, p_parents, p_children, scope, media, c_lineno, c_property, c_codestr):
"""
Implements properties and variables extraction
"""
prop, value = (_prop_split_re.split(c_property, 1) + [None])[:2]
try:
is_var = (c_property[len(pr... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:link_with_parents; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:parent; 6, identifier:c_selectors; 7, identifier:c_rules; 8, block; 8, 9; 8, 11; 8, 15; 8, 324; 9, expression_statement; 9, 10; 10, comment; 11, express... | def link_with_parents(self, parent, c_selectors, c_rules):
"""
Link with a parent for the current child rule.
If parents found, returns a list of parent rules to the child
"""
parent_found = None
for p_selectors, p_rules in self.parts.items():
_p_selectors, _,... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_extends; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 10; 5, 11; 5, 93; 5, 97; 5, 101; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, comment; 10, comment; 11, for_statement; 11, 12; 11, 15; 11, 22; 1... | def parse_extends(self):
"""
For each part, create the inheritance parts from the ' extends '
"""
# To be able to manage multiple extends, you need to
# destroy the actual node and create many nodes that have
# mono extend. The first one gets all the css rules
for... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:scan; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:restrict; 6, block; 6, 7; 6, 9; 6, 10; 6, 202; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, while_statement; 10, 11; 10, 12; 10, 13; 10, 14; 11, True; 12, comment;... | def scan(self, restrict):
"""
Should scan another token and add it to the list, self.tokens,
and add the restriction to self.restrictions
"""
# Keep looking for a token, ignoring any in self.ignore
while True:
# Search the patterns for a match, with earlier
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:read_form_data; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 20; 5, 26; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 12; 9, attribute; 9, 10; 9, 11; 10, identifier:self; 11, identifier:processed_data... | def read_form_data(self):
"""Attempt to read the form data from the request"""
if self.processed_data:
raise exceptions.AlreadyProcessed('The data has already been processed for this form')
if self.readonly:
return
if request.method == self.method:
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:_imm_trans_setattr; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:name; 6, identifier:value; 7, block; 7, 8; 7, 10; 7, 17; 7, 27; 8, expression_statement; 8, 9; 9, string:'''
An immutable's transient setattr allows para... | def _imm_trans_setattr(self, name, value):
'''
An immutable's transient setattr allows params to be set, and runs checks as they are.
'''
params = _imm_param_data(self)
dd = object.__getattribute__(self, '__dict__')
if name in params:
(_, tx_fn, arg_lists, check_fns, deps) = params[name]... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:verify_consistency; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:predictions; 5, identifier:scores; 6, identifier:proba; 7, identifier:opt_class; 8, block; 8, 9; 8, 11; 8, 27; 8, 42; 8, 43; 8, 58; 8, 59; 8, 74; 8, 75; 8, 90; 8, 105; 8, ... | def verify_consistency(predictions, scores, proba, opt_class):
"""Verifies that all arrays have consistent dimensions. Also verifies
that the scores are consistent with proba.
Returns
-------
proba, opt_class
"""
if predictions.shape != scores.shape:
raise ValueError("predictions an... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_call; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:context; 6, block; 6, 7; 6, 9; 6, 15; 6, 30; 6, 36; 6, 47; 6, 56; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11,... | def _call(self, context):
"""
Executes a single request against a handler. If the req.method == 'barrister-idl', the
Contract IDL JSON structure is returned. Otherwise the method is resolved to a handler
based on the interface name, and the appropriate function is called on the handler... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:validate; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:expected_type; 6, identifier:is_array; 7, identifier:val; 8, block; 8, 9; 8, 11; 8, 192; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12; 1... | def validate(self, expected_type, is_array, val):
"""
Validates that the expected type matches the value
Returns two element tuple: (bool, string)
- `bool` - True if valid, False if not
- `string` - Description of validation error, or None if valid
:Parameters:
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:validate; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:val; 6, block; 6, 7; 6, 9; 6, 27; 6, 92; 6, 101; 6, 134; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 16; 10, comparison_operator:is; 10, 11; 10, 15... | def validate(self, val):
"""
Validates that the val matches the expected fields for this struct.
val must be a dict, and must contain only fields represented by this struct and its
ancestors.
Returns two element tuple: (bool, string)
- `bool` - True if valid, False if n... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_struct; 3, parameters; 3, 4; 4, identifier:s; 5, block; 5, 6; 5, 8; 5, 14; 5, 22; 5, 35; 5, 39; 5, 43; 5, 47; 5, 94; 5, 98; 5, 102; 5, 106; 5, 110; 5, 209; 5, 213; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; ... | def parse_struct(s):
"""
Returns a docco section for the given struct.
:Parameters:
s
Parsed IDL struct dict. Keys: 'comment', 'name', 'extends', 'fields'
"""
docs = s['comment']
code = '<span class="k">struct</span> <span class="gs">%s</span>' % s['name']
if s['extends']:
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:parse_interface; 3, parameters; 3, 4; 4, identifier:iface; 5, block; 5, 6; 5, 8; 5, 12; 5, 18; 5, 26; 5, 131; 5, 135; 5, 146; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:... | def parse_interface(iface):
"""
Returns a docco section for the given interface.
:Parameters:
iface
Parsed IDL interface dict. Keys: 'comment', 'name', 'returns', 'params'
"""
sections = [ ]
docs = iface['comment']
code = '<span class="k">interface</span> <span class="gs">%s</... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:run; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 14; 5, 20; 5, 26; 5, 32; 5, 39; 5, 62; 5, 82; 5, 88; 5, 89; 5, 97; 5, 104; 5, 220; 5, 227; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assig... | def run(self):
"""run the model"""
model = self.model
configfile = self.configfile
interval = self.interval
sockets = self.sockets
model.initialize(configfile)
if model.state == 'pause':
logger.info(
"model initialized and started in ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:save; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:self; 5, list_splat_pattern; 5, 6; 6, identifier:args; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 12; 9, 187; 10, expression_statement; 10, 11; 11, comment; ... | def save(self, *args, **kwargs):
"""
Before saving, if slide is for a publication, use publication info
for slide's title, subtitle, description.
"""
if self.publication:
publication = self.publication
if not self.title:
self.title = publi... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:cmd; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:send; 5, identifier:msg; 6, identifier:args; 7, block; 7, 8; 7, 10; 7, 22; 7, 28; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignment; 11, 12; 11, 13; 1... | def cmd(send, msg, args):
"""Slap somebody.
Syntax: {command} <nick> [for <reason>]
"""
implements = ['the golden gate bridge', 'a large trout', 'a clue-by-four', 'a fresh haddock', 'moon', 'an Itanium', 'fwilson', 'a wombat']
methods = ['around a bit', 'upside the head']
if not msg:
c... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:cmd; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:send; 5, identifier:msg; 6, identifier:args; 7, block; 7, 8; 7, 10; 7, 20; 7, 26; 7, 55; 7, 56; 7, 82; 7, 83; 7, 100; 7, 117; 7, 123; 7, 129; 7, 148; 7, 159; 8, expression_statement; 8, 9; 9, ... | def cmd(send, msg, args):
"""Corrects a previous message.
Syntax: {command}/<msg>/<replacement>/<ig|nick>
"""
if not msg:
send("Invalid Syntax.")
return
char = msg[0]
msg = [x.replace(r'\/', '/') for x in re.split(r'(?<!\\)\%s' % char, msg[1:], maxsplit=2)]
# fix for people... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_add_single_session_to_to_ordered_dict; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:d; 6, identifier:dataset_index; 7, identifier:recommended_only; 8, block; 8, 9; 8, 11; 9, expression_statement; 9, 10; 10, comment;... | def _add_single_session_to_to_ordered_dict(self, d, dataset_index, recommended_only):
"""
Save a single session to an ordered dictionary.
"""
for model_index, model in enumerate(self.models):
# determine if model should be presented, or if a null-model should
# be... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_group_models; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 14; 5, 15; 5, 16; 5, 103; 5, 104; 5, 132; 5, 151; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identi... | def _group_models(self):
"""
If AIC and BMD are numeric and identical, then treat models as
identical. Returns a list of lists. The outer list is a list of related
models, the inner list contains each individual model, sorted by the
number of parameters in ascending order.
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:random_stats; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:all_stats; 6, identifier:race; 7, identifier:ch_class; 8, block; 8, 9; 8, 11; 8, 12; 8, 16; 8, 20; 8, 41; 8, 45; 8, 142; 9, expression_statement; 9, 10; 10, ... | def random_stats(self, all_stats, race, ch_class):
"""
create random stats based on the characters class and race
This looks up the tables from CharacterCollection to get
base stats and applies a close random fit
"""
# create blank list of stats to be generated
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:palette; 3, parameters; 3, 4; 3, 5; 4, identifier:fg; 5, default_parameter; 5, 6; 5, 7; 6, identifier:bg; 7, unary_operator:-; 7, 8; 8, integer:1; 9, block; 9, 10; 9, 12; 9, 26; 9, 40; 9, 54; 9, 78; 9, 79; 9, 97; 9, 137; 9, 177; 9, 190; 10, exp... | def palette(fg, bg=-1):
"""
Since curses only supports a finite amount of initialised colour pairs
we memoise any selections you've made as an attribute on this function
"""
if not hasattr(palette, "counter"):
palette.counter = 1
if not hasattr(palette, "selections"):
palette.s... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:coordinate; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:panes; 7, list:[]; 8, default_parameter; 8, 9; 8, 10; 9, identifier:index; 10, integer:0; 11, block; 11, 12; 11, 14; 11, 18; 11, 1... | def coordinate(self, panes=[], index=0):
"""
Update pane coordinate tuples based on their height and width relative to other panes
within the dimensions of the current window.
We account for panes with a height of 1 where the bottom coordinates are the same as the top.
Account f... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 15; 2, function_name:_MakePackagePages; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 3, 12; 4, identifier:self; 5, identifier:package; 6, default_parameter; 6, 7; 6, 8; 7, identifier:showprivate; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:nested; 11, F... | def _MakePackagePages(self, package, showprivate=False, nested=False, showinh=False):
"""An internal helper to generate all of the pages for a given package
Args:
package (module): The top-level package to document
showprivate (bool): A flag for whether or not to display private... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:_DocPackageFromTop; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:packages; 6, default_parameter; 6, 7; 6, 8; 7, identifier:showprivate; 8, False; 9, default_parameter; 9, 10; 9, 11; 10, identifier:showinh; 11, False... | def _DocPackageFromTop(self, packages, showprivate=False, showinh=False):
"""Generates all of the documentation for given packages and
appends new tocrees to the index. All documentation pages will be under the
set relative path.
Args:
packages (list(module)): A package or l... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:cmd; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:send; 5, identifier:msg; 6, identifier:args; 7, block; 7, 8; 7, 10; 7, 29; 7, 42; 7, 83; 7, 95; 7, 99; 7, 103; 7, 165; 7, 180; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, ... | def cmd(send, msg, args):
"""Leaves a note for a user or users.
Syntax: {command} <nick>[,nick2,...] <note>
"""
if not args['config']['feature'].getboolean('hooks'):
send("Hooks are disabled, and this command depends on hooks. Please contact the bot admin(s).")
return
if args['type... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:add_category; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:category; 6, block; 6, 7; 6, 9; 7, expression_statement; 7, 8; 8, string:'''
Add unicode category to set
Unicode categories are strings like 'Ll', 'Lu',... | def add_category(self, category):
'''
Add unicode category to set
Unicode categories are strings like 'Ll', 'Lu', 'Nd', etc.
See `unicodedata.category()`
'''
if category == sre.CATEGORY_DIGIT:
self._categories |= UNICODE_DIGIT_CATEGORIES
elif category... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_estimate_free; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 9; 5, 19; 5, 35; 5, 43; 5, 50; 5, 63; 5, 70; 5, 71; 5, 84; 5, 101; 5, 102; 5, 103; 5, 111; 5, 123; 5, 129; 6, expression_statement; 6, 7; 7, comment; 8, comment; ... | def _estimate_free(self):
"""
Estimate completion time for a free task.
:returns: deferred that when fired returns a datetime object for the
estimated, or the actual datetime, or None if we could not
estimate a time for this task method.
"""
#... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:package; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 23; 5, 39; 5, 54; 5, 55; 5, 70; 5, 71; 5, 79; 5, 86; 5, 87; 5, 172; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 14; 9, comparison_operator:==; 9... | def package(self):
"""
Find a package name from a build task's parameters.
:returns: name of the package this build task is building.
:raises: ValueError if we could not parse this tasks's request params.
"""
if self.method == 'buildNotification':
return self... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:is_admin; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:send; 6, identifier:nick; 7, default_parameter; 7, 8; 7, 9; 8, identifier:required_role; 9, string:'admin'; 10, block; 10, 11; 10, 13; 10, 14; 10, 20; 10, 21; 1... | def is_admin(self, send, nick, required_role='admin'):
"""Checks if a nick is a admin.
If NickServ hasn't responded yet, then the admin is unverified,
so assume they aren't a admin.
"""
# If the required role is None, bypass checks.
if not required_role:
ret... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:do_mode; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:self; 5, identifier:target; 6, identifier:msg; 7, identifier:nick; 8, identifier:send; 9, block; 9, 10; 9, 12; 9, 23; 9, 86; 9, 87; 9, 88; 9, 143; 10, expression_statement; 10,... | def do_mode(self, target, msg, nick, send):
"""reop and handle guard violations."""
mode_changes = irc.modes.parse_channel_modes(msg)
with self.data_lock:
for change in mode_changes:
if change[1] == 'v':
self.voiced[target][change[2]] = True if cha... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:do_kick; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 4, identifier:self; 5, identifier:send; 6, identifier:target; 7, identifier:nick; 8, identifier:msg; 9, default_parameter; 9, 10; 9, 11; 10, identifier:slogan; 11, True; 12, block; 12... | def do_kick(self, send, target, nick, msg, slogan=True):
"""Kick users.
- If kick is disabled, don't do anything.
- If the bot is not a op, rage at a op.
- Kick the user.
"""
if not self.kick_enabled:
return
if target not in self.channels:
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:handle_msg; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:c; 6, identifier:e; 7, block; 7, 8; 7, 10; 7, 38; 7, 66; 7, 67; 7, 80; 7, 109; 7, 140; 7, 141; 7, 152; 7, 164; 7, 182; 7, 200; 7, 231; 7, 249; 7, 280; 7, 298; 7, 309... | def handle_msg(self, c, e):
"""The Heart and Soul of IrcBot."""
if e.type not in ['authenticate', 'error', 'join', 'part', 'quit']:
nick = e.source.nick
else:
nick = e.source
if e.arguments is None:
msg = ""
else:
msg = " ".join(e... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:cmd; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:send; 5, identifier:msg; 6, identifier:args; 7, block; 7, 8; 7, 10; 7, 16; 7, 35; 7, 69; 7, 79; 7, 89; 8, expression_statement; 8, 9; 9, comment; 10, expression_statement; 10, 11; 11, assignme... | def cmd(send, msg, args):
"""Microwaves something.
Syntax: {command} <level> <target>
"""
nick = args['nick']
channel = args['target'] if args['target'] != 'private' else args['config']['core']['channel']
levels = {
1: 'Whirr...',
2: 'Vrrm...',
3: 'Zzzzhhhh...',
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:cmdloop; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:intro; 7, None; 8, block; 8, 9; 8, 11; 8, 17; 8, 18; 8, 66; 9, expression_statement; 9, 10; 10, string:''' Override the command loop to hand... | def cmdloop(self, intro=None):
''' Override the command loop to handle Ctrl-C. '''
self.preloop()
# Set up completion with readline.
if self.use_rawinput and self.completekey:
try:
import readline
self.old_completer = readline.get_completer()
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:free; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:local_path; 6, block; 6, 7; 6, 9; 6, 10; 6, 11; 6, 19; 6, 20; 6, 30; 6, 38; 6, 48; 6, 49; 6, 56; 6, 65; 6, 66; 6, 77; 6, 88; 6, 98; 6, 136; 6, 137; 6, 146; 6, 147; 6, 299; 7, ex... | def free(self, local_path):
'''
Stop synchronization of local_path
'''
# Process local ~~~
# 1. Syncthing config
config = self.get_config()
# Check whether folders are still connected to this device
folder = st_util.find_folder_with_path(local_path, config)
self.delete_... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:get_package_update_list; 3, parameters; 3, 4; 3, 5; 4, identifier:package_name; 5, identifier:version; 6, block; 6, 7; 6, 9; 6, 20; 6, 21; 6, 28; 6, 36; 6, 37; 6, 41; 6, 45; 6, 46; 6, 50; 6, 54; 6, 55; 6, 59; 6, 63; 6, 67; 6, 71; 6, 75; 6, 293;... | def get_package_update_list(package_name, version):
"""
Return update information of a package from a given version
:param package_name: string
:param version: string
:return: dict
"""
package_version = semantic_version.Version.coerce(version)
# Get package and version data from pypi
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:page_location_template; 3, parameters; 3, 4; 4, identifier:self; 5, block; 5, 6; 5, 8; 5, 18; 5, 28; 5, 40; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 11; 10, identifier:cycle; 11, attribu... | def page_location_template(self):
"""
Returns the published URL template for a page type.
"""
cycle = self.election_day.cycle.name
model_class = self.model_type.model_class()
if model_class == ElectionDay:
return "/{}/".format(cycle)
if model_class == ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_ask; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:answers; 6, block; 6, 7; 6, 9; 6, 40; 7, expression_statement; 7, 8; 8, comment; 9, if_statement; 9, 10; 9, 17; 9, 30; 10, call; 10, 11; 10, 12; 11, identifier:isinstance; 12, a... | def _ask(self, answers):
""" Really ask the question.
We may need to populate multiple validators with answers here.
Then ask the question and insert the default value if
appropriate. Finally call the validate function to check all
validators for this question a... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:_annotate_fn_args; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 11; 4, identifier:stack; 5, identifier:fn_opname; 6, identifier:nargs; 7, default_parameter; 7, 8; 7, 9; 8, identifier:nkw; 9, unary_operator:-; 9, 10; 10, integer:1; 11, default_par... | def _annotate_fn_args(stack, fn_opname, nargs, nkw=-1, consume_fn_name=True):
"""Add commas and equals as appropriate to function argument lists in the stack."""
kwarg_names = []
if nkw == -1:
if sys.version_info[0] < 3:
# Compute nkw and nargs from nargs for python 2.7
nargs, nkw = (nargs % 256, ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:generate_mediation_matrix; 3, parameters; 3, 4; 4, identifier:dsm; 5, block; 5, 6; 5, 8; 5, 14; 5, 20; 5, 28; 5, 39; 5, 54; 5, 55; 5, 73; 5, 394; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9,... | def generate_mediation_matrix(dsm):
"""
Generate the mediation matrix of the given matrix.
Rules for mediation matrix generation:
Set -1 for items NOT to be considered
Set 0 for items which MUST NOT be present
Set 1 for items which MUST be present
Each module h... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:check; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:dsm; 6, default_parameter; 6, 7; 6, 8; 7, identifier:independence_factor; 8, integer:5; 9, dictionary_splat_pattern; 9, 10; 10, identifier:kwargs; 11, block; 11, 1... | def check(self, dsm, independence_factor=5, **kwargs):
"""
Check least common mechanism.
Args:
dsm (:class:`DesignStructureMatrix`): the DSM to check.
independence_factor (int): if the maximum dependencies for one
module is inferior or equal to the DSM si... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:abstract; 3, parameters; 3, 4; 4, identifier:class_; 5, block; 5, 6; 5, 8; 5, 22; 5, 26; 5, 27; 5, 28; 5, 35; 5, 71; 5, 77; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 16; 9, not_operator; 9, 10; 10, call; 10, 11; 10, 1... | def abstract(class_):
"""Mark the class as _abstract_ base class, forbidding its instantiation.
.. note::
Unlike other modifiers, ``@abstract`` can be applied
to all Python classes, not just subclasses of :class:`Object`.
.. versionadded:: 0.0.3
"""
if not inspect.isclass(class_):... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:final; 3, parameters; 3, 4; 4, identifier:arg; 5, block; 5, 6; 5, 8; 5, 43; 5, 56; 5, 62; 6, expression_statement; 6, 7; 7, comment; 8, if_statement; 8, 9; 8, 15; 8, 31; 9, call; 9, 10; 9, 13; 10, attribute; 10, 11; 10, 12; 11, identifier:inspe... | def final(arg):
"""Mark a class or method as _final_.
Final classes are those that end the inheritance chain, i.e. forbid
further subclassing. A final class can thus be only instantiated,
not inherited from.
Similarly, methods marked as final in a superclass cannot be overridden
in any of the ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:override; 3, parameters; 3, 4; 4, default_parameter; 4, 5; 4, 6; 5, identifier:base; 6, identifier:ABSENT; 7, block; 7, 8; 7, 10; 7, 14; 7, 15; 7, 16; 7, 49; 7, 50; 7, 60; 7, 61; 7, 77; 8, expression_statement; 8, 9; 9, comment; 10, expression_... | def override(base=ABSENT):
"""Mark a method as overriding a corresponding method from superclass.
:param base:
Optional base class from which this method is being overridden.
If provided, it can be a class itself, or its (qualified) name.
.. note::
When overriding a :class:`class... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_index; 3, parameters; 3, 4; 3, 6; 4, list_splat_pattern; 4, 5; 5, identifier:args; 6, dictionary_splat_pattern; 6, 7; 7, identifier:kwargs; 8, block; 8, 9; 8, 11; 8, 21; 8, 31; 8, 145; 8, 152; 8, 166; 8, 170; 9, expression_statement; 9, 10; 10... | def _index(*args, **kwargs):
"""Implementation of list searching.
:param of: Element to search for
:param where: Predicate to search for
:param in_: List to search in
:param start: Start index for the lookup
:param step: Counter step (i.e. in/decrement) for each iteration
:return: Pair of ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:tally_poll; 3, parameters; 3, 4; 4, identifier:args; 5, block; 5, 6; 5, 8; 5, 16; 5, 28; 5, 37; 5, 47; 5, 54; 5, 65; 5, 89; 5, 106; 5, 115; 5, 132; 5, 172; 5, 178; 5, 187; 5, 213; 5, 220; 5, 228; 6, expression_statement; 6, 7; 7, comment; 8, if... | def tally_poll(args):
"""Shows the results of poll."""
if not args.msg:
return "Syntax: !vote tally <pollnum>"
if not args.msg.isdigit():
return "Not A Valid Positive Integer."
pid = int(args.msg)
poll = get_open_poll(args.session, pid)
if poll is None:
return "That poll ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_setup_pages; 3, parameters; 3, 4; 3, 5; 4, identifier:cls; 5, identifier:config; 6, block; 6, 7; 6, 9; 6, 15; 6, 21; 6, 27; 6, 33; 6, 40; 6, 44; 6, 48; 6, 82; 6, 92; 6, 104; 7, expression_statement; 7, 8; 8, comment; 9, import_from_statement; ... | def _setup_pages(cls, config):
"""
Create the page structure.
It created a home page (if not exists) and a sub-page, and attach the Apphook to the
sub-page.
Pages titles are provided by ``AutoCMSAppMixin.auto_setup``
:param setup_config: boolean to control whether creat... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:pretty_description; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:description; 5, default_parameter; 5, 6; 5, 7; 6, identifier:wrap_at; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:indent; 10, integer:0; 11, block; 11, 12; 11, 14... | def pretty_description(description, wrap_at=None, indent=0):
"""
Return a pretty formatted string given some text.
Args:
description (str): string to format.
wrap_at (int): maximum length of a line.
indent (int): level of indentation.
Returns:
str: pretty formatted stri... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 19; 2, function_name:search; 3, parameters; 3, 4; 3, 5; 3, 10; 3, 13; 3, 16; 4, identifier:term; 5, default_parameter; 5, 6; 5, 7; 6, identifier:category; 7, attribute; 7, 8; 7, 9; 8, identifier:Categories; 9, identifier:ALL; 10, default_parameter; 10, 11; 10, 12;... | def search(term, category=Categories.ALL, pages=1, sort=None, order=None):
"""Return a search result for term in category. Can also be
sorted and span multiple pages."""
s = Search()
s.search(term=term, category=category, pages=pages, sort=sort, order=order)
return s |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 10; 2, function_name:popular; 3, parameters; 3, 4; 3, 7; 4, default_parameter; 4, 5; 4, 6; 5, identifier:category; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:sortOption; 9, string:"title"; 10, block; 10, 11; 10, 13; 10, 19; 10, 27; 11, expression_sta... | def popular(category=None, sortOption = "title"):
"""Return a search result containing torrents appearing
on the KAT home page. Can be categorized. Cannot be
sorted or contain multiple pages"""
s = Search()
s.popular(category, sortOption)
return s |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 16; 2, function_name:recent; 3, parameters; 3, 4; 3, 7; 3, 10; 3, 13; 4, default_parameter; 4, 5; 4, 6; 5, identifier:category; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:pages; 9, integer:1; 10, default_parameter; 10, 11; 10, 12; 11, identifier:sort... | def recent(category=None, pages=1, sort=None, order=None):
"""Return most recently added torrents. Can be sorted and categorized
and contain multiple pages."""
s = Search()
s.recent(category, pages, sort, order)
return s |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 4; 2, function_name:pick_action_todo; 3, parameters; 4, block; 4, 5; 4, 7; 4, 70; 5, expression_statement; 5, 6; 6, comment; 7, for_statement; 7, 8; 7, 11; 7, 15; 7, 16; 8, pattern_list; 8, 9; 8, 10; 9, identifier:ndx; 10, identifier:todo; 11, call; 11, 12; 11, 13... | def pick_action_todo():
"""
only for testing and AI - user will usually choose an action
Sort of works
"""
for ndx, todo in enumerate(things_to_do):
#print('todo = ', todo)
if roll_dice(todo["chance"]):
cur_act = actions[get_action_by_name(todo["name"])]
if to... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:select; 3, parameters; 3, 4; 3, 5; 4, identifier:soup; 5, identifier:selector; 6, block; 6, 7; 6, 9; 6, 17; 6, 22; 6, 289; 7, expression_statement; 7, 8; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12; 11, identifier... | def select(soup, selector):
"""
soup should be a BeautifulSoup instance; selector is a CSS selector
specifying the elements you want to retrieve.
"""
tokens = selector.split()
current_context = [soup]
for token in tokens:
m = attribselect_re.match(token)
if m:
# ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 14; 2, function_name:try_; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 4, identifier:block; 5, default_parameter; 5, 6; 5, 7; 6, identifier:except_; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:else_; 10, None; 11, default_parameter; 11, 12; 11, 13; 12, i... | def try_(block, except_=None, else_=None, finally_=None):
"""Emulate a ``try`` block.
:param block: Function to be executed within the ``try`` statement
:param except_: Function to execute when an :class:`Exception` occurs.
It receives a single argument: the exception object.
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:replace_u_end_day; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:day; 5, identifier:year; 6, identifier:month; 7, block; 7, 8; 7, 10; 7, 19; 7, 26; 7, 38; 7, 61; 7, 78; 7, 114; 7, 115; 7, 134; 7, 135; 7, 160; 8, expression_statement; 8, 9; 9, ... | def replace_u_end_day(day, year, month):
"""Find the latest legitimate day."""
day = day.lstrip('-')
year = int(year)
month = int(month.lstrip('-'))
if day == 'uu' or day == '3u':
# Use the last day of the month for a given year/month.
return str(calendar.monthrange(year, month)[1])
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:zero_year_special_case; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:from_date; 5, identifier:to_date; 6, identifier:start; 7, identifier:end; 8, block; 8, 9; 8, 11; 9, expression_statement; 9, 10; 10, comment; 11, if_statement; 11, 12;... | def zero_year_special_case(from_date, to_date, start, end):
"""strptime does not resolve a 0000 year, we must handle this."""
if start == 'pos' and end == 'pos':
# always interval from earlier to later
if from_date.startswith('0000') and not to_date.startswith('0000'):
return True
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:is_valid_interval; 3, parameters; 3, 4; 4, identifier:edtf_candidate; 5, block; 5, 6; 5, 8; 5, 9; 5, 13; 5, 17; 5, 18; 5, 26; 6, expression_statement; 6, 7; 7, comment; 8, comment; 9, expression_statement; 9, 10; 10, assignment; 10, 11; 10, 12;... | def is_valid_interval(edtf_candidate):
"""Test to see if the edtf candidate is a valid interval"""
# resolve interval into from / to datetime objects
from_date = None
to_date = None
# initialize interval flags for special cases, assume positive
end, start = 'pos', 'pos'
if edtf_candidate.co... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:template; 3, parameters; 3, 4; 3, 7; 3, 10; 4, default_parameter; 4, 5; 4, 6; 5, identifier:page; 6, None; 7, default_parameter; 7, 8; 7, 9; 8, identifier:layout; 9, None; 10, dictionary_splat_pattern; 10, 11; 11, identifier:kwargs; 12, block;... | def template(page=None, layout=None, **kwargs):
"""
Decorator to change the view template and layout.
It works on both View class and view methods
on class
only $layout is applied, everything else will be passed to the kwargs
Using as first argument, it will be the layout.
:fi... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:getargspec; 3, parameters; 3, 4; 4, identifier:obj; 5, block; 5, 6; 5, 8; 5, 20; 5, 124; 5, 125; 5, 126; 5, 127; 5, 140; 5, 207; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, assignment; 9, 10; 9, 15; 10, pattern_... | def getargspec(obj):
"""An improved inspect.getargspec.
Has a slightly different return value from the default getargspec.
Returns a tuple of:
required, optional, args, kwargs
list, dict, bool, bool
Required is a list of required named arguments.
Optional is a dictionary mapping o... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:_find_overlap; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 4, identifier:queries; 5, identifier:client; 6, identifier:find_method; 7, identifier:get_method; 8, identifier:overlap_function; 9, block; 9, 10; 9, 12; 9, 16; 9, 71; 10, expression_s... | async def _find_overlap(queries, client, find_method, get_method,
overlap_function):
"""Generic find and overlap implementation.
Arguments
names (:py:class:`collections.abc.Sequence`): The queries of the
people to find overlaps for.
client (:py:class:`~.TMDbClient`):... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:power; 3, parameters; 3, 4; 4, identifier:set_; 5, block; 5, 6; 5, 8; 5, 13; 5, 37; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9; 9, call; 9, 10; 9, 11; 10, identifier:ensure_countable; 11, argument_list; 11, 12; 12,... | def power(set_):
"""Returns all subsets of given set.
:return: Powerset of given set, i.e. iterable containing all its subsets,
sorted by ascending cardinality.
"""
ensure_countable(set_)
result = chain.from_iterable(combinations(set_, r)
for r in xran... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 12; 2, function_name:generate_pws_in_order; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 9; 4, identifier:self; 5, identifier:n; 6, default_parameter; 6, 7; 6, 8; 7, identifier:filter_func; 8, None; 9, default_parameter; 9, 10; 9, 11; 10, identifier:N_max; 11, float:1e6; 1... | def generate_pws_in_order(self, n, filter_func=None, N_max=1e6):
"""
Generates passwords in order between upto N_max
@N_max is the maximum size of the priority queue will be tolerated,
so if the size of the queue is bigger than 1.5 * N_max, it will shrink
the size to 0.75 * N_max... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:expand_seed; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:start_seed; 6, identifier:num_iterations; 7, identifier:val; 8, block; 8, 9; 8, 11; 8, 26; 8, 36; 9, expression_statement; 9, 10; 10, comment; 11, expression_... | def expand_seed(self, start_seed, num_iterations, val):
"""
takes a seed start point and grows out in random
directions setting cell points to val
"""
self.grd.set_tile(start_seed[0], start_seed[1], val)
cur_pos = [start_seed[0], start_seed[1]]
while num_iteration... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:denoise_grid; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:val; 6, default_parameter; 6, 7; 6, 8; 7, identifier:expand; 8, integer:1; 9, block; 9, 10; 9, 12; 9, 48; 9, 244; 10, expression_statement; 10, 11; 11, comment; 12... | def denoise_grid(self, val, expand=1):
"""
for every cell in the grid of 'val' fill all cells
around it to de noise the grid
"""
updated_grid = [[self.grd.get_tile(y,x) \
for x in range(self.grd.grid_width)] \
for y in rang... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:run; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 4, identifier:self; 5, identifier:num_runs; 6, identifier:show_trails; 7, identifier:log_file_base; 8, block; 8, 9; 8, 11; 8, 16; 8, 35; 8, 60; 8, 80; 8, 86; 8, 87; 8, 134; 8, 272; 8, 273; 9, expressi... | def run(self, num_runs, show_trails, log_file_base):
"""
Run each agent in the world for 'num_runs' iterations
Optionally saves grid results to file if base name is
passed to method.
"""
print("--------------------------------------------------")
print("Starting S... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 9; 2, function_name:merge; 3, parameters; 3, 4; 3, 5; 3, 7; 4, identifier:arg; 5, list_splat_pattern; 5, 6; 6, identifier:rest; 7, dictionary_splat_pattern; 7, 8; 8, identifier:kwargs; 9, block; 9, 10; 9, 12; 9, 21; 9, 27; 9, 39; 9, 40; 9, 41; 9, 42; 9, 46; 9, 76;... | def merge(arg, *rest, **kwargs):
"""Merge a collection, with functions as items, into a single function
that takes a collection and maps its items through corresponding functions.
:param arg: A collection of functions, such as list, tuple, or dictionary
:param default: Optional default function to use ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:cmd; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:send; 5, identifier:msg; 6, identifier:args; 7, block; 7, 8; 7, 10; 7, 29; 7, 35; 7, 46; 7, 54; 7, 64; 7, 74; 7, 89; 7, 117; 8, expression_statement; 8, 9; 9, comment; 10, if_statement; 10, 11... | def cmd(send, msg, args):
"""Gets scores.
Syntax: {command} <--high|--low|nick>
"""
if not args['config']['feature'].getboolean('hooks'):
send("Hooks are disabled, and this command depends on hooks. Please contact the bot admin(s).")
return
session = args['db']
parser = argumen... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:buildPrices; 3, parameters; 3, 4; 3, 5; 3, 8; 3, 11; 3, 14; 4, identifier:data; 5, default_parameter; 5, 6; 5, 7; 6, identifier:roles; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:regex; 10, identifier:default_price_regex; 11, def... | def buildPrices(data, roles=None, regex=default_price_regex,
default=None, additional={}):
''' Create a dictionary with price information. Multiple ways are
supported.
:rtype: :obj:`dict`: keys are role as str, values are the prices as
cent count'''
if isinstance(da... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:toTag; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, identifier:output; 6, block; 6, 7; 6, 9; 6, 10; 6, 19; 6, 42; 6, 65; 6, 88; 6, 111; 6, 134; 6, 156; 6, 179; 6, 180; 6, 209; 6, 210; 6, 313; 7, expression_statement; 7, 8; 8, string:''' Th... | def toTag(self, output):
''' This methods adds all data of this canteen as canteen xml tag
to the given xml Document.
:meth:`toXMLFeed` uses this method to create the XML Feed. So there is
normally no need to call it directly.
:param output: XML Document to which the data shoul... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 33; 2, function_name:AddAnalogShortIdMsecRecord; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 12; 3, 15; 3, 18; 3, 21; 3, 24; 3, 27; 3, 30; 4, identifier:site_service; 5, identifier:tag; 6, identifier:time_value; 7, identifier:msec; 8, identifier:value; 9... | def AddAnalogShortIdMsecRecord(site_service, tag, time_value, msec, value,
low_warn=False, high_warn=False, low_alarm=False, high_alarm=False,
oor_low=False, oor_high=False, unreliable=False, manual=False):
"""
This function will add an analog value to the specified eDNA service and
tag, with many o... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:update_node_ids; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sub_job_num; 7, None; 8, block; 8, 9; 8, 11; 8, 12; 8, 30; 8, 34; 8, 38; 8, 72; 8, 73; 8, 88; 8, 89; 8, 94; 8, 111; 8, 128; 8, 140; ... | def update_node_ids(self, sub_job_num=None):
"""
Associate Jobs with respective cluster ids.
"""
# Build condor_q and condor_history commands
dag_id = '%s.%s' % (self.cluster_id, sub_job_num) if sub_job_num else str(self.cluster_id)
job_delimiter = '+++'
attr_deli... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 17; 2, function_name:concat_cols; 3, parameters; 3, 4; 3, 5; 3, 6; 3, 7; 3, 8; 3, 9; 3, 10; 3, 11; 3, 14; 4, identifier:df1; 5, identifier:df2; 6, identifier:idx_col; 7, identifier:df1_cols; 8, identifier:df2_cols; 9, identifier:df1_suffix; 10, identifier:df2_suff... | def concat_cols(df1,df2,idx_col,df1_cols,df2_cols,
df1_suffix,df2_suffix,wc_cols=[],suffix_all=False):
"""
Concatenates two pandas tables
:param df1: dataframe 1
:param df2: dataframe 2
:param idx_col: column name which will be used as a common index
"""
df1=df1.set_index... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 11; 2, function_name:to_json; 3, parameters; 3, 4; 3, 5; 3, 8; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:indent; 7, None; 8, default_parameter; 8, 9; 8, 10; 9, identifier:sort_keys; 10, True; 11, block; 11, 12; 11, 14; 12, expression_stat... | def to_json(self, indent=None, sort_keys=True):
"""Return a JSON string representation of this instance
:param indent: specify an indent level or a string used to indent each
level
:param sort_keys: the output is sorted by key
"""
return json.dumps(self.to... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 6; 2, function_name:_validate_method_decoration; 3, parameters; 3, 4; 3, 5; 4, identifier:meta; 5, identifier:class_; 6, block; 6, 7; 6, 9; 6, 10; 6, 11; 6, 21; 6, 44; 6, 45; 6, 46; 7, expression_statement; 7, 8; 8, comment; 9, comment; 10, comment; 11, expression... | def _validate_method_decoration(meta, class_):
"""Validate the usage of ``@override`` and ``@final`` modifiers
on methods of the given ``class_``.
"""
# TODO(xion): employ some code inspection tricks to serve ClassErrors
# as if they were thrown at the offending class's/method's ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:_parse_status; 3, parameters; 3, 4; 4, identifier:bug_el; 5, block; 5, 6; 5, 8; 5, 14; 5, 15; 5, 43; 5, 60; 5, 77; 5, 100; 5, 112; 5, 124; 5, 136; 5, 148; 5, 171; 5, 194; 5, 217; 5, 242; 5, 267; 5, 288; 5, 305; 5, 306; 5, 307; 5, 308; 5, 309; 5... | def _parse_status(bug_el):
"""Return a bugreport object from a given status xml element"""
bug = Bugreport()
# plain fields
for field in ('originator', 'subject', 'msgid', 'package', 'severity',
'owner', 'summary', 'location', 'source', 'pending',
'forwarded'):
... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 7; 2, function_name:set; 3, parameters; 3, 4; 3, 5; 3, 6; 4, identifier:self; 5, identifier:attr; 6, identifier:value; 7, block; 7, 8; 7, 10; 7, 64; 7, 75; 7, 102; 7, 125; 7, 143; 7, 168; 7, 239; 8, expression_statement; 8, 9; 9, comment; 10, function_definition; ... | def set(self, attr, value):
"""Set the value of an attribute in the submit description file.
The value can be passed in as a Python type (i.e. a list, a tuple or a Python boolean).
The Python values will be reformatted into strings based on the standards described in
the HTCondor manual... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 8; 2, function_name:_update_status; 3, parameters; 3, 4; 3, 5; 4, identifier:self; 5, default_parameter; 5, 6; 5, 7; 6, identifier:sub_job_num; 7, None; 8, block; 8, 9; 8, 11; 8, 29; 8, 36; 8, 51; 8, 56; 8, 73; 8, 90; 8, 107; 8, 117; 8, 126; 8, 179; 8, 180; 8, 186... | def _update_status(self, sub_job_num=None):
"""Gets the job status.
Return:
str: The current status of the job
"""
job_id = '%s.%s' % (self.cluster_id, sub_job_num) if sub_job_num else str(self.cluster_id)
format = ['-format', '"%d"', 'JobStatus']
cmd = 'con... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 5; 2, function_name:mangle; 3, parameters; 3, 4; 4, identifier:text; 5, block; 5, 6; 5, 8; 5, 17; 5, 18; 5, 25; 5, 26; 5, 32; 5, 38; 5, 43; 5, 47; 5, 51; 5, 55; 5, 56; 5, 65; 5, 319; 5, 320; 6, expression_statement; 6, 7; 7, comment; 8, expression_statement; 8, 9;... | def mangle(text):
"""
Takes a script and mangles it
TokenError is thrown when encountering bad syntax
"""
text_bytes = text.encode('utf-8')
# Wrap the input script as a byte stream
buff = BytesIO(text_bytes)
# Byte stream for the mangled script
mangled = BytesIO()
last_tok = ... |
0, module; 0, 1; 1, function_definition; 1, 2; 1, 3; 1, 18; 1, 34; 2, function_name:get_array_from_hist2D; 3, parameters; 3, 4; 3, 8; 3, 13; 4, typed_parameter; 4, 5; 4, 6; 5, identifier:hist; 6, type; 6, 7; 7, identifier:Hist; 8, typed_default_parameter; 8, 9; 8, 10; 8, 12; 9, identifier:set_zero_to_NaN; 10, type; 10,... | def get_array_from_hist2D(hist: Hist, set_zero_to_NaN: bool = True, return_bin_edges: bool = False) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
""" Extract x, y, and bin values from a 2D ROOT histogram.
Converts the histogram into a numpy array, and suitably processes it for a surface plot
by removing 0s... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.