Python builtins.list() Examples
The following are 30
code examples of builtins.list().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
builtins
, or try the search function
.
Example #1
Source File: message.py From OrangeAssassin with Apache License 2.0 | 6 votes |
def _decode_header(header): """Decodes an email header and returns it as a string. Any parts of the header that cannot be decoded are simply ignored. """ parts = list() try: decoded_header = email.header.decode_header(header) except (ValueError, email.header.HeaderParseError): return for value, encoding in decoded_header: if encoding: try: parts.append(value.decode(encoding, "ignore")) except (LookupError, UnicodeError, AssertionError): continue else: try: parts.append(value.decode("utf-8", "ignore")) except AttributeError: parts.append(value) return "".join(parts)
Example #2
Source File: windbg.py From ida-minsc with BSD 3-Clause "New" or "Revised" License | 6 votes |
def tokenize(input, escapables={"'", '"', '\\'} | {item for item in string.whitespace} - {' '}): """Yield each token belonging to the windbg format in `input` that would need to be escaped using the specified `escapables`. If the set `escapables` is defined, then use it as the list of characters to tokenize. """ result, iterable = '', iter(input) try: while True: char = six.next(iterable) if operator.contains(escapables, char): if result: yield result yield char result = '' else: result += char continue except StopIteration: if result: yield result return return
Example #3
Source File: builtinslib.py From CrossHair with MIT License | 6 votes |
def __init__(self, space: StateSpace, typ: Type, smtvar: object): self.val_pytype = normalize_pytype(type_arg_of(typ, 1)) self.smt_val_sort = type_to_smt_sort(self.val_pytype) SmtDictOrSet.__init__(self, space, typ, smtvar) self.val_ch_type = crosshair_type_for_python_type(self.val_pytype) arr_var = self._arr() len_var = self._len() self.val_missing_checker = arr_var.sort().range().recognizer(0) self.val_missing_constructor = arr_var.sort().range().constructor(0) self.val_constructor = arr_var.sort().range().constructor(1) self.val_accessor = arr_var.sort().range().accessor(1, 0) self.empty = z3.K(arr_var.sort().domain(), self.val_missing_constructor()) self._iter_cache = [] space.add((arr_var == self.empty) == (len_var == 0)) def list_can_be_iterated(): list(self) return True space.defer_assumption('dict iteration is consistent with items', list_can_be_iterated)
Example #4
Source File: utils.py From ml-on-gcp with Apache License 2.0 | 6 votes |
def standardize(dataframe): """Scales numerical columns using their means and standard deviation to get z-scores: the mean of each numerical column becomes 0, and the standard deviation becomes 1. This can help the model converge during training. Args: dataframe: Pandas dataframe Returns: Input dataframe with the numerical columns scaled to z-scores """ dtypes = list(zip(dataframe.dtypes.index, map(str, dataframe.dtypes))) # Normalize numeric columns. for column, dtype in dtypes: if dtype == 'float32': dataframe[column] -= dataframe[column].mean() dataframe[column] /= dataframe[column].std() return dataframe
Example #5
Source File: message.py From OrangeAssassin with Apache License 2.0 | 5 votes |
def receive_date(self): """Get the date from the headers.""" received = self.msg.get_all("Received") or list() for header in received: try: ts = header.rsplit(";", 1)[1] except IndexError: continue ts = email.utils.parsedate(ts) return calendar.timegm(ts) # SA will look in other headers too. Perhaps we should also? return time.time()
Example #6
Source File: message.py From OrangeAssassin with Apache License 2.0 | 5 votes |
def normalize_html_part(payload): """Strip all HTML tags.""" data = list() stripper = _ParseHTML(data) try: stripper.feed(payload) except (UnicodeDecodeError, html.parser.HTMLParseError): # We can't parse the HTML, so just strip it. This is still # better than including generic HTML/CSS text. pass return data
Example #7
Source File: message.py From OrangeAssassin with Apache License 2.0 | 5 votes |
def get_raw_header(self, header_name): """Get a list of raw headers with this name.""" # This is just for consistencies, the raw headers should have been # parsed together with the message. return self.raw_headers.get(header_name, list())
Example #8
Source File: message.py From OrangeAssassin with Apache License 2.0 | 5 votes |
def get_decoded_header(self, header_name): """Get a list of decoded headers with this name.""" values = list() for value in self.get_raw_header(header_name): values.append(self._decode_header(value)) for value in self.get_headers(header_name): values.append(value) return values
Example #9
Source File: message.py From OrangeAssassin with Apache License 2.0 | 5 votes |
def get_untrusted_ips(self): """Returns the untrusted IPs based on the users trusted network settings. :return: A list of `ipaddress.ip_address`. """ ips = [ip for ip in self.get_header_ips() if ip not in self.ctxt.networks.trusted] return ips
Example #10
Source File: message.py From OrangeAssassin with Apache License 2.0 | 5 votes |
def get_header_ips(self): values = list() for header in self.received_headers: values.append(ipaddress.ip_address(header["ip"])) return values
Example #11
Source File: message.py From OrangeAssassin with Apache License 2.0 | 5 votes |
def get_addr_header(self, header_name): """Get a list of the first addresses from this header.""" values = list() for value in self.get_decoded_header(header_name): for dummy, addr in email.utils.getaddresses([value]): if addr: values.append(addr) break return values
Example #12
Source File: message.py From OrangeAssassin with Apache License 2.0 | 5 votes |
def get_all_addr_header(self, header_name): """Get a list of all the addresses from this header.""" values = list() for value in self.get_decoded_header(header_name): for dummy, addr in email.utils.getaddresses([value]): if addr: values.append(addr) return values
Example #13
Source File: message.py From OrangeAssassin with Apache License 2.0 | 5 votes |
def get_raw_mime_header(self, header_name): """Get a list of raw MIME headers with this name.""" # This is just for consistencies, the raw headers should have been # parsed together with the message. return self.raw_mime_headers.get(header_name, list())
Example #14
Source File: message.py From OrangeAssassin with Apache License 2.0 | 5 votes |
def get_decoded_mime_header(self, header_name): """Get a list of raw MIME headers with this name.""" values = list() for value in self.get_raw_mime_header(header_name): values.append(self._decode_header(value)) return values
Example #15
Source File: message.py From OrangeAssassin with Apache License 2.0 | 5 votes |
def __init__(self, global_context, raw_msg): """Parse the message, extracts and decode all headers and all text parts. """ self.missing_boundary_header = False self.missing_header_body_separator = False super(Message, self).__init__(global_context) self.raw_msg = self.translate_line_breaks(raw_msg) self.msg = email.message_from_string(self.raw_msg) self.headers = _Headers() self.raw_headers = _Headers() self.addr_headers = _Headers() self.name_headers = _Headers() self.mime_headers = _Headers() self.received_headers = list() self.raw_mime_headers = _Headers() self.header_ips = _Headers() self.text = "" self.raw_text = "" self.uri_list = set() self.score = 0 self.rules_checked = dict() self.interpolate_data = dict() self.rules_descriptions = dict() self.plugin_tags = dict() # Data self.sender_address = "" self.hostname_with_ip = list() self.internal_relays = [] self.external_relays = [] self.last_internal_relay_index = 0 self.last_trusted_relay_index = 0 self.trusted_relays = [] self.untrusted_relays = [] self._parse_message() self._hook_parsed_metadata()
Example #16
Source File: base.py From OrangeAssassin with Apache License 2.0 | 5 votes |
def get_rule_kwargs(data): """Extract the keyword arguments necessary to create a new instance for this class. """ kwargs = dict() try: kwargs["score"] = list(map(float, data["score"].strip().split())) except KeyError: pass try: kwargs["desc"] = data["describe"].strip() except KeyError: pass try: kwargs["priority"] = data["priority"].strip() except KeyError: pass try: if data["tflags"]: kwargs["tflags"] = [] for flag in data["tflags"]: kwargs["tflags"].append(flag.strip()) except KeyError: pass return kwargs
Example #17
Source File: errors.py From OrangeAssassin with Apache License 2.0 | 5 votes |
def __init__(self): ParsingError.__init__(self) self._recursion_list = list()
Example #18
Source File: errors.py From OrangeAssassin with Apache License 2.0 | 5 votes |
def recursion_list(self): """Return the recursion list as a list of tuples: (filename, line number, line) """ return self._recursion_list
Example #19
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def _func_getargvalues(*args, **kwargs): return list(args), kwargs
Example #20
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def _process_arguments(self, args, keywords): kwdict = dict(keywords) argdict = {} nargs = min(len(args), len(self._argnames)) for iarg in range(nargs): argdict[self._argnames[iarg]] = args[iarg] if nargs < len(args): if self._varpos is None: msg = "macro '{0}' called with too many positional arguments "\ "(expected: {1}, received: {2})"\ .format(self._name, len(self._argnames), len(args)) raise FyppFatalError(msg, self._fname, self._spans[0]) else: argdict[self._varpos] = list(args[nargs:]) elif self._varpos is not None: argdict[self._varpos] = [] for argname in self._argnames[:nargs]: if argname in kwdict: msg = "got multiple values for argument '{0}'".format(argname) raise FyppFatalError(msg, self._fname, self._spans[0]) if nargs < len(self._argnames): for argname in self._argnames[nargs:]: if argname in kwdict: argdict[argname] = kwdict.pop(argname) elif argname in self._defaults: argdict[argname] = self._defaults[argname] else: msg = "macro '{0}' called without mandatory positional "\ "argument '{1}'".format(self._name, argname) raise FyppFatalError(msg, self._fname, self._spans[0]) if kwdict and self._varkw is None: kwstr = "', '".join(kwdict.keys()) msg = "macro '{0}' called with unknown keyword argument(s) '{1}'"\ .format(self._name, kwstr) raise FyppFatalError(msg, self._fname, self._spans[0]) if self._varkw is not None: argdict[self._varkw] = kwdict return argdict
Example #21
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def _get_syspath_without_scriptdir(): '''Remove the folder of the fypp binary from the search path''' syspath = list(sys.path) scriptdir = os.path.abspath(os.path.dirname(sys.argv[0])) if os.path.abspath(syspath[0]) == scriptdir: del syspath[0] return syspath
Example #22
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def __call__(self, line): '''Folds a line. Can be directly called to return the list of folded lines:: linefolder = FortranLineFolder(maxlen=10) linefolder(' print *, "some Fortran line"') Args: line (str): Line to fold. Returns: list of str: Components of folded line. They should be assembled via ``\\n.join()`` to obtain the string representation. ''' if self._maxlen < 0 or len(line) <= self._maxlen: return [line] if self._inherit_indent: indent = len(line) - len(line.lstrip()) prefix = ' ' * indent + self._prefix else: indent = 0 prefix = self._prefix suffix = self._suffix return self._split_line(line, self._maxlen, prefix, suffix, self._fold_position_finder)
Example #23
Source File: fypp.py From fypp with BSD 2-Clause "Simplified" License | 5 votes |
def __call__(self, line): '''Returns the entire line without any folding. Returns: list of str: Components of folded line. They should be assembled via ``\\n.join()`` to obtain the string representation. ''' return [line]
Example #24
Source File: tags.py From ida-minsc with BSD 3-Clause "New" or "Revised" License | 5 votes |
def list(): '''Return the tags for the all of the function contents within the database as a set.''' return {res for res in itertools.chain(*(res for _, res in db.selectcontents()))} ### internal utility functions and classes
Example #25
Source File: tags.py From ida-minsc with BSD 3-Clause "New" or "Revised" License | 5 votes |
def addressToLocation(ea, chunks=None): """Convert the address `ea` to a `(function, id, offset)`. The fields `id` and `offset` represent the chunk index and the offset into the chunk for the function at `ea`. If the list `chunks` is specified as a parameter, then use it as a tuple of ranges in order to calculate the correct address. """ F, chunks = func.by(ea), chunks or [ch for ch in func.chunks(ea)] cid, base = next((i, l) for i, (l, r) in enumerate(chunks) if l <= ea < r) return func.top(F), cid, ea - base
Example #26
Source File: tags.py From ida-minsc with BSD 3-Clause "New" or "Revised" License | 5 votes |
def update_navigation(xs, setter): '''Call `setter` on ea for each iteration of list `xs`.''' for x in xs: ea, _ = x setter(ea) yield x return ## convert a sorted list keyed by a location into something that updates ida's navigation pointer
Example #27
Source File: message.py From OrangeAssassin with Apache License 2.0 | 5 votes |
def __init__(self): collections.defaultdict.__init__(self, list)
Example #28
Source File: plugin.py From pytest-nodev with MIT License | 5 votes |
def pytest_addoption(parser): group = parser.getgroup('nodev') group.addoption( '--candidates-from-stdlib', action='store_true', help="Collects candidates form the Python standard library.") group.addoption( '--candidates-from-all', action='store_true', help="Collects candidates form the Python standard library and all installed packages. " "Disabled by default, see the docs.") group.addoption( '--candidates-from-specs', default=[], nargs='+', help="Collects candidates from installed packages. Space separated list of `pip` specs.") group.addoption( '--candidates-from-modules', default=[], nargs='+', help="Collects candidates from installed modules. Space separated list of module names.") group.addoption( '--candidates-includes', nargs='+', help="Space separated list of regexs matching full object names to include, " "defaults to include all objects collected via `--candidates-from-*`.") group.addoption( '--candidates-excludes', default=[], nargs='+', help="Space separated list of regexs matching full object names to exclude.") group.addoption( '--candidates-predicate', default='builtins:callable', help="Full name of the predicate passed to `inspect.getmembers`, " "defaults to `builtins.callable`.") group.addoption('--candidates-fail', action='store_true', help="Show candidates failures.")
Example #29
Source File: plugin.py From pytest-nodev with MIT License | 5 votes |
def pytest_pycollect_makeitem(collector, name, obj): candidate_marker = getattr(obj, 'candidate', None) if candidate_marker and getattr(candidate_marker, 'args', []): candidate_name = candidate_marker.args[0] def wrapper(candidate, monkeypatch, *args, **kwargs): if '.' in candidate_name: monkeypatch.setattr(candidate_name, candidate, raising=False) else: monkeypatch.setattr(inspect.getmodule(obj), candidate_name, candidate, raising=False) return obj(*args, **kwargs) wrapper.__dict__ = obj.__dict__ return list(collector._genfunctions(name, wrapper))
Example #30
Source File: test_collect.py From pytest-nodev with MIT License | 5 votes |
def test_collect_stdlib_distributions(): stdlib_distributions = list(collect.collect_stdlib_distributions()) assert len(stdlib_distributions) == 1 _, module_names = stdlib_distributions[0] assert len(module_names) > 10