code
stringlengths
51
2.34k
sequence
stringlengths
1.16k
13.1k
docstring
stringlengths
11
171
def assert_valid(self, instance, value=None): valid = super(Tuple, self).assert_valid(instance, value) if not valid: return False if value is None: value = instance._get(self.name) if value is None: return True if ( (sel...
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'assert_valid'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'val...
Check if tuple and contained properties are valid
def __update(self): self.reset() if not os.path.exists(self.IRQ_FILE): return self.stats try: with open(self.IRQ_FILE) as irq_proc: time_since_update = getTimeSinceLastUpdate('irq') self.__header(irq_proc.readline()) for lin...
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '__update'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; ...
Load the IRQ file and update the internal dict.
def serialize(self): keys = self._all_keys() serdata = {} for fieldname, value in self._data.items(): serdata[fieldname] = getattr(type(self), fieldname).python_to_cache(value) return json.dumps(serdata)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'serialize'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'};...
Serialize all the fields into one string.
def _getFont(self, font): if os.path.isfile(font): font_files = [font] else: font_files = fc.query(family=font) if not font_files: raise ValueError('No such font') return font_files
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_getFont'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sel...
Returns font paths from font name or path
def owner(self): if self._writer is not None: return self.WRITER if self._readers: return self.READER return None
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'owner'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'i...
Returns whether the lock is locked by a writer or reader.
def create_process(self, command, shell=True, stdout=None, stderr=None, env=None): env = env if env is not None else dict(os.environ) env['DISPLAY'] = self.display return subprocess.Popen(command, shell=shell, stdout=stdout, stderr=stderr, ...
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_process'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', ...
Execute a process using subprocess.Popen, setting the backend's DISPLAY
def positive_float(string): error_msg = 'Positive float required, {string} given.'.format(string=string) try: value = float(string) except ValueError: raise ArgumentTypeError(error_msg) if value < 0: raise ArgumentTypeError(error_msg) return value
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'positive_float'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'st...
Convert string to positive float.
def contains(self, key): for store in self._stores: if store.contains(key): return True return False
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'contains'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sel...
Returns whether the object is in this datastore.
def collect_episodes(local_evaluator=None, remote_evaluators=[], timeout_seconds=180): pending = [ a.apply.remote(lambda ev: ev.get_metrics()) for a in remote_evaluators ] collected, _ = ray.wait( pending, num_returns=len(pending), timeout=timeout_se...
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'collect_episodes'}; {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10']}; {'id': '4', 'type': 'default_parameter', 'childr...
Gathers new episodes metrics tuples from the given evaluators.
def main(): parser = argparse.ArgumentParser( description='Start an instance of the Cheroot WSGI/HTTP server.', ) for arg, spec in _arg_spec.items(): parser.add_argument(arg, **spec) raw_args = parser.parse_args() '' in sys.path or sys.path.insert(0, '') raw_args._wsgi_app.server...
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '4']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'main'}; {'id': '3', 'type': 'parameters', 'children': []}; {'id': '4', 'type': 'block', 'children': ['5', '16', '35', '43', '59']}; {'...
Create a new Cheroot instance with arguments from the command line.
def cli(env): ticket_mgr = SoftLayer.TicketManager(env.client) table = formatting.Table(['id', 'subject']) for subject in ticket_mgr.list_subjects(): table.add_row([subject['id'], subject['name']]) env.fout(table)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'cli'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'env'}; {'id':...
List Subject IDs for ticket creation.
def _fetch_headers(self): self._header_text, self._n_ref = self._read_top_header() self._ref_lengths, self._ref_names = self._read_reference_information() self._header = SAMHeader(self._header_text)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_fetch_headers'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'se...
Needs ._fh handle to stream to be set by child
def insult(rest): "Generate a random insult from datahamster" url = 'http://autoinsult.datahamster.com/' ins_type = random.randrange(4) ins_url = url + "?style={ins_type}".format(**locals()) insre = re.compile('<div class="insult" id="insult">(.*?)</div>') resp = requests.get(ins_url) resp.raise_for_status() in...
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'insult'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'rest'}; {'...
Generate a random insult from datahamster
def _get_args(self, *args) -> (Exception, str): ex = None msg = None for arg in args: if isinstance(arg, str): msg = arg elif isinstance(arg, Exception): ex = arg return ex, msg
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_args'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
Returns exception and message from the provided arguments
def format_value(self, val): if isinstance(val, six.text_type): return self.format_string(val) else: return six.text_type(val)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'format_value'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': ...
Helper function to format a value.
def prepare_auth(self, auth, url=''): if auth is None: url_auth = get_auth_from_url(self.url) auth = url_auth if any(url_auth) else None if auth: if isinstance(auth, tuple) and len(auth) == 2: auth = HTTPBasicAuth(*auth) r = auth(self) ...
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'prepare_auth'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'val...
Prepares the given HTTP auth data.
def loop(self): for mail in Mail.objects.filter(done=False, send_fail_count__lt=3): mail.send_mail() for mail in Mail.objects.filter(done=True, timestamp__lt=time() - 60 * 60 * 24 * 7): mail.delete() return 1, None
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'loop'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id...
check for mails and send them
def elliot_function( signal, derivative=False ): s = 1 abs_signal = (1 + np.abs(signal * s)) if derivative: return 0.5 * s / abs_signal**2 else: return 0.5*(signal * s) / abs_signal + 0.5
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'elliot_function'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value...
A fast approximation of sigmoid
def add_to_map(map_obj, lat, lon, date_time, key, cluster_obj): text = "Event {0} at {1}".format(key, date_time.split()[1]) folium.Marker([lat, lon], popup=text).add_to(cluster_obj)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_to_map'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'child...
Add individual elements to a foilum map in a cluster object
def finalize(self, result): if not self._running: return del os.environ["TEST_MONGODB"] del os.environ["TEST_MONGODB_DATABASE"] if sys.platform == 'darwin': self.process.kill() else: self.process.terminate() self.process.wait() ...
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'finalize'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'sel...
Stop the mongodb instance.
def _rm_gos_edges(rm_goids, edges_all): edges_reduced = [] for goid_child, goid_parent in sorted(edges_all, key=lambda t: t[1]): if goid_child not in rm_goids and goid_parent not in rm_goids: edges_reduced.append((goid_child, goid_parent)) return edges_reduced
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_rm_gos_edges'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value':...
Remove any is_a edges that contain user-specified edges.
def find_file(name, directory): path_bits = directory.split(os.sep) for i in range(0, len(path_bits) - 1): check_path = path_bits[0:len(path_bits) - i] check_file = "%s%s%s" % (os.sep.join(check_path), os.sep, name) if os.path.exists(check_file): return abspath(check_file) ...
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_file'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'na...
Searches up from a directory looking for a file
def execute(self, cacheable=False): if self.network.is_caching_enabled() and cacheable: response = self._get_cached_response() else: response = self._download_response() return minidom.parseString(_string(response).replace("opensearch:", ""))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'execute'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self...
Returns the XML DOM response of the POST Request from the server
def privmsg(self, target, message, nowait=False): if message: messages = utils.split_message(message, self.config.max_length) if isinstance(target, DCCChat): for message in messages: target.send_line(message) elif target: f ...
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'privmsg'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'va...
send a privmsg to target
def runPlugins(self, category, func, protocol, *args): for plugin in self.plugins: try: event_listener = getattr(plugin, func) except AttributeError: pass else: try: stop = event_listener(protocol, *args) ...
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'runPlugins'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children':...
Run the specified set of plugins against a given protocol.
def name(self) -> str: if self.is_platform: if self._data["publicCode"]: return self._data['name'] + " Platform " + \ self._data["publicCode"] else: return self._data['name'] + " Platform " + \ self.place_id.sp...
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'name'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'};...
Friendly name for the stop place or platform
def sign(self, encoded): signature = self._hmac.copy() signature.update(encoded) return signature.hexdigest().encode('utf-8')
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sign'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'};...
Return authentication signature of encoded bytes