code
stringlengths
51
2.34k
sequence
stringlengths
186
3.94k
docstring
stringlengths
11
171
def check_udp(helper, host, port, session): open_ports = walk_data(session, '.1.3.6.1.2.1.7.5.1.2', helper)[0] if scan: print "All open UDP ports at host " + host for port in open_ports: print "UDP: \t" + port quit() if port in open_ports: udp_status = "OPEN" else: udp_status = "CLOSED" helper.status(critical) return ("Current status for UDP port " + port + " is: " + udp_status)
module function_definition identifier parameters identifier identifier identifier identifier block expression_statement assignment identifier subscript call identifier argument_list identifier string string_start string_content string_end identifier integer if_statement identifier block print_statement binary_operator string string_start string_content string_end identifier for_statement identifier identifier block print_statement binary_operator string string_start string_content escape_sequence string_end identifier expression_statement call identifier argument_list if_statement comparison_operator identifier identifier block expression_statement assignment identifier string string_start string_content string_end else_clause block expression_statement assignment identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier return_statement parenthesized_expression binary_operator binary_operator binary_operator string string_start string_content string_end identifier string string_start string_content string_end identifier
the check logic for UDP ports
def close(self): if not self.connected: return None if self.config is not None: if self.config.changed() and not self.config.committed(): try: self.config.discard() except pyPluribus.exceptions.ConfigurationDiscardError as discarderr: raise pyPluribus.exceptions.ConnectionError("Could not discard the configuration: \ {err}".format(err=discarderr)) self._connection.close() self.config = None self._connection = None self.connected = False
module function_definition identifier parameters identifier block if_statement not_operator attribute identifier identifier block return_statement none if_statement comparison_operator attribute identifier identifier none block if_statement boolean_operator call attribute attribute identifier identifier identifier argument_list not_operator call attribute attribute identifier identifier identifier argument_list block try_statement block expression_statement call attribute attribute identifier identifier identifier argument_list except_clause as_pattern attribute attribute identifier identifier identifier as_pattern_target identifier block raise_statement call attribute attribute identifier identifier identifier argument_list call attribute string string_start string_content escape_sequence string_end identifier argument_list keyword_argument identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list expression_statement assignment attribute identifier identifier none expression_statement assignment attribute identifier identifier none expression_statement assignment attribute identifier identifier false
Closes the SSH connection if the connection is UP.
def _check(self): import time if self.expires_in is None or self.authenticated is None: return False current = time.time() expire_time = self.authenticated + self.expires_in return expire_time > current
module function_definition identifier parameters identifier block import_statement dotted_name identifier if_statement boolean_operator comparison_operator attribute identifier identifier none comparison_operator attribute identifier identifier none block return_statement false expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier binary_operator attribute identifier identifier attribute identifier identifier return_statement comparison_operator identifier identifier
Check if the access token is expired or not.
def cpp_spec(): return { INDENTATION : '\t', BEG_BLOCK : '{', END_BLOCK : '}', BEG_LINE : '', END_LINE : '\n', BEG_ACTION : '', END_ACTION : ';', BEG_CONDITION : 'if(', END_CONDITION : ')', LOGICAL_AND : ' && ', LOGICAL_OR : ' || ' }
module function_definition identifier parameters block return_statement dictionary pair identifier string string_start string_content escape_sequence string_end pair identifier string string_start string_content string_end pair identifier string string_start string_content string_end pair identifier string string_start string_end pair identifier string string_start string_content escape_sequence string_end pair identifier string string_start string_end pair identifier string string_start string_content string_end pair identifier string string_start string_content string_end pair identifier string string_start string_content string_end pair identifier string string_start string_content string_end pair identifier string string_start string_content string_end
C++ specification, provided for example, and java compatible.
def bytes_from_decode_data(s): if isinstance(s, (str, unicode)): try: return s.encode('ascii') except UnicodeEncodeError: raise NotValidParamError( 'String argument should contain only ASCII characters') if isinstance(s, bytes_types): return s try: return memoryview(s).tobytes() except TypeError: raise suppress_context( TypeError( 'Argument should be a bytes-like object or ASCII string, not ' '{!r}'.format(s.__class__.__name__)))
module function_definition identifier parameters identifier block if_statement call identifier argument_list identifier tuple identifier identifier block try_statement block return_statement call attribute identifier identifier argument_list string string_start string_content string_end except_clause identifier block raise_statement call identifier argument_list string string_start string_content string_end if_statement call identifier argument_list identifier identifier block return_statement identifier try_statement block return_statement call attribute call identifier argument_list identifier identifier argument_list except_clause identifier block raise_statement call identifier argument_list call identifier argument_list call attribute concatenated_string string string_start string_content string_end string string_start string_content string_end identifier argument_list attribute attribute identifier identifier identifier
copy from base64._bytes_from_decode_data
def add_tags(self, md5, tags): if not tags: return tag_set = set(self.get_tags(md5)) if self.get_tags(md5) else set() if isinstance(tags, str): tags = [tags] for tag in tags: tag_set.add(tag) self.data_store.store_work_results({'tags': list(tag_set)}, 'tags', md5)
module function_definition identifier parameters identifier identifier identifier block if_statement not_operator identifier block return_statement expression_statement assignment identifier conditional_expression call identifier argument_list call attribute identifier identifier argument_list identifier call attribute identifier identifier argument_list identifier call identifier argument_list if_statement call identifier argument_list identifier identifier block expression_statement assignment identifier list identifier for_statement identifier identifier block expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list dictionary pair string string_start string_content string_end call identifier argument_list identifier string string_start string_content string_end identifier
Add tags to this sample
def _create_thumbnail(self, source_image, geometry_string, options, thumbnail): logger.debug('Creating thumbnail file [%s] at [%s] with [%s]', thumbnail.name, geometry_string, options) ratio = default.engine.get_image_ratio(source_image, options) geometry = parse_geometry(geometry_string, ratio) image = default.engine.create(source_image, geometry, options) default.engine.write(image, options, thumbnail) size = default.engine.get_image_size(image) thumbnail.set_size(size)
module function_definition identifier parameters identifier identifier identifier identifier identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end attribute identifier identifier identifier identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier identifier expression_statement assignment identifier call identifier argument_list identifier identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list identifier identifier identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier
Creates the thumbnail by using default.engine
def publish_scene_name(self, scene_id, name): self.sequence_number += 1 self.publisher.send_multipart(msgs.MessageBuilder.scene_name(self.sequence_number, scene_id, name)) return self.sequence_number
module function_definition identifier parameters identifier identifier identifier block expression_statement augmented_assignment attribute identifier identifier integer expression_statement call attribute attribute identifier identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list attribute identifier identifier identifier identifier return_statement attribute identifier identifier
publish a changed scene name
def unmarshall_key(self, key, cls): return setattr(cls, key, self.get(key))
module function_definition identifier parameters identifier identifier identifier block return_statement call identifier argument_list identifier identifier call attribute identifier identifier argument_list identifier
Takes a single key and unmarshalls it into a class.
def resolve(self): model = self.copy() for ct in model.component_types: model.resolve_component_type(ct) for c in model.components: if c.id not in model.fat_components: model.add(model.fatten_component(c)) for c in ct.constants: c2 = c.copy() c2.numeric_value = model.get_numeric_value(c2.value, c2.dimension) model.add(c2) return model
module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list for_statement identifier attribute identifier identifier block expression_statement call attribute identifier identifier argument_list identifier for_statement identifier attribute identifier identifier block if_statement comparison_operator attribute identifier identifier attribute identifier identifier block expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list identifier for_statement identifier attribute identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list identifier return_statement identifier
Resolves references in this model.
def snooze(self, from_email, duration): if from_email is None or not isinstance(from_email, six.string_types): raise MissingFromEmail(from_email) endpoint = '/'.join((self.endpoint, self.id, 'snooze')) add_headers = {'from': from_email, } return self.__class__.create( endpoint=endpoint, api_key=self.api_key, add_headers=add_headers, data_key='duration', data=duration, )
module function_definition identifier parameters identifier identifier identifier block if_statement boolean_operator comparison_operator identifier none not_operator call identifier argument_list identifier attribute identifier identifier block raise_statement call identifier argument_list identifier expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list tuple attribute identifier identifier attribute identifier identifier string string_start string_content string_end expression_statement assignment identifier dictionary pair string string_start string_content string_end identifier return_statement call attribute attribute identifier identifier identifier argument_list keyword_argument identifier identifier keyword_argument identifier attribute identifier identifier keyword_argument identifier identifier keyword_argument identifier string string_start string_content string_end keyword_argument identifier identifier
Snooze this incident for `duration` seconds.
def was_packet_accepted(self, packet): self._validatepacket(packet) cmd = ord(packet[2]) if cmd == Vendapin.ACK: return True elif cmd == Vendapin.NAK: print('NAK - Rejected/Negative Status') return False elif cmd == Vendapin.INC: raise Exception('INC - Incomplete Command Packet') elif cmd == Vendapin.UNR: raise Exception('UNR - Unrecognized Command Packet') elif cmd == Vendapin.CER: raise Exception('CER - Data Packet Checksum Error') else: raise Exception('Received bad CMD in response from card dispenser')
module function_definition identifier parameters identifier identifier block expression_statement call attribute identifier identifier argument_list identifier expression_statement assignment identifier call identifier argument_list subscript identifier integer if_statement comparison_operator identifier attribute identifier identifier block return_statement true elif_clause comparison_operator identifier attribute identifier identifier block expression_statement call identifier argument_list string string_start string_content string_end return_statement false elif_clause comparison_operator identifier attribute identifier identifier block raise_statement call identifier argument_list string string_start string_content string_end elif_clause comparison_operator identifier attribute identifier identifier block raise_statement call identifier argument_list string string_start string_content string_end elif_clause comparison_operator identifier attribute identifier identifier block raise_statement call identifier argument_list string string_start string_content string_end else_clause block raise_statement call identifier argument_list string string_start string_content string_end
parse the "command" byte from the response packet to get a "response code"
def apply(self, arr): for t in self.cpu_transforms: arr = t.apply(arr) return arr
module function_definition identifier parameters identifier identifier block for_statement identifier attribute identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier return_statement identifier
Apply all CPU transforms on an array.
async def update_status(self): if self._operation.async_url: self._response = await self.request_status(self._operation.async_url) self._operation.set_async_url_if_present(self._response) self._operation.get_status_from_async(self._response) elif self._operation.location_url: self._response = await self.request_status(self._operation.location_url) self._operation.set_async_url_if_present(self._response) self._operation.get_status_from_location(self._response) elif self._operation.method == "PUT": initial_url = self._operation.initial_response.request.url self._response = await self.request_status(initial_url) self._operation.set_async_url_if_present(self._response) self._operation.get_status_from_resource(self._response) else: raise BadResponse("Unable to find status link for polling.")
module function_definition identifier parameters identifier block if_statement attribute attribute identifier identifier identifier block expression_statement assignment attribute identifier identifier await call attribute identifier identifier argument_list attribute attribute identifier identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier elif_clause attribute attribute identifier identifier identifier block expression_statement assignment attribute identifier identifier await call attribute identifier identifier argument_list attribute attribute identifier identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier elif_clause comparison_operator attribute attribute identifier identifier identifier string string_start string_content string_end block expression_statement assignment identifier attribute attribute attribute attribute identifier identifier identifier identifier identifier expression_statement assignment attribute identifier identifier await call attribute identifier identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier else_clause block raise_statement call identifier argument_list string string_start string_content string_end
Update the current status of the LRO.
def replace_name(expr: AST, old_name: str, new_name: str) -> AST: return _NameReplacer(old_name, new_name).visit(deepcopy(expr))
module function_definition identifier parameters typed_parameter identifier type identifier typed_parameter identifier type identifier typed_parameter identifier type identifier type identifier block return_statement call attribute call identifier argument_list identifier identifier identifier argument_list call identifier argument_list identifier
Replace all Name nodes named `old_name` with nodes named `new_name`.
def __put_key(self, local_file, target_file, acl='public-read', del_after_upload=False, overwrite=True, source="filename"): action_word = "moving" if del_after_upload else "copying" try: self.k.key = target_file if source == "filename": self.k.set_contents_from_filename(local_file, self.AWS_HEADERS) elif source == "fileobj": self.k.set_contents_from_file(local_file, self.AWS_HEADERS) elif source == "string": self.k.set_contents_from_string(local_file, self.AWS_HEADERS) else: raise Exception("%s is not implemented as a source." % source) self.k.set_acl(acl) self.k.close() self.printv("%s %s to %s" % (action_word, local_file, target_file)) if del_after_upload and source == "filename": try: os.remove(local_file) except: logger.error("Unable to delete the file: ", local_file, exc_info=True) return True except: logger.error("Error in writing to %s", target_file, exc_info=True) return False
module function_definition identifier parameters identifier identifier identifier default_parameter identifier string string_start string_content string_end default_parameter identifier false default_parameter identifier true default_parameter identifier string string_start string_content string_end block expression_statement assignment identifier conditional_expression string string_start string_content string_end identifier string string_start string_content string_end try_statement block expression_statement assignment attribute attribute identifier identifier identifier identifier if_statement comparison_operator identifier string string_start string_content string_end block expression_statement call attribute attribute identifier identifier identifier argument_list identifier attribute identifier identifier elif_clause comparison_operator identifier string string_start string_content string_end block expression_statement call attribute attribute identifier identifier identifier argument_list identifier attribute identifier identifier elif_clause comparison_operator identifier string string_start string_content string_end block expression_statement call attribute attribute identifier identifier identifier argument_list identifier attribute identifier identifier else_clause block raise_statement call identifier argument_list binary_operator string string_start string_content string_end identifier expression_statement call attribute attribute identifier identifier identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list expression_statement call attribute identifier identifier argument_list binary_operator string string_start string_content string_end tuple identifier identifier identifier if_statement boolean_operator identifier comparison_operator identifier string string_start string_content string_end block try_statement block expression_statement call attribute identifier identifier argument_list identifier except_clause block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier keyword_argument identifier true return_statement true except_clause block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier keyword_argument identifier true return_statement false
Copy a file to s3.
def update_release(id, **kwargs): data = update_release_raw(id, **kwargs) if data: return utils.format_json(data)
module function_definition identifier parameters identifier dictionary_splat_pattern identifier block expression_statement assignment identifier call identifier argument_list identifier dictionary_splat identifier if_statement identifier block return_statement call attribute identifier identifier argument_list identifier
Update an existing ProductRelease with new information
def user_deleted(sender, **kwargs): if kwargs.get('created'): write('user_variations', {'variation': 1}, tags={'action': 'created'}) write('user_count', {'total': User.objects.count()})
module function_definition identifier parameters identifier dictionary_splat_pattern identifier block if_statement call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement call identifier argument_list string string_start string_content string_end dictionary pair string string_start string_content string_end integer keyword_argument identifier dictionary pair string string_start string_content string_end string string_start string_content string_end expression_statement call identifier argument_list string string_start string_content string_end dictionary pair string string_start string_content string_end call attribute attribute identifier identifier identifier argument_list
collect metrics about new users signing up
def maiden(self): if self._dialect == DIALECT_DEFAULT: for name in self._names: if name.type == "maiden": return name.value[1] if self._primary and len(self._primary.value) > 3: return self._primary.value[3] return None
module function_definition identifier parameters identifier block if_statement comparison_operator attribute identifier identifier identifier block for_statement identifier attribute identifier identifier block if_statement comparison_operator attribute identifier identifier string string_start string_content string_end block return_statement subscript attribute identifier identifier integer if_statement boolean_operator attribute identifier identifier comparison_operator call identifier argument_list attribute attribute identifier identifier identifier integer block return_statement subscript attribute attribute identifier identifier identifier integer return_statement none
Maiden last name, can be None
def find_hwpack_dir(root): root = path(root) log.debug('files in dir: %s', root) for x in root.walkfiles(): log.debug(' %s', x) hwpack_dir = None for h in (root.walkfiles('boards.txt')): assert not hwpack_dir hwpack_dir = h.parent log.debug('found hwpack: %s', hwpack_dir) assert hwpack_dir return hwpack_dir
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier for_statement identifier call attribute identifier identifier argument_list block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier expression_statement assignment identifier none for_statement identifier parenthesized_expression call attribute identifier identifier argument_list string string_start string_content string_end block assert_statement not_operator identifier expression_statement assignment identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier assert_statement identifier return_statement identifier
search for hwpack dir under root.
def on_any_event(self, event): self.updated = True if self._changed: self._changed()
module function_definition identifier parameters identifier identifier block expression_statement assignment attribute identifier identifier true if_statement attribute identifier identifier block expression_statement call attribute identifier identifier argument_list
Called whenever a FS event occurs.
def merge_users(merge_to, merge_from): assert(merge_to.username.endswith('umail.ucsb.edu')) for u2g in merge_from.groups_assocs[:]: merge_to.group_with(merge_from, u2g.project, bypass_limit=True) merge_to.classes.extend(merge_from.classes) merge_to.files.extend(merge_from.files) for sub in Submission.query_by(created_by=merge_from).all(): sub.created_by = merge_to Session.delete(merge_from)
module function_definition identifier parameters identifier identifier block assert_statement parenthesized_expression call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end for_statement identifier subscript attribute identifier identifier slice block expression_statement call attribute identifier identifier argument_list identifier attribute identifier identifier keyword_argument identifier true expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier for_statement identifier call attribute call attribute identifier identifier argument_list keyword_argument identifier identifier identifier argument_list block expression_statement assignment attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list identifier
Merge a non-umail account with a umail account.
def as_bitcode(self): ptr = c_char_p(None) size = c_size_t(-1) ffi.lib.LLVMPY_WriteBitcodeToString(self, byref(ptr), byref(size)) if not ptr: raise MemoryError try: assert size.value >= 0 return string_at(ptr, size.value) finally: ffi.lib.LLVMPY_DisposeString(ptr)
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list none expression_statement assignment identifier call identifier argument_list unary_operator integer expression_statement call attribute attribute identifier identifier identifier argument_list identifier call identifier argument_list identifier call identifier argument_list identifier if_statement not_operator identifier block raise_statement identifier try_statement block assert_statement comparison_operator attribute identifier identifier integer return_statement call identifier argument_list identifier attribute identifier identifier finally_clause block expression_statement call attribute attribute identifier identifier identifier argument_list identifier
Return the module's LLVM bitcode, as a bytes object.
def next(self): if self._current_index < len(self._collection): value = self._collection[self._current_index] self._current_index += 1 return value elif self._next_cursor: self.__fetch_next() return self.next() else: self._current_index = 0 raise StopIteration
module function_definition identifier parameters identifier block if_statement comparison_operator attribute identifier identifier call identifier argument_list attribute identifier identifier block expression_statement assignment identifier subscript attribute identifier identifier attribute identifier identifier expression_statement augmented_assignment attribute identifier identifier integer return_statement identifier elif_clause attribute identifier identifier block expression_statement call attribute identifier identifier argument_list return_statement call attribute identifier identifier argument_list else_clause block expression_statement assignment attribute identifier identifier integer raise_statement identifier
Returns the next item in the cursor.
def update_hash_from_str(hsh, str_input): byte_input = str(str_input).encode("UTF-8") hsh.update(byte_input)
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute call identifier argument_list identifier identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier
Convert a str to object supporting buffer API and update a hash with it.
def call(self, method, *args, **kwargs): tried_reconnect = False for _ in range(2): try: self._send_call(self.deluge_version, self.deluge_protocol_version, method, *args, **kwargs) return self._receive_response(self.deluge_version, self.deluge_protocol_version) except (socket.error, ConnectionLostException, CallTimeoutException): if self.automatic_reconnect: if tried_reconnect: raise FailedToReconnectException() else: try: self.reconnect() except (socket.error, ConnectionLostException, CallTimeoutException): raise FailedToReconnectException() tried_reconnect = True else: raise
module function_definition identifier parameters identifier identifier list_splat_pattern identifier dictionary_splat_pattern identifier block expression_statement assignment identifier false for_statement identifier call identifier argument_list integer block try_statement block expression_statement call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier identifier list_splat identifier dictionary_splat identifier return_statement call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier except_clause tuple attribute identifier identifier identifier identifier block if_statement attribute identifier identifier block if_statement identifier block raise_statement call identifier argument_list else_clause block try_statement block expression_statement call attribute identifier identifier argument_list except_clause tuple attribute identifier identifier identifier identifier block raise_statement call identifier argument_list expression_statement assignment identifier true else_clause block raise_statement
Calls an RPC function
def BitVecFuncVal( value: int, func_name: str, size: int, annotations: Annotations = None, input_: Union[int, "BitVec"] = None, ) -> BitVecFunc: raw = z3.BitVecVal(value, size) return BitVecFunc(raw, func_name, input_, annotations)
module function_definition identifier parameters typed_parameter identifier type identifier typed_parameter identifier type identifier typed_parameter identifier type identifier typed_default_parameter identifier type identifier none typed_default_parameter identifier type generic_type identifier type_parameter type identifier type string string_start string_content string_end none type identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier return_statement call identifier argument_list identifier identifier identifier identifier
Creates a new bit vector function with a concrete value.
def feasible_set(self): for y in itertools.product(*[range(1, k + 1) for k in self.K]): yield np.array(y)
module function_definition identifier parameters identifier block for_statement identifier call attribute identifier identifier argument_list list_splat list_comprehension call identifier argument_list integer binary_operator identifier integer for_in_clause identifier attribute identifier identifier block expression_statement yield call attribute identifier identifier argument_list identifier
Iterator over values in feasible set
def in_region(rname, rstart, target_chr, target_start, target_end): return (rname == target_chr) and \ (target_start <= rstart <= target_end)
module function_definition identifier parameters identifier identifier identifier identifier identifier block return_statement boolean_operator parenthesized_expression comparison_operator identifier identifier line_continuation parenthesized_expression comparison_operator identifier identifier identifier
Quick check if a point is within the target region.
def _sunos_memdata(): grains = {'mem_total': 0, 'swap_total': 0} prtconf = '/usr/sbin/prtconf 2>/dev/null' for line in __salt__['cmd.run'](prtconf, python_shell=True).splitlines(): comps = line.split(' ') if comps[0].strip() == 'Memory' and comps[1].strip() == 'size:': grains['mem_total'] = int(comps[2].strip()) swap_cmd = salt.utils.path.which('swap') swap_data = __salt__['cmd.run']('{0} -s'.format(swap_cmd)).split() try: swap_avail = int(swap_data[-2][:-1]) swap_used = int(swap_data[-4][:-1]) swap_total = (swap_avail + swap_used) // 1024 except ValueError: swap_total = None grains['swap_total'] = swap_total return grains
module function_definition identifier parameters block expression_statement assignment identifier dictionary pair string string_start string_content string_end integer pair string string_start string_content string_end integer expression_statement assignment identifier string string_start string_content string_end for_statement identifier call attribute call subscript identifier string string_start string_content string_end argument_list identifier keyword_argument identifier true identifier argument_list block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end if_statement boolean_operator comparison_operator call attribute subscript identifier integer identifier argument_list string string_start string_content string_end comparison_operator call attribute subscript identifier integer identifier argument_list string string_start string_content string_end block expression_statement assignment subscript identifier string string_start string_content string_end call identifier argument_list call attribute subscript identifier integer identifier argument_list expression_statement assignment identifier call attribute attribute attribute identifier identifier identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute call subscript identifier string string_start string_content string_end argument_list call attribute string string_start string_content string_end identifier argument_list identifier identifier argument_list try_statement block expression_statement assignment identifier call identifier argument_list subscript subscript identifier unary_operator integer slice unary_operator integer expression_statement assignment identifier call identifier argument_list subscript subscript identifier unary_operator integer slice unary_operator integer expression_statement assignment identifier binary_operator parenthesized_expression binary_operator identifier identifier integer except_clause identifier block expression_statement assignment identifier none expression_statement assignment subscript identifier string string_start string_content string_end identifier return_statement identifier
Return the memory information for SunOS-like systems
def _convert_to_boolean(self, value): if value.lower() not in self.BOOLEAN_STATES: raise ValueError('Not a boolean: %s' % value) return self.BOOLEAN_STATES[value.lower()]
module function_definition identifier parameters identifier identifier block if_statement comparison_operator call attribute identifier identifier argument_list attribute identifier identifier block raise_statement call identifier argument_list binary_operator string string_start string_content string_end identifier return_statement subscript attribute identifier identifier call attribute identifier identifier argument_list
Return a boolean value translating from other types if necessary.
def import_discord_user(self, uid, user): url = api_url+'users/social/' payload = { 'user': int(user), 'provider': 'discord', 'uid': str(uid) } print(json.dumps(payload)) r = requests.put(url, data=json.dumps(payload), headers=self.headers) print(request_status(r)) r.raise_for_status() return DiscordUser(r.json())
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier binary_operator identifier string string_start string_content string_end expression_statement assignment identifier dictionary pair string string_start string_content string_end call identifier argument_list identifier pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end call identifier argument_list identifier expression_statement call identifier argument_list call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier keyword_argument identifier call attribute identifier identifier argument_list identifier keyword_argument identifier attribute identifier identifier expression_statement call identifier argument_list call identifier argument_list identifier expression_statement call attribute identifier identifier argument_list return_statement call identifier argument_list call attribute identifier identifier argument_list
Add a discord user to the database if not already present, get if is present.
def ensure_dir(directory: str) -> None: if not os.path.isdir(directory): LOG.debug(f"Directory {directory} does not exist, creating it.") os.makedirs(directory)
module function_definition identifier parameters typed_parameter identifier type identifier type none block if_statement not_operator call attribute attribute identifier identifier identifier argument_list identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content interpolation identifier string_content string_end expression_statement call attribute identifier identifier argument_list identifier
Create a directory if it doesn't exist.
def tag_remove(self, *tags): return View({**self.spec, 'tag': list(set(self.tags) - set(tags))})
module function_definition identifier parameters identifier list_splat_pattern identifier block return_statement call identifier argument_list dictionary dictionary_splat attribute identifier identifier pair string string_start string_content string_end call identifier argument_list binary_operator call identifier argument_list attribute identifier identifier call identifier argument_list identifier
Return a view with the specified tags removed
def _update_table_cache(self): self._table_cache.clear() for sel, tab, val in self: try: self._table_cache[tab].append((sel, val)) except KeyError: self._table_cache[tab] = [(sel, val)] assert len(self) == self._len_table_cache()
module function_definition identifier parameters identifier block expression_statement call attribute attribute identifier identifier identifier argument_list for_statement pattern_list identifier identifier identifier identifier block try_statement block expression_statement call attribute subscript attribute identifier identifier identifier identifier argument_list tuple identifier identifier except_clause identifier block expression_statement assignment subscript attribute identifier identifier identifier list tuple identifier identifier assert_statement comparison_operator call identifier argument_list identifier call attribute identifier identifier argument_list
Clears and updates the table cache to be in sync with self
def croak(error, message_writer=message): if isinstance(error, MaltegoException): message_writer(MaltegoTransformExceptionMessage(exceptions=[error])) else: message_writer(MaltegoTransformExceptionMessage(exceptions=[MaltegoException(error)]))
module function_definition identifier parameters identifier default_parameter identifier identifier block if_statement call identifier argument_list identifier identifier block expression_statement call identifier argument_list call identifier argument_list keyword_argument identifier list identifier else_clause block expression_statement call identifier argument_list call identifier argument_list keyword_argument identifier list call identifier argument_list identifier
Throw an exception in the Maltego GUI containing error_msg.
def add_block_hash( self, block_hash ): if len(self.block_hashes) > 2000: raise Exception("A getheaders request cannot have over 2000 block hashes") hash_num = int("0x" + block_hash, 16) bh = BlockHash() bh.block_hash = hash_num self.block_hashes.append( bh ) self.hash_stop = hash_num
module function_definition identifier parameters identifier identifier block if_statement comparison_operator call identifier argument_list attribute identifier identifier integer block raise_statement call identifier argument_list string string_start string_content string_end expression_statement assignment identifier call identifier argument_list binary_operator string string_start string_content string_end identifier integer expression_statement assignment identifier call identifier argument_list expression_statement assignment attribute identifier identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment attribute identifier identifier identifier
Append up to 2000 block hashes for which to get headers.
def copy(self, new_grab=None): obj = self.__class__() obj.process_grab(new_grab if new_grab else self.grab) copy_keys = ('status', 'code', 'head', 'body', 'total_time', 'connect_time', 'name_lookup_time', 'url', 'charset', '_unicode_body', '_grab_config') for key in copy_keys: setattr(obj, key, getattr(self, key)) obj.headers = copy(self.headers) obj.cookies = copy(self.cookies) return obj
module function_definition identifier parameters identifier default_parameter identifier none block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list conditional_expression identifier identifier attribute identifier identifier expression_statement assignment identifier tuple string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end for_statement identifier identifier block expression_statement call identifier argument_list identifier identifier call identifier argument_list identifier identifier expression_statement assignment attribute identifier identifier call identifier argument_list attribute identifier identifier expression_statement assignment attribute identifier identifier call identifier argument_list attribute identifier identifier return_statement identifier
Clone the Response object.
def verify_otp(request): ctx = {} if request.method == "POST": verification_code = request.POST.get('verification_code') if verification_code is None: ctx['error_message'] = "Missing verification code." else: otp_ = UserOTP.objects.get(user=request.user) totp_ = totp.TOTP(otp_.secret_key) is_verified = totp_.verify(verification_code) if is_verified: request.session['verfied_otp'] = True response = redirect(request.POST.get("next", settings.LOGIN_REDIRECT_URL)) return update_rmb_cookie(request, response) ctx['error_message'] = "Your code is expired or invalid." ctx['next'] = request.GET.get('next', settings.LOGIN_REDIRECT_URL) return render(request, 'django_mfa/login_verify.html', ctx, status=400)
module function_definition identifier parameters identifier block expression_statement assignment identifier dictionary if_statement comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end if_statement comparison_operator identifier none block expression_statement assignment subscript identifier string string_start string_content string_end string string_start string_content string_end else_clause block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list keyword_argument identifier attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement identifier block expression_statement assignment subscript attribute identifier identifier string string_start string_content string_end true expression_statement assignment identifier call identifier argument_list call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end attribute identifier identifier return_statement call identifier argument_list identifier identifier expression_statement assignment subscript identifier string string_start string_content string_end string string_start string_content string_end expression_statement assignment subscript identifier string string_start string_content string_end call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end attribute identifier identifier return_statement call identifier argument_list identifier string string_start string_content string_end identifier keyword_argument identifier integer
Verify a OTP request
def _render_template(param, username): env = Environment() template = env.from_string(param) variables = {'username': username} return template.render(variables)
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier dictionary pair string string_start string_content string_end identifier return_statement call attribute identifier identifier argument_list identifier
Render config template, substituting username where found.
def deploy(self): if not os.path.exists(self.path): makedirs(self.path) link(self.vault_path, self.real_path)
module function_definition identifier parameters identifier block if_statement not_operator call attribute attribute identifier identifier identifier argument_list attribute identifier identifier block expression_statement call identifier argument_list attribute identifier identifier expression_statement call identifier argument_list attribute identifier identifier attribute identifier identifier
Creates a link at the original path of this target
def _data_build(self, data, modname, path): try: node = _parse(data + "\n") except (TypeError, ValueError, SyntaxError) as exc: raise exceptions.AstroidSyntaxError( "Parsing Python code failed:\n{error}", source=data, modname=modname, path=path, error=exc, ) from exc if path is not None: node_file = os.path.abspath(path) else: node_file = "<?>" if modname.endswith(".__init__"): modname = modname[:-9] package = True else: package = ( path is not None and os.path.splitext(os.path.basename(path))[0] == "__init__" ) builder = rebuilder.TreeRebuilder(self._manager) module = builder.visit_module(node, modname, node_file, package) module._import_from_nodes = builder._import_from_nodes module._delayed_assattr = builder._delayed_assattr return module
module function_definition identifier parameters identifier identifier identifier identifier block try_statement block expression_statement assignment identifier call identifier argument_list binary_operator identifier string string_start string_content escape_sequence string_end except_clause as_pattern tuple identifier identifier identifier as_pattern_target identifier block raise_statement call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier identifier if_statement comparison_operator identifier none block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier else_clause block expression_statement assignment identifier string string_start string_content string_end if_statement call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement assignment identifier subscript identifier slice unary_operator integer expression_statement assignment identifier true else_clause block expression_statement assignment identifier parenthesized_expression boolean_operator comparison_operator identifier none comparison_operator subscript call attribute attribute identifier identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list identifier integer string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier identifier identifier expression_statement assignment attribute identifier identifier attribute identifier identifier expression_statement assignment attribute identifier identifier attribute identifier identifier return_statement identifier
Build tree node from data and add some informations
def verify_keys(self): verify_keys_endpoint = Template("${rest_root}/site/${public_key}") url = verify_keys_endpoint.substitute(rest_root=self._rest_root, public_key=self._public_key) data = { "clientName": "mollom_python", "clientVersion": "1.0" } self._client.headers["Content-Type"] = "application/x-www-form-urlencoded" response = self._client.post(url, data, timeout=self._timeout) if response.status_code != 200: raise MollomAuthenticationError return True
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list keyword_argument identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier expression_statement assignment identifier dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end string string_start string_content string_end expression_statement assignment subscript attribute attribute identifier identifier identifier string string_start string_content string_end string string_start string_content string_end expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier identifier keyword_argument identifier attribute identifier identifier if_statement comparison_operator attribute identifier identifier integer block raise_statement identifier return_statement true
Verify that the public and private key combination is valid; raises MollomAuthenticationError otherwise
def create_user(self, claims): email = claims.get('email') username = self.get_username(claims) return self.UserModel.objects.create_user(username, email)
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list identifier return_statement call attribute attribute attribute identifier identifier identifier identifier argument_list identifier identifier
Return object for a newly created user account.
def _iterate(self, data, expanded_data): for attribute in SOURCE_KEYS: for k, v in data[attribute].items(): if k == None: group = 'Sources' else: group = k if group in data[attribute].keys(): self._expand_data(data[attribute][group], expanded_data, group) for k, v in data['include_files'].items(): if k == None: group = 'Includes' else: group = k self._expand_data(data['include_files'][group], expanded_data, group) expanded_data['groups'] = OrderedDict(sorted(expanded_data['groups'].items(), key=lambda t: t[0]))
module function_definition identifier parameters identifier identifier identifier block for_statement identifier identifier block for_statement pattern_list identifier identifier call attribute subscript identifier identifier identifier argument_list block if_statement comparison_operator identifier none block expression_statement assignment identifier string string_start string_content string_end else_clause block expression_statement assignment identifier identifier if_statement comparison_operator identifier call attribute subscript identifier identifier identifier argument_list block expression_statement call attribute identifier identifier argument_list subscript subscript identifier identifier identifier identifier identifier for_statement pattern_list identifier identifier call attribute subscript identifier string string_start string_content string_end identifier argument_list block if_statement comparison_operator identifier none block expression_statement assignment identifier string string_start string_content string_end else_clause block expression_statement assignment identifier identifier expression_statement call attribute identifier identifier argument_list subscript subscript identifier string string_start string_content string_end identifier identifier identifier expression_statement assignment subscript identifier string string_start string_content string_end call identifier argument_list call identifier argument_list call attribute subscript identifier string string_start string_content string_end identifier argument_list keyword_argument identifier lambda lambda_parameters identifier subscript identifier integer
_Iterate through all data, store the result expansion in extended dictionary
def parse_lint_result(lint_result_path, manifest_path): unused_string_pattern = re.compile('The resource `R\.string\.([^`]+)` appears to be unused') mainfest_string_refs = get_manifest_string_refs(manifest_path) root = etree.parse(lint_result_path).getroot() issues = [] for issue_xml in root.findall('.//issue[@id="UnusedResources"]'): message = issue_xml.get('message') unused_string = re.match(unused_string_pattern, issue_xml.get('message')) has_string_in_manifest = unused_string and unused_string.group(1) in mainfest_string_refs if not has_string_in_manifest: issues.extend(_get_issues_from_location(UnusedResourceIssue, issue_xml.findall('location'), message)) for issue_xml in root.findall('.//issue[@id="ExtraTranslation"]'): message = issue_xml.get('message') if re.findall(ExtraTranslationIssue.pattern, message): issues.extend(_get_issues_from_location(ExtraTranslationIssue, issue_xml.findall('location'), message)) return issues
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier call attribute call attribute identifier identifier argument_list identifier identifier argument_list expression_statement assignment identifier list for_statement identifier call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier boolean_operator identifier comparison_operator call attribute identifier identifier argument_list integer identifier if_statement not_operator identifier block expression_statement call attribute identifier identifier argument_list call identifier argument_list identifier call attribute identifier identifier argument_list string string_start string_content string_end identifier for_statement identifier call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end if_statement call attribute identifier identifier argument_list attribute identifier identifier identifier block expression_statement call attribute identifier identifier argument_list call identifier argument_list identifier call attribute identifier identifier argument_list string string_start string_content string_end identifier return_statement identifier
Parse lint-result.xml and create Issue for every problem found except unused strings referenced in AndroidManifest
def select_sources(cat_table, cuts): nsrc = len(cat_table) full_mask = np.ones((nsrc), bool) for cut in cuts: if cut == 'mask_extended': full_mask *= mask_extended(cat_table) elif cut == 'select_extended': full_mask *= select_extended(cat_table) else: full_mask *= make_mask(cat_table, cut) lout = [src_name.strip() for src_name in cat_table['Source_Name'][full_mask]] return lout
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list parenthesized_expression identifier identifier for_statement identifier identifier block if_statement comparison_operator identifier string string_start string_content string_end block expression_statement augmented_assignment identifier call identifier argument_list identifier elif_clause comparison_operator identifier string string_start string_content string_end block expression_statement augmented_assignment identifier call identifier argument_list identifier else_clause block expression_statement augmented_assignment identifier call identifier argument_list identifier identifier expression_statement assignment identifier list_comprehension call attribute identifier identifier argument_list for_in_clause identifier subscript subscript identifier string string_start string_content string_end identifier return_statement identifier
Select only rows passing a set of cuts from catalog table
def _convert_asset_timestamp_fields(dict_): for key in _asset_timestamp_fields & viewkeys(dict_): value = pd.Timestamp(dict_[key], tz='UTC') dict_[key] = None if isnull(value) else value return dict_
module function_definition identifier parameters identifier block for_statement identifier binary_operator identifier call identifier argument_list identifier block expression_statement assignment identifier call attribute identifier identifier argument_list subscript identifier identifier keyword_argument identifier string string_start string_content string_end expression_statement assignment subscript identifier identifier conditional_expression none call identifier argument_list identifier identifier return_statement identifier
Takes in a dict of Asset init args and converts dates to pd.Timestamps
def save_cache(dpath, fname, cfgstr, data, ext='.cPkl', verbose=None): fpath = _args2_fpath(dpath, fname, cfgstr, ext) util_io.save_data(fpath, data, verbose=verbose) return fpath
module function_definition identifier parameters identifier identifier identifier identifier default_parameter identifier string string_start string_content string_end default_parameter identifier none block expression_statement assignment identifier call identifier argument_list identifier identifier identifier identifier expression_statement call attribute identifier identifier argument_list identifier identifier keyword_argument identifier identifier return_statement identifier
Saves data using util_io, but smartly constructs a filename
def sentence_starts(self): if not self.is_tagged(SENTENCES): self.tokenize_sentences() return self.starts(SENTENCES)
module function_definition identifier parameters identifier block if_statement not_operator call attribute identifier identifier argument_list identifier block expression_statement call attribute identifier identifier argument_list return_statement call attribute identifier identifier argument_list identifier
The list of start positions representing ``sentences`` layer elements.
def remove_child(self, child): assert child in self.children self.children.remove(child) self.index.pop(child.tax_id) if child.parent is self: child.parent = None if child.index is self.index: child.index = None for n in child: if n is child: continue self.index.pop(n.tax_id) if n.index is self.index: n.index = None
module function_definition identifier parameters identifier identifier block assert_statement comparison_operator identifier attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier if_statement comparison_operator attribute identifier identifier identifier block expression_statement assignment attribute identifier identifier none if_statement comparison_operator attribute identifier identifier attribute identifier identifier block expression_statement assignment attribute identifier identifier none for_statement identifier identifier block if_statement comparison_operator identifier identifier block continue_statement expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier if_statement comparison_operator attribute identifier identifier attribute identifier identifier block expression_statement assignment attribute identifier identifier none
Remove a child from this node.
def create_table_header(self): self.table_header = QTableView() self.table_header.verticalHeader().hide() self.table_header.setEditTriggers(QTableWidget.NoEditTriggers) self.table_header.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.table_header.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.table_header.setHorizontalScrollMode(QTableView.ScrollPerPixel) self.table_header.setHorizontalScrollBar(self.hscroll) self.table_header.setFrameStyle(QFrame.Plain) self.table_header.horizontalHeader().sectionResized.connect( self._column_resized) self.table_header.setItemDelegate(QItemDelegate()) self.layout.addWidget(self.table_header, 0, 1)
module function_definition identifier parameters identifier block expression_statement assignment attribute identifier identifier call identifier argument_list expression_statement call attribute call attribute attribute identifier identifier identifier argument_list identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement call attribute attribute call attribute attribute identifier identifier identifier argument_list identifier identifier argument_list attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list call identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier integer integer
Create the QTableView that will hold the header model.
def missing_requirements_command(missing_programs, installation_string, filename, unused_lines): verb = 'is' if len(missing_programs) > 1: verb = 'are' return { filename: { 'skipped': [ '%s %s not installed. %s' % (', '.join(missing_programs), verb, installation_string) ] } }
module function_definition identifier parameters identifier identifier identifier identifier block expression_statement assignment identifier string string_start string_content string_end if_statement comparison_operator call identifier argument_list identifier integer block expression_statement assignment identifier string string_start string_content string_end return_statement dictionary pair identifier dictionary pair string string_start string_content string_end list binary_operator string string_start string_content string_end tuple call attribute string string_start string_content string_end identifier argument_list identifier identifier identifier
Pseudo-command to be used when requirements are missing.
def age(self): if self.exists: return datetime.utcnow() - datetime.utcfromtimestamp(os.path.getmtime(self.name)) return timedelta()
module function_definition identifier parameters identifier block if_statement attribute identifier identifier block return_statement binary_operator call attribute identifier identifier argument_list call attribute identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list attribute identifier identifier return_statement call identifier argument_list
Age of the video
def unsubscribe(self): _LOGGER.info("PubNub unsubscribing") self._pubnub.unsubscribe_all() self._pubnub.stop() self._pubnub = None
module function_definition identifier parameters identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement call attribute attribute identifier identifier identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list expression_statement assignment attribute identifier identifier none
Completly stop all pubnub operations.
def getContact(self, user=None, channel=None): try: return self.contacts[(channel, user)] except KeyError: new_contact = self.contactClass(self, user=user, channel=channel) self.contacts[(channel, user)] = new_contact new_contact.setServiceParent(self) return new_contact
module function_definition identifier parameters identifier default_parameter identifier none default_parameter identifier none block try_statement block return_statement subscript attribute identifier identifier tuple identifier identifier except_clause identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier keyword_argument identifier identifier keyword_argument identifier identifier expression_statement assignment subscript attribute identifier identifier tuple identifier identifier identifier expression_statement call attribute identifier identifier argument_list identifier return_statement identifier
get a Contact instance for ``user`` on ``channel``
def _process_value(value): if not value: value = _("Not set") elif value == "None": value = _("Not set") elif value == "0": pass elif api.is_uid(value): value = _get_title_or_id_from_uid(value) elif isinstance(value, (dict)): value = json.dumps(sorted(value.items()), indent=1) elif isinstance(value, (list, tuple)): value = sorted(map(_process_value, value)) value = "; ".join(value) elif isinstance(value, unicode): value = api.safe_unicode(value).encode("utf8") return str(value)
module function_definition identifier parameters identifier block if_statement not_operator identifier block expression_statement assignment identifier call identifier argument_list string string_start string_content string_end elif_clause comparison_operator identifier string string_start string_content string_end block expression_statement assignment identifier call identifier argument_list string string_start string_content string_end elif_clause comparison_operator identifier string string_start string_content string_end block pass_statement elif_clause call attribute identifier identifier argument_list identifier block expression_statement assignment identifier call identifier argument_list identifier elif_clause call identifier argument_list identifier parenthesized_expression identifier block expression_statement assignment identifier call attribute identifier identifier argument_list call identifier argument_list call attribute identifier identifier argument_list keyword_argument identifier integer elif_clause call identifier argument_list identifier tuple identifier identifier block expression_statement assignment identifier call identifier argument_list call identifier argument_list identifier identifier expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list identifier elif_clause call identifier argument_list identifier identifier block expression_statement assignment identifier call attribute call attribute identifier identifier argument_list identifier identifier argument_list string string_start string_content string_end return_statement call identifier argument_list identifier
Convert the value into a human readable diff string
def _from_dict(cls, _dict): args = {} if 'total_minutes_of_audio' in _dict: args['total_minutes_of_audio'] = _dict.get('total_minutes_of_audio') else: raise ValueError( 'Required property \'total_minutes_of_audio\' not present in AudioResources JSON' ) if 'audio' in _dict: args['audio'] = [ AudioResource._from_dict(x) for x in (_dict.get('audio')) ] else: raise ValueError( 'Required property \'audio\' not present in AudioResources JSON' ) return cls(**args)
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier dictionary if_statement comparison_operator string string_start string_content string_end identifier block expression_statement assignment subscript identifier string string_start string_content string_end call attribute identifier identifier argument_list string string_start string_content string_end else_clause block raise_statement call identifier argument_list string string_start string_content escape_sequence escape_sequence string_end if_statement comparison_operator string string_start string_content string_end identifier block expression_statement assignment subscript identifier string string_start string_content string_end list_comprehension call attribute identifier identifier argument_list identifier for_in_clause identifier parenthesized_expression call attribute identifier identifier argument_list string string_start string_content string_end else_clause block raise_statement call identifier argument_list string string_start string_content escape_sequence escape_sequence string_end return_statement call identifier argument_list dictionary_splat identifier
Initialize a AudioResources object from a json dictionary.
def interface(self, iface_name): if self.has_interface(iface_name): return self.interfaces[iface_name] else: raise RpcException(ERR_INVALID_PARAMS, "Unknown interface: '%s'", iface_name)
module function_definition identifier parameters identifier identifier block if_statement call attribute identifier identifier argument_list identifier block return_statement subscript attribute identifier identifier identifier else_clause block raise_statement call identifier argument_list identifier string string_start string_content string_end identifier
Returns the interface with the given name, or raises RpcException if no interface matches
def decrypt_stream(mode, in_stream, out_stream, block_size = BLOCK_SIZE, padding = PADDING_DEFAULT): 'Decrypts a stream of bytes from in_stream to out_stream using mode.' decrypter = Decrypter(mode, padding = padding) _feed_stream(decrypter, in_stream, out_stream, block_size)
module function_definition identifier parameters identifier identifier identifier default_parameter identifier identifier default_parameter identifier identifier block expression_statement string string_start string_content string_end expression_statement assignment identifier call identifier argument_list identifier keyword_argument identifier identifier expression_statement call identifier argument_list identifier identifier identifier identifier
Decrypts a stream of bytes from in_stream to out_stream using mode.
def prevent_recursion(default): def decorator(func): name = '_calling_%s_' % func.__name__ def newfunc(self, *args, **kwds): if getattr(self, name, False): return default() setattr(self, name, True) try: return func(self, *args, **kwds) finally: setattr(self, name, False) return newfunc return decorator
module function_definition identifier parameters identifier block function_definition identifier parameters identifier block expression_statement assignment identifier binary_operator string string_start string_content string_end attribute identifier identifier function_definition identifier parameters identifier list_splat_pattern identifier dictionary_splat_pattern identifier block if_statement call identifier argument_list identifier identifier false block return_statement call identifier argument_list expression_statement call identifier argument_list identifier identifier true try_statement block return_statement call identifier argument_list identifier list_splat identifier dictionary_splat identifier finally_clause block expression_statement call identifier argument_list identifier identifier false return_statement identifier return_statement identifier
A decorator that returns the return value of `default` in recursions
def bft(self): queue = deque([self]) while queue: node = queue.pop() yield node if hasattr(node, "childs"): queue.extendleft(node.childs)
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list list identifier while_statement identifier block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement yield identifier if_statement call identifier argument_list identifier string string_start string_content string_end block expression_statement call attribute identifier identifier argument_list attribute identifier identifier
Generator that returns each element of the tree in Breadth-first order
def vectorize(data, cloud=None, api_key=None, version=None, **kwargs): batch = detect_batch(data) data = data_preprocess(data, batch=batch) url_params = {"batch": batch, "api_key": api_key, "version": version, "method": "vectorize"} return api_handler(data, cloud=cloud, api="custom", url_params=url_params, **kwargs)
module function_definition identifier parameters identifier default_parameter identifier none default_parameter identifier none default_parameter identifier none dictionary_splat_pattern identifier block expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier call identifier argument_list identifier keyword_argument identifier identifier expression_statement assignment identifier dictionary pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier pair string string_start string_content string_end string string_start string_content string_end return_statement call identifier argument_list identifier keyword_argument identifier identifier keyword_argument identifier string string_start string_content string_end keyword_argument identifier identifier dictionary_splat identifier
Support for raw features from the custom collections API
def containers_running(get_container_name): running = [] for n in ['web', 'postgres', 'solr', 'datapusher', 'redis']: info = docker.inspect_container(get_container_name(n)) if info and not info['State']['Running']: running.append(n + '(halted)') elif info: running.append(n) return running
module function_definition identifier parameters identifier block expression_statement assignment identifier list for_statement identifier list string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end block expression_statement assignment identifier call attribute identifier identifier argument_list call identifier argument_list identifier if_statement boolean_operator identifier not_operator subscript subscript identifier string string_start string_content string_end string string_start string_content string_end block expression_statement call attribute identifier identifier argument_list binary_operator identifier string string_start string_content string_end elif_clause identifier block expression_statement call attribute identifier identifier argument_list identifier return_statement identifier
Return a list of containers tracked by this environment that are running
def resolve_import(import_path, from_module): if not import_path or not import_path.startswith('.'): return import_path from_module = from_module.split('.') dots = 0 for c in import_path: if c == '.': dots += 1 else: break if dots: from_module = from_module[:-dots] import_path = import_path[dots:] if import_path: from_module.append(import_path) return '.'.join(from_module)
module function_definition identifier parameters identifier identifier block if_statement boolean_operator not_operator identifier not_operator call attribute identifier identifier argument_list string string_start string_content string_end block return_statement identifier expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier integer for_statement identifier identifier block if_statement comparison_operator identifier string string_start string_content string_end block expression_statement augmented_assignment identifier integer else_clause block break_statement if_statement identifier block expression_statement assignment identifier subscript identifier slice unary_operator identifier expression_statement assignment identifier subscript identifier slice identifier if_statement identifier block expression_statement call attribute identifier identifier argument_list identifier return_statement call attribute string string_start string_content string_end identifier argument_list identifier
Resolves relative imports from a module.
def _check_pointers(parser): from fortpy.stats.bp import check_pointers check_pointers(parser, args["source"], args["filter"], args["recursive"])
module function_definition identifier parameters identifier block import_from_statement dotted_name identifier identifier identifier dotted_name identifier expression_statement call identifier argument_list identifier subscript identifier string string_start string_content string_end subscript identifier string string_start string_content string_end subscript identifier string string_start string_content string_end
Checks the pointer best-practice conditions.
def mk_tab_context_menu(callback_object): callback_object.context_menu = Gtk.Menu() menu = callback_object.context_menu mi1 = Gtk.MenuItem(_("New Tab")) mi1.connect("activate", callback_object.on_new_tab) menu.add(mi1) mi2 = Gtk.MenuItem(_("Rename")) mi2.connect("activate", callback_object.on_rename) menu.add(mi2) mi3 = Gtk.MenuItem(_("Close")) mi3.connect("activate", callback_object.on_close) menu.add(mi3) menu.show_all() return menu
module function_definition identifier parameters identifier block expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list expression_statement assignment identifier attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list call identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list string string_start string_content string_end attribute identifier identifier expression_statement call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list call identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list string string_start string_content string_end attribute identifier identifier expression_statement call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list call identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list string string_start string_content string_end attribute identifier identifier expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list return_statement identifier
Create the context menu for a notebook tab
def types(cls, **kwargs): named = {name: factory(Arguments._fields.index(name), name) for name, factory in six.iteritems(kwargs)} return cls(**named)
module function_definition identifier parameters identifier dictionary_splat_pattern identifier block expression_statement assignment identifier dictionary_comprehension pair identifier call identifier argument_list call attribute attribute identifier identifier identifier argument_list identifier identifier for_in_clause pattern_list identifier identifier call attribute identifier identifier argument_list identifier return_statement call identifier argument_list dictionary_splat identifier
Create an Arguments of the possible Types.
def cluster_version(self): versionstr = self.client.info()['version']['number'] return [int(x) for x in versionstr.split('.')]
module function_definition identifier parameters identifier block expression_statement assignment identifier subscript subscript call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end return_statement list_comprehension call identifier argument_list identifier for_in_clause identifier call attribute identifier identifier argument_list string string_start string_content string_end
Get version of Elasticsearch running on the cluster.
def _write_config(self, cfg, slot): old_pgm_seq = self._status.pgm_seq frame = cfg.to_frame(slot=slot) self._debug("Writing %s frame :\n%s\n" % \ (yubikey_config.command2str(frame.command), cfg)) self._write(frame) self._waitfor_clear(yubikey_defs.SLOT_WRITE_FLAG) self.status() self._debug("Programmed slot %i, sequence %i -> %i\n" % (slot, old_pgm_seq, self._status.pgm_seq)) cfgs = self._status.valid_configs() if not cfgs and self._status.pgm_seq == 0: return if self._status.pgm_seq == old_pgm_seq + 1: return raise YubiKeyUSBHIDError('YubiKey programming failed (seq %i not increased (%i))' % \ (old_pgm_seq, self._status.pgm_seq))
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier attribute attribute identifier identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list keyword_argument identifier identifier expression_statement call attribute identifier identifier argument_list binary_operator string string_start string_content escape_sequence escape_sequence string_end line_continuation tuple call attribute identifier identifier argument_list attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list attribute identifier identifier expression_statement call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list binary_operator string string_start string_content escape_sequence string_end tuple identifier identifier attribute attribute identifier identifier identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list if_statement boolean_operator not_operator identifier comparison_operator attribute attribute identifier identifier identifier integer block return_statement if_statement comparison_operator attribute attribute identifier identifier identifier binary_operator identifier integer block return_statement raise_statement call identifier argument_list binary_operator string string_start string_content string_end line_continuation tuple identifier attribute attribute identifier identifier identifier
Write configuration to YubiKey.
def zip_nested(arg0, *args, **kwargs): dict_only = kwargs.pop("dict_only", False) assert not kwargs if isinstance(arg0, dict): return { k: zip_nested(*a, dict_only=dict_only) for k, a in zip_dict(arg0, *args) } elif not dict_only: if isinstance(arg0, list): return [zip_nested(*a, dict_only=dict_only) for a in zip(arg0, *args)] return (arg0,) + args
module function_definition identifier parameters identifier list_splat_pattern identifier dictionary_splat_pattern identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end false assert_statement not_operator identifier if_statement call identifier argument_list identifier identifier block return_statement dictionary_comprehension pair identifier call identifier argument_list list_splat identifier keyword_argument identifier identifier for_in_clause pattern_list identifier identifier call identifier argument_list identifier list_splat identifier elif_clause not_operator identifier block if_statement call identifier argument_list identifier identifier block return_statement list_comprehension call identifier argument_list list_splat identifier keyword_argument identifier identifier for_in_clause identifier call identifier argument_list identifier list_splat identifier return_statement binary_operator tuple identifier identifier
Zip data struct together and return a data struct with the same shape.
def process_settings(self, settings): logging.debug("Using configuration from: %s", settings.name) exec(compile(settings.read(), settings.name, 'exec'), globals(), locals())
module function_definition identifier parameters identifier identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end attribute identifier identifier expression_statement call identifier argument_list call identifier argument_list call attribute identifier identifier argument_list attribute identifier identifier string string_start string_content string_end call identifier argument_list call identifier argument_list
A lazy way of feeding Dharma with configuration settings.
def default(self, obj): if isinstance(obj, Sensor): return { 'sensor_id': obj.sensor_id, 'children': obj.children, 'type': obj.type, 'sketch_name': obj.sketch_name, 'sketch_version': obj.sketch_version, 'battery_level': obj.battery_level, 'protocol_version': obj.protocol_version, 'heartbeat': obj.heartbeat, } if isinstance(obj, ChildSensor): return { 'id': obj.id, 'type': obj.type, 'description': obj.description, 'values': obj.values, } return json.JSONEncoder.default(self, obj)
module function_definition identifier parameters identifier identifier block if_statement call identifier argument_list identifier identifier block return_statement dictionary pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier if_statement call identifier argument_list identifier identifier block return_statement dictionary pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier return_statement call attribute attribute identifier identifier identifier argument_list identifier identifier
Serialize obj into JSON.
def _trig_auth_check(self, useriden): if not self.user.admin and useriden != self.user.iden: raise s_exc.AuthDeny(user=self.user.name, mesg='As non-admin, may only manipulate triggers created by you')
module function_definition identifier parameters identifier identifier block if_statement boolean_operator not_operator attribute attribute identifier identifier identifier comparison_operator identifier attribute attribute identifier identifier identifier block raise_statement call attribute identifier identifier argument_list keyword_argument identifier attribute attribute identifier identifier identifier keyword_argument identifier string string_start string_content string_end
Check that, as a non-admin, may only manipulate resources created by you.
def _run_command_in_extended_path(syslog_ng_sbin_dir, command, params): orig_path = os.environ.get('PATH', '') env = None if syslog_ng_sbin_dir: env = { str('PATH'): salt.utils.stringutils.to_str( os.pathsep.join( salt.utils.data.decode( (orig_path, syslog_ng_sbin_dir) ) ) ) } return _run_command(command, options=params, env=env)
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end string string_start string_end expression_statement assignment identifier none if_statement identifier block expression_statement assignment identifier dictionary pair call identifier argument_list string string_start string_content string_end call attribute attribute attribute identifier identifier identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list call attribute attribute attribute identifier identifier identifier identifier argument_list tuple identifier identifier return_statement call identifier argument_list identifier keyword_argument identifier identifier keyword_argument identifier identifier
Runs the specified command with the syslog_ng_sbin_dir in the PATH
def gotoHome(self): mode = QTextCursor.MoveAnchor if QApplication.instance().keyboardModifiers() == Qt.ShiftModifier: mode = QTextCursor.KeepAnchor cursor = self.textCursor() block = projex.text.nativestring(cursor.block().text()) cursor.movePosition( QTextCursor.StartOfBlock, mode ) if block.startswith('>>> '): cursor.movePosition(QTextCursor.Right, mode, 4) elif block.startswith('... '): match = re.match('...\s*', block) cursor.movePosition(QTextCursor.Right, mode, match.end()) self.setTextCursor(cursor)
module function_definition identifier parameters identifier block expression_statement assignment identifier attribute identifier identifier if_statement comparison_operator call attribute call attribute identifier identifier argument_list identifier argument_list attribute identifier identifier block expression_statement assignment identifier attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list call attribute call attribute identifier identifier argument_list identifier argument_list expression_statement call attribute identifier identifier argument_list attribute identifier identifier identifier if_statement call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement call attribute identifier identifier argument_list attribute identifier identifier identifier integer elif_clause call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end identifier expression_statement call attribute identifier identifier argument_list attribute identifier identifier identifier call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list identifier
Navigates to the home position for the edit.
def events(self, all_instances=None, instance_ids=None, filters=None): params = {} if filters: params["filters"] = make_filters(filters) if instance_ids: params['InstanceIds'] = instance_ids statuses = self.status(all_instances, **params) event_list = [] for status in statuses: if status.get("Events"): for event in status.get("Events"): event[u"InstanceId"] = status.get('InstanceId') event_list.append(event) return event_list
module function_definition identifier parameters identifier default_parameter identifier none default_parameter identifier none default_parameter identifier none block expression_statement assignment identifier dictionary if_statement identifier block expression_statement assignment subscript identifier string string_start string_content string_end call identifier argument_list identifier if_statement identifier block expression_statement assignment subscript identifier string string_start string_content string_end identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier dictionary_splat identifier expression_statement assignment identifier list for_statement identifier identifier block if_statement call attribute identifier identifier argument_list string string_start string_content string_end block for_statement identifier call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement assignment subscript identifier string string_start string_content string_end call attribute identifier identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier return_statement identifier
a list of tuples containing instance Id's and event information
def parse_seqres(self, pdb): seqresre = re.compile("SEQRES") seqreslines = [line for line in pdb.lines if seqresre.match(line)] for line in seqreslines: chain = line[11] resnames = line[19:70].strip() self.setdefault(chain, []) self[chain] += resnames.split()
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier list_comprehension identifier for_in_clause identifier attribute identifier identifier if_clause call attribute identifier identifier argument_list identifier for_statement identifier identifier block expression_statement assignment identifier subscript identifier integer expression_statement assignment identifier call attribute subscript identifier slice integer integer identifier argument_list expression_statement call attribute identifier identifier argument_list identifier list expression_statement augmented_assignment subscript identifier identifier call attribute identifier identifier argument_list
Parse the SEQRES entries into the object
def visit_exec(self, node, parent): newnode = nodes.Exec(node.lineno, node.col_offset, parent) newnode.postinit( self.visit(node.body, newnode), _visit_or_none(node, "globals", self, newnode), _visit_or_none(node, "locals", self, newnode), ) return newnode
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list attribute identifier identifier identifier call identifier argument_list identifier string string_start string_content string_end identifier identifier call identifier argument_list identifier string string_start string_content string_end identifier identifier return_statement identifier
visit an Exec node by returning a fresh instance of it
def _download_ota_script(script_url): try: blob = requests.get(script_url, stream=True) return blob.content except Exception as e: iprint("Failed to download OTA script") iprint(e) return False
module function_definition identifier parameters identifier block try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list identifier keyword_argument identifier true return_statement attribute identifier identifier except_clause as_pattern identifier as_pattern_target identifier block expression_statement call identifier argument_list string string_start string_content string_end expression_statement call identifier argument_list identifier return_statement false
Download the script from the cloud service and store to temporary file location
def __edge_weight(edge_id, dfs_data): graph = dfs_data['graph'] edge_lookup = dfs_data['edge_lookup'] edge = graph.get_edge(edge_id) u, v = edge['vertices'] d_u = D(u, dfs_data) d_v = D(v, dfs_data) lp_1 = L1(v, dfs_data) d_lp_1 = D(lp_1, dfs_data) if edge_lookup[edge_id] == 'backedge' and d_v < d_u: return 2*d_v elif is_type_I_branch(u, v, dfs_data): return 2*d_lp_1 elif is_type_II_branch(u, v, dfs_data): return 2*d_lp_1 + 1 else: return 2*graph.num_nodes() + 1
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier subscript identifier string string_start string_content string_end expression_statement assignment identifier subscript identifier string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment pattern_list identifier identifier subscript identifier string string_start string_content string_end expression_statement assignment identifier call identifier argument_list identifier identifier expression_statement assignment identifier call identifier argument_list identifier identifier expression_statement assignment identifier call identifier argument_list identifier identifier expression_statement assignment identifier call identifier argument_list identifier identifier if_statement boolean_operator comparison_operator subscript identifier identifier string string_start string_content string_end comparison_operator identifier identifier block return_statement binary_operator integer identifier elif_clause call identifier argument_list identifier identifier identifier block return_statement binary_operator integer identifier elif_clause call identifier argument_list identifier identifier identifier block return_statement binary_operator binary_operator integer identifier integer else_clause block return_statement binary_operator binary_operator integer call attribute identifier identifier argument_list integer
Calculates the edge weight used to sort edges.
def extract_domain(var_name, output): var = getenv(var_name) if var: p = urlparse(var) output.append(p.hostname)
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list identifier if_statement identifier block expression_statement assignment identifier call identifier argument_list identifier expression_statement call attribute identifier identifier argument_list attribute identifier identifier
Extracts just the domain name from an URL and adds it to a list
def _onMenuButton(self, evt): x, y = self.GetPositionTuple() w, h = self.GetSizeTuple() self.PopupMenuXY(self._menu, x, y+h-4) evt.Skip()
module function_definition identifier parameters identifier identifier block expression_statement assignment pattern_list identifier identifier call attribute identifier identifier argument_list expression_statement assignment pattern_list identifier identifier call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list attribute identifier identifier identifier binary_operator binary_operator identifier identifier integer expression_statement call attribute identifier identifier argument_list
Handle menu button pressed.
def _load_custom(self, settings_name='localsettings.py'): if settings_name[-3:] == '.py': settings_name = settings_name[:-3] new_settings = {} try: settings = importlib.import_module(settings_name) new_settings = self._convert_to_dict(settings) except ImportError: log.info("No override settings found") for key in new_settings: if key in self.my_settings: item = new_settings[key] if isinstance(item, dict) and \ isinstance(self.my_settings[key], dict): for key2 in item: self.my_settings[key][key2] = item[key2] else: self.my_settings[key] = item else: self.my_settings[key] = new_settings[key]
module function_definition identifier parameters identifier default_parameter identifier string string_start string_content string_end block if_statement comparison_operator subscript identifier slice unary_operator integer string string_start string_content string_end block expression_statement assignment identifier subscript identifier slice unary_operator integer expression_statement assignment identifier dictionary try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier except_clause identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end for_statement identifier identifier block if_statement comparison_operator identifier attribute identifier identifier block expression_statement assignment identifier subscript identifier identifier if_statement boolean_operator call identifier argument_list identifier identifier line_continuation call identifier argument_list subscript attribute identifier identifier identifier identifier block for_statement identifier identifier block expression_statement assignment subscript subscript attribute identifier identifier identifier identifier subscript identifier identifier else_clause block expression_statement assignment subscript attribute identifier identifier identifier identifier else_clause block expression_statement assignment subscript attribute identifier identifier identifier subscript identifier identifier
Load the user defined settings, overriding the defaults
def _check_retcode(cmd): return salt.modules.cmdmod.retcode(cmd, output_loglevel='quiet', ignore_retcode=True) == 0
module function_definition identifier parameters identifier block return_statement comparison_operator call attribute attribute attribute identifier identifier identifier identifier argument_list identifier keyword_argument identifier string string_start string_content string_end keyword_argument identifier true integer
Simple internal wrapper for cmdmod.retcode
def mock_cmd(self, release, *cmd, **kwargs): fmt = '{mock_cmd}' if kwargs.get('new_chroot') is True: fmt +=' --new-chroot' fmt += ' --configdir={mock_dir}' return self.call(fmt.format(**release).split() + list(cmd))
module function_definition identifier parameters identifier identifier list_splat_pattern identifier dictionary_splat_pattern identifier block expression_statement assignment identifier string string_start string_content string_end if_statement comparison_operator call attribute identifier identifier argument_list string string_start string_content string_end true block expression_statement augmented_assignment identifier string string_start string_content string_end expression_statement augmented_assignment identifier string string_start string_content string_end return_statement call attribute identifier identifier argument_list binary_operator call attribute call attribute identifier identifier argument_list dictionary_splat identifier identifier argument_list call identifier argument_list identifier
Run a mock command in the chroot for a given release
def to_dict(self): dyn_dict = {} for (key, val) in six.iteritems(self.__dict__): if key not in self._printable_exclude: dyn_dict[key] = val return dyn_dict
module function_definition identifier parameters identifier block expression_statement assignment identifier dictionary for_statement tuple_pattern identifier identifier call attribute identifier identifier argument_list attribute identifier identifier block if_statement comparison_operator identifier attribute identifier identifier block expression_statement assignment subscript identifier identifier identifier return_statement identifier
Converts dynstruct to a dictionary.
def open_as_pillow(filename): with __sys_open(filename, 'rb') as f: data = BytesIO(f.read()) return Image.open(data)
module function_definition identifier parameters identifier block with_statement with_clause with_item as_pattern call identifier argument_list identifier string string_start string_content string_end as_pattern_target identifier block expression_statement assignment identifier call identifier argument_list call attribute identifier identifier argument_list return_statement call attribute identifier identifier argument_list identifier
This way can delete file immediately
def _init_eval_iter(self, eval_data): if eval_data is None: return eval_data if isinstance(eval_data, (tuple, list)) and len(eval_data) == 2: if eval_data[0] is not None: if eval_data[1] is None and isinstance(eval_data[0], io.DataIter): return eval_data[0] input_data = (np.array(eval_data[0]) if isinstance(eval_data[0], list) else eval_data[0]) input_label = (np.array(eval_data[1]) if isinstance(eval_data[1], list) else eval_data[1]) return self._init_iter(input_data, input_label, is_train=True) else: raise ValueError("Eval data is NONE") if not isinstance(eval_data, io.DataIter): raise TypeError('Eval data must be DataIter, or ' \ 'NDArray/numpy.ndarray/list pair (i.e. tuple/list of length 2)') return eval_data
module function_definition identifier parameters identifier identifier block if_statement comparison_operator identifier none block return_statement identifier if_statement boolean_operator call identifier argument_list identifier tuple identifier identifier comparison_operator call identifier argument_list identifier integer block if_statement comparison_operator subscript identifier integer none block if_statement boolean_operator comparison_operator subscript identifier integer none call identifier argument_list subscript identifier integer attribute identifier identifier block return_statement subscript identifier integer expression_statement assignment identifier parenthesized_expression conditional_expression call attribute identifier identifier argument_list subscript identifier integer call identifier argument_list subscript identifier integer identifier subscript identifier integer expression_statement assignment identifier parenthesized_expression conditional_expression call attribute identifier identifier argument_list subscript identifier integer call identifier argument_list subscript identifier integer identifier subscript identifier integer return_statement call attribute identifier identifier argument_list identifier identifier keyword_argument identifier true else_clause block raise_statement call identifier argument_list string string_start string_content string_end if_statement not_operator call identifier argument_list identifier attribute identifier identifier block raise_statement call identifier argument_list concatenated_string string string_start string_content string_end string string_start string_content string_end return_statement identifier
Initialize the iterator given eval_data.
def _remap_fields(cls, kwargs): mapped = {} for key in kwargs: if key in cls._remap: mapped[cls._remap[key]] = kwargs[key] else: mapped[key] = kwargs[key] return mapped
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier dictionary for_statement identifier identifier block if_statement comparison_operator identifier attribute identifier identifier block expression_statement assignment subscript identifier subscript attribute identifier identifier identifier subscript identifier identifier else_clause block expression_statement assignment subscript identifier identifier subscript identifier identifier return_statement identifier
Map fields from kwargs into dict acceptable by NIOS
def prewalk_hook(self, dispatcher, node): self.walk(dispatcher, node) self.finalize() return node
module function_definition identifier parameters identifier identifier identifier block expression_statement call attribute identifier identifier argument_list identifier identifier expression_statement call attribute identifier identifier argument_list return_statement identifier
This is for the Unparser to use as a prewalk hook.
def tag_details(tag, nodenames): details = {} details['type'] = tag.name details['ordinal'] = tag_ordinal(tag) if tag_details_sibling_ordinal(tag): details['sibling_ordinal'] = tag_details_sibling_ordinal(tag) if tag_details_asset(tag): details['asset'] = tag_details_asset(tag) object_id_tag = first(raw_parser.object_id(tag, pub_id_type= "doi")) if object_id_tag: details['component_doi'] = extract_component_doi(tag, nodenames) return details
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier dictionary expression_statement assignment subscript identifier string string_start string_content string_end attribute identifier identifier expression_statement assignment subscript identifier string string_start string_content string_end call identifier argument_list identifier if_statement call identifier argument_list identifier block expression_statement assignment subscript identifier string string_start string_content string_end call identifier argument_list identifier if_statement call identifier argument_list identifier block expression_statement assignment subscript identifier string string_start string_content string_end call identifier argument_list identifier expression_statement assignment identifier call identifier argument_list call attribute identifier identifier argument_list identifier keyword_argument identifier string string_start string_content string_end if_statement identifier block expression_statement assignment subscript identifier string string_start string_content string_end call identifier argument_list identifier identifier return_statement identifier
Used in media and graphics to extract data from their parent tags
def do_shutdown (self): with self.mutex: unfinished = self.unfinished_tasks - len(self.queue) self.queue.clear() if unfinished <= 0: if unfinished < 0: raise ValueError('shutdown is in error') self.all_tasks_done.notifyAll() self.unfinished_tasks = unfinished self.shutdown = True
module function_definition identifier parameters identifier block with_statement with_clause with_item attribute identifier identifier block expression_statement assignment identifier binary_operator attribute identifier identifier call identifier argument_list attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list if_statement comparison_operator identifier integer block if_statement comparison_operator identifier integer block raise_statement call identifier argument_list string string_start string_content string_end expression_statement call attribute attribute identifier identifier identifier argument_list expression_statement assignment attribute identifier identifier identifier expression_statement assignment attribute identifier identifier true
Shutdown the queue by not accepting any more URLs.
def update_schema(self): self.commit() self.build_source_files.schema.objects_to_record() self.commit()
module function_definition identifier parameters identifier block expression_statement call attribute identifier identifier argument_list expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list expression_statement call attribute identifier identifier argument_list
Propagate schema object changes to file records
def end(self, *args): if self._is_verbose: return self if not args: self._indent -= 1 return self self.writeln('end', *args) self._indent -= 1 return self
module function_definition identifier parameters identifier list_splat_pattern identifier block if_statement attribute identifier identifier block return_statement identifier if_statement not_operator identifier block expression_statement augmented_assignment attribute identifier identifier integer return_statement identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end list_splat identifier expression_statement augmented_assignment attribute identifier identifier integer return_statement identifier
End a nested log.
def queryset(self, request, queryset): if self.form.is_valid(): filter_params = dict( filter(lambda x: bool(x[1]), self.form.cleaned_data.items()) ) return queryset.filter(**filter_params) return queryset
module function_definition identifier parameters identifier identifier identifier block if_statement call attribute attribute identifier identifier identifier argument_list block expression_statement assignment identifier call identifier argument_list call identifier argument_list lambda lambda_parameters identifier call identifier argument_list subscript identifier integer call attribute attribute attribute identifier identifier identifier identifier argument_list return_statement call attribute identifier identifier argument_list dictionary_splat identifier return_statement identifier
Filter queryset using params from the form.
def check_scrapers(): d = {} for scraperclass in _scraperclasses: name = scraperclass.getName().lower() if name in d: name1 = scraperclass.getName() name2 = d[name].getName() raise ValueError('duplicate scrapers %s and %s found' % (name1, name2)) d[name] = scraperclass
module function_definition identifier parameters block expression_statement assignment identifier dictionary for_statement identifier identifier block expression_statement assignment identifier call attribute call attribute identifier identifier argument_list identifier argument_list if_statement comparison_operator identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier call attribute subscript identifier identifier identifier argument_list raise_statement call identifier argument_list binary_operator string string_start string_content string_end tuple identifier identifier expression_statement assignment subscript identifier identifier identifier
Check for duplicate scraper class names.
def hash_data(obj): collect = sha1() for text in bytes_iter(obj): if isinstance(text, six.text_type): text = text.encode('utf-8') collect.update(text) return collect.hexdigest()
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list for_statement identifier call identifier argument_list identifier block if_statement call identifier argument_list identifier attribute identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier return_statement call attribute identifier identifier argument_list
Generate a SHA1 from a complex object.
def jx_type(column): if column.es_column.endswith(EXISTS_TYPE): return EXISTS return es_type_to_json_type[column.es_type]
module function_definition identifier parameters identifier block if_statement call attribute attribute identifier identifier identifier argument_list identifier block return_statement identifier return_statement subscript identifier attribute identifier identifier
return the jx_type for given column
def __convert_key(expression): if type(expression) is str and len(expression) > 2 and expression[1] == '!': expression = eval(expression[2:-1]) return expression
module function_definition identifier parameters identifier block if_statement boolean_operator boolean_operator comparison_operator call identifier argument_list identifier identifier comparison_operator call identifier argument_list identifier integer comparison_operator subscript identifier integer string string_start string_content string_end block expression_statement assignment identifier call identifier argument_list subscript identifier slice integer unary_operator integer return_statement identifier
Converts keys in YAML that reference other keys.