code
stringlengths
52
7.75k
docs
stringlengths
1
5.85k
def add_attr2fields(self, attr_name, attr_val, fields=[], exclude=[], include_all_if_empty=True): for f in self.filter_fields(fields, exclude, include_all_if_empty): f = self.fields[f.name] org_val = f.widget.attrs.get(attr_name, '') f.widget.attrs[attr_name] = '%s %...
add attr to fields
def add_class2fields(self, html_class, fields=[], exclude=[], include_all_if_empty=True): self.add_attr2fields('class', html_class, fields, exclude)
add class to html widgets.
def filter_fields(self, fields=[], exclude=[], include_all_if_empty=True): if not include_all_if_empty and not fields: return [] ret = [] for f in self.visible_fields(): if fields and f.name not in fields: continue if exclude and f.nam...
filter fields fields: exclude: include_all_if_empty: if fields is empty return all fields return: fileds
def as_required_fields(self, fields=[]): fields = self.filter_fields(fields) for f in fields: f = self.fields[f.name] f.required = True
set required to True
def check_uniqe(self, obj_class, error_msg=_('Must be unique'), **kwargs): if obj_class.objects.filter(**kwargs).exclude(pk=self.instance.pk): raise forms.ValidationError(error_msg)
check if this object is unique
def get_info(pyfile): '''Retrieve dunder values from a pyfile''' info = {} info_re = re.compile(r"^__(\w+)__ = ['\"](.*)['\"]") with open(pyfile, 'r') as f: for line in f.readlines(): match = info_re.search(line) if match: info[match.group(1)] = match.grou...
Retrieve dunder values from a pyfile
def main(): args = parse_args() config_logger(args) logger = structlog.get_logger(__name__) if args.show_version: # only print the version print_version() sys.exit(0) version = pkg_resources.get_distribution('lander').version logger.info('Lander version {0}'.format...
Entrypoint for ``lander`` executable.
def insert_node(self, node): if self._is_node_reserved(node): return False # Put node in map self._node_map[node.get_id()] = node return True
Adds node if name is available or pre-existing node returns True if added returns False if not added
def merge(self, subordinate_graph): if not isinstance(subordinate_graph, Graph): raise Exception("Graph is expected to only merge with a Graph.") subordinate_nodes = subordinate_graph.get_nodes() merge_results = [] for node_id in subordinate_nodes: node...
merge rules: 00 + 00 == 00 00 + 0B == 0B 0A + 00 == 0A 0A + 0B == 0A A0 + 00 == A0 A0 + 0B == AB AA + 00 == AA AA + 0B == AB 00 + B0 == B0 00 + BB == BB 0A + B0 == BA 0A + BB == BA A0 + B0 == A0 A0 + BB == AB AA + B0 == AA AA + BB ...
def join(self, distbase, location): sep = '' if distbase and distbase[-1] not in (':', '/'): sep = '/' return distbase + sep + location
Join 'distbase' and 'location' in such way that the result is a valid scp destination.
def get_location(self, location, depth=0): if not location: return [] if location in self.aliases: res = [] if depth > MAXALIASDEPTH: err_exit('Maximum alias depth exceeded: %(location)s' % locals()) for loc in self.aliases[locatio...
Resolve aliases and apply distbase.
def get_default_location(self): res = [] for location in self.distdefault: res.extend(self.get_location(location)) return res
Return the default location.
def check_empty_locations(self, locations=None): if locations is None: locations = self.locations if not locations: err_exit('mkrelease: option -d is required\n%s' % USAGE)
Fail if 'locations' is empty.
def check_valid_locations(self, locations=None): if locations is None: locations = self.locations for location in locations: if (not self.is_server(location) and not self.is_ssh_url(location) and not self.has_host(location)): ...
Fail if 'locations' contains bad destinations.
def set_defaults(self, config_file): self.defaults = Defaults(config_file) self.locations = Locations(self.defaults) self.python = Python() self.setuptools = Setuptools() self.scp = SCP() self.scms = SCMFactory() self.urlparser = URLParser() self....
Set defaults.
def list_locations(self): known = self.defaults.get_known_locations() for default in self.defaults.distdefault: if default not in known: known.add(default) if not known: err_exit('No locations', 0) for location in sorted(known): ...
Print known dist-locations and exit.
def get_skipregister(self, location=None): if location is None: return self.skipregister or not self.defaults.register else: server = self.defaults.servers[location] if self.skipregister: return True elif server.register is not Non...
Return true if the register command is disabled (for the given server.)
def get_uploadflags(self, location): uploadflags = [] server = self.defaults.servers[location] if self.sign: uploadflags.append('--sign') elif server.sign is not None: if server.sign: uploadflags.append('--sign') elif self.default...
Return uploadflags for the given server.
def get_options(self): args = self.parse_options(self.args) if args: self.directory = args[0] if self.develop: self.skiptag = True if not self.develop: self.develop = self.defaults.develop if not self.develop: self.infofl...
Process the command line.
def get_package(self): directory = self.directory develop = self.develop scmtype = self.scmtype self.scm = self.scms.get_scm(scmtype, directory) if self.scm.is_valid_url(directory): directory = self.urlparser.abspath(directory) self.remoteurl =...
Get the URL or sandbox to release.
def configure_gateway( cls, launch_jvm: bool = True, gateway: Union[GatewayParameters, Dict[str, Any]] = None, callback_server: Union[CallbackServerParameters, Dict[str, Any]] = False, javaopts: Iterable[str] = (), classpath: Iterable[str] = ''): assert c...
Configure a Py4J gateway. :param launch_jvm: ``True`` to spawn a Java Virtual Machine in a subprocess and connect to it, ``False`` to connect to an existing Py4J enabled JVM :param gateway: either a :class:`~py4j.java_gateway.GatewayParameters` object or a dictionary of keyword ...
def load(self, filename, offset): self.offset = offset self.filename = filename self.bootsector = BootSector( filename=filename, length=NTFS_BOOTSECTOR_SIZE, offset=self.offset) self.mft_table = MftTable( mft_entry_size=self.boot...
Loads NTFS volume information Args: filename (str): Path to file/device to read the volume \ information from. offset (uint): Valid NTFS partition offset from the beginning \ of the file/device. Raises: IOError: If source file/device does not...
def _get_mft_zone_size(self, num_clusters, mft_zone_multiplier=1): sizes = { 4: num_clusters >> 1, # 50% 3: (num_clusters * 3) >> 3, # 37,5% 2: num_clusters >> 2, # 25% } return sizes.get(mft_zone_multiplier, num_clusters >> ...
Returns mft zone size in clusters. From ntfs_progs.1.22.
def artist(self): if not self._artist: self._artist = Artist(self._artist_id, self._artist_name, self._connection) return self._artist
:class:`Artist` object of album's artist
def cover(self): if not self._cover: self._cover = Picture(self._cover_url, self._connection) return self._cover
album cover as :class:`Picture` object
def export(self): return {'id' : self.id, 'name' : self.name, 'artist' : self._artist_name, 'artist_id' : self._artist_id, 'cover' : self._cover_url}
Returns a dictionary with all album information. Use the :meth:`from_export` method to recreate the :class:`Album` object.
def close(self): if hasattr(self, 'iterators'): for it in self.iterators: if hasattr(it, 'close'): it.close()
Closes all the iterators. This is particularly important if the iterators are files.
def _update_sorting(self): key = self.key sorted_tops = self.sorted_tops tops = self.tops iterators = self.iterators for idx in self.idxs: try: tops[idx] = next(iterators[idx]) top_key = key(tops[idx]) if top_ke...
Insert new entries into the merged iterator. :param sorted_tops: A SortedDict. :param tops: The most recent entry from each iterator. :param idxs: The indices to update.
def parse(raw_email): # type: (six.string_types) -> Tuple[six.string_types, six.string_types] if not isinstance(raw_email, six.string_types): raise InvalidEmail("Invalid email: %s" % raw_email) if not raw_email or pd.isnull(raw_email): raise InvalidEmail("None or NaN is not a valid emai...
Extract email from a full address. Example: 'John Doe <jdoe+github@foo.com>' -> jdoe@foo.com >>> parse("John Doe <me+github.com@someorg.com") ('me', 'someorg.com') >>> parse(42) # doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... InvalidEmail: 'Invalid email: 4...
def university_domains(): # type: () -> set fpath = os.path.join( os.path.dirname(__file__), "email_university_domains.csv") with open(fpath) as fh: return set(addr_domain.strip() for addr_domain in fh)
Return list of university domains outside of .edu TLD NOTE: only 2nd level domain is returned, i.e. for aaa.bbb.uk only bbbl.uk will be returned. This is necessary since many universities use departmenntal domains, like cs.cmu.edu or andrew.cmu.edu NOTE2: .edu domains are not included into t...
def domain_user_stats(): # type: () -> pd.Series fname = os.path.join(os.path.dirname(__file__), "email_domain_users.csv") stats = pd.read_csv(fname, header=0, squeeze=True, index_col=0) return stats[pd.notnull(stats.index)]
Get number of distinct email addresses in observed domains TODO: get up to date with new projects layout How to build email_domain_users.csv: from collections import defaultdict import logging from common import utils as common import stscraper as scraper log = logging.getLogger("domain_u...
def commercial_domains(): # type: () -> set dus = domain_user_stats() es = "test@" + pd.Series(dus.index, index=dus.index) return set( dus[~is_public_bulk(es) & ~is_university_bulk(es) & (dus > 1)].index)
Return list of commercial email domains, which means: - domain is not public - domain is not university - it is not personal (more than 1 person using this domain) >>> "google.com" in commercial_domains() True >>> "microsoft.com" in commercial_domains() True >>> "isri.cs.cmu.edu" in comm...
def is_university(addr): # type: (Union[str, unicode]) -> bool addr_domain = domain(addr) if not addr_domain: # invalid email return False chunks = addr_domain.split(".") if len(chunks) < 2: # local or invalid address return False domains = university_domains() # many...
Check if provided email has a university domain - either in .edu domain (except public sercices like england.edu or australia.edu) - or in .edu.TLD (non-US based institutions, like edu.au) - or listed in a public list of universities since universities often have department addresses as wel...
def is_public(addr): # type: (Union[str, unicode]) -> bool addr_domain = domain(addr) if not addr_domain: # anybody can use invalid email return True chunks = addr_domain.rsplit(".", 1) return len(chunks) < 2 \ or addr_domain.endswith("local") \ or addr_domain i...
Check if the passed email registered at a free pubic mail server :param addr: email address to check :return: bool >>> is_public("john@cmu.edu") False >>> is_public("john@gmail.com") True
def pos(self, x=None, y=None): u'''Move or query the window cursor.''' if x is not None: System.Console.CursorLeft=x else: x = System.Console.CursorLeft if y is not None: System.Console.CursorTop=y else: y = System.Console....
u'''Move or query the window cursor.
def write_plain(self, text, attr=None): u'''write text at current cursor position.''' log(u'write("%s", %s)' %(text, attr)) if attr is None: attr = self.attr n = c_int(0) self.SetConsoleTextAttribute(self.hout, attr) self.WriteConsoleA(self.hout, text, ...
u'''write text at current cursor position.
def text(self, x, y, text, attr=None): u'''Write text at the given position.''' self.pos(x, y) self.write_color(text, attrf text(self, x, y, text, attr=None): u'''Write text at the given position.''' self.pos(x, y) self.write_color(text, attr)
u'''Write text at the given position.
def rectangle(self, rect, attr=None, fill=u' '): u'''Fill Rectangle.''' oldtop = self.WindowTop oldpos = self.pos() #raise NotImplementedError x0, y0, x1, y1 = rect if attr is None: attr = self.attr if fill: rowfill = fill[:1] * ab...
u'''Fill Rectangle.
def scroll_window(self, lines): u'''Scroll the window by the indicated number of lines.''' top = self.WindowTop + lines if top < 0: top = 0 if top + System.Console.WindowHeight > System.Console.BufferHeight: top = System.Console.BufferHeight self.Wi...
u'''Scroll the window by the indicated number of lines.
def getkeypress(self): u'''Return next key press event from the queue, ignoring others.''' ck = System.ConsoleKey while 1: e = System.Console.ReadKey(True) if e.Key == System.ConsoleKey.PageDown: #PageDown self.scroll_window(12) elif e.K...
u'''Return next key press event from the queue, ignoring others.
def title(self, txt=None): u'''Set/get title.''' if txt: System.Console.Title = txt else: return System.Console.Titlf title(self, txt=None): u'''Set/get title.''' if txt: System.Console.Title = txt else: return Sys...
u'''Set/get title.
def size(self, width=None, height=None): u'''Set/get window size.''' sc = System.Console if width is not None and height is not None: sc.BufferWidth, sc.BufferHeight = width,height else: return sc.BufferWidth, sc.BufferHeight if width is not None ...
u'''Set/get window size.
def files(self): if self._files is None: self._files = SeriesZipTifHolo._index_files(self.path) return self._files
List of hologram data file names in the input zip file
def get_time(self, idx): # first try to get the time from the TIFF file # (possible meta data keywords) ds = self._get_dataset(idx) thetime = ds.get_time() if np.isnan(thetime): # use zipfile date_time zf = zipfile.ZipFile(self.path) i...
Time for each TIFF file If there are no metadata keyword arguments defined for the TIFF file format, then the zip file `date_time` value is used.
def set_user_variable(input_dict, environment_dict): # Iterates through the dictionary to retrieve the variable name command_key = input_dict.keys()[0] while input_dict[command_key]['name'] is not 'variable_name': input_dict = input_dict[command_key]['children'] variable_name = command_key = input_dict...
<Purpose> Seash callback to allow user to define a custom variable and assign a value to it. <Arguments> input_dict: Input dictionary generated by seash_dictionary.parse_command(). environment_dict: Dictionary describing the current seash environment. For more information, see command_callbac...
def show_user_variables(input_dict, environment_dict): for variable, value in uservariables.iteritems(): print variable+": '"+value+"'"
<Purpose> Seash callback to allow user to check all variables that they defined. <Arguments> input_dict: Input dictionary generated by seash_dictionary.parse_command(). environment_dict: Dictionary describing the current seash environment. For more information, see command_callbacks.py's module d...
def autocomplete(input_list): # We are only interested if the last token starts with a single '$' # Double $$'s indicate that it is meant to be a '$', so we don't do anything. if input_list[-1].startswith('$') and not input_list[-1].startswith('$$'): # Omit the '$' partial_variable = input_list[-1][1:]...
<Purpose> Returns all valid input completions for the specified command line input. <Arguments> input_list: A list of tokens. <Side Effects> None <Exceptions> None <Returns> A list of strings representing valid completions.
def need_data(self, i): # If we are not caching, we always grab data from the raw source if self.caching is False: return False logger.debug("Checking cache for data availability at %s." % self.part.location.logstring()) try: # Tell the DataController ...
Method to test if cache contains the data that the particle needs
def linterp(self, setx, sety, x): if math.isnan(sety[0]) or math.isnan(setx[0]): return np.nan #if math.isnan(sety[0]): # sety[0] = 0. #if math.isnan(sety[1]): # sety[1] = 0. return sety[0] + (x - setx[0]) * ( (sety[1]-sety[0]) / (setx[1]-setx[0...
Linear interp of model data values between time steps
def get_buildfile_path(settings): base = os.path.basename(settings.build_url) return os.path.join(BUILDS_ROOT, base)
Path to which a build tarball should be downloaded.
def prior_dates(*args, **kwargs): try: chron = args[0] except IndexError: chron = kwargs['coredates'] d_r = np.array(kwargs['d_r']) d_std = np.array(kwargs['d_std']) t_a = np.array(kwargs['t_a']) t_b = np.array(kwargs['t_b']) try...
Get the prior distribution of calibrated radiocarbon dates
def prior_sediment_rate(*args, **kwargs): # PlotAccPrior @ Bacon.R ln 113 -> ln 1097-1115 # alpha = acc_shape, beta = acc_shape / acc_mean # TODO(brews): Check that these stats are correctly translated to scipy.stats distribs. acc_mean = kwargs['acc_mean'] acc_shape = kw...
Get the prior density of sediment rates Returns ------- y : ndarray Array giving the density. x : ndarray Array of sediment accumulation values (yr/cm) over which the density was evaluated.
def prior_sediment_memory(*args, **kwargs): # "plot the prior for the memory (= accumulation rate varibility between neighbouring depths)" # PlotMemPrior @ Bacon.R ln 114 -> ln 1119 - 1141 # w_a = mem_strength * mem_mean, w_b = mem_strength * (1 - mem_mean) # TODO(brews): Check ...
Get the prior density of sediment memory Returns ------- y : ndarray Array giving the density. x : ndarray Array of Memory (ratio) values over which the density was evaluated.
def _init_browser(self): self.browser = splinter.Browser('phantomjs') self.browser.visit(self.server_url) self.browser.find_link_by_partial_text("Sign in").click() self.browser.fill( 'ctl00$ctl00$NICEMasterPageBodyContent$SiteContentPlaceholder$' 'txtForm...
Update this everytime the CERN SSO login form is refactored.
def album(self): if not self._album: self._album = Album(self._album_id, self._album_name, self._artist_id, self._artist_name, self._cover_url, self._connection) return self._album
album as :class:`Album` object
def stream(self): # Add song to queue self._connection.request( 'addSongsToQueue', {'songIDsArtistIDs': [{'artistID': self.artist.id, 'source': 'user', 'songID': self.id, ...
:class:`Stream` object for playing
def export(self): return {'id': self.id, 'name': self.name, 'artist': self._artist_name, 'artist_id': self._artist_id, 'album': self._album_name, 'album_id': self._album_id, 'track': self.track, 'duration': self.duration, 'popularity': self.popularity, ...
Returns a dictionary with all song information. Use the :meth:`from_export` method to recreate the :class:`Song` object.
def format(self, pattern): pattern = pattern.replace('%a', self.artist.name) pattern = pattern.replace('%s', self.name) pattern = pattern.replace('%A', self.album.name) return pattern.replace('/', '') \ .replace('\\', '') \ .replace(":...
Format the song according to certain patterns: %a: artist title %s: song title %A: album title
def download(self, directory='~/Music', song_name='%a - %s - %A'): formatted = self.format(song_name) path = os.path.expanduser(directory) + os.path.sep + formatted + '.mp3' try: raw = self.safe_download() with open(path, 'wb') as f: f.write(raw) ...
Download a song to a directory. :param directory: A system file path. :param song_name: A name that will be formatted with :meth:`format`. :return: The formatted song name.
def safe_download(self): def _markStreamKeyOver30Seconds(stream): self._connection.request( 'markStreamKeyOver30Seconds', {'streamServerID': stream.ip, 'artistID': self.artist.id, 'songQueueID': self._connection.session.queue...
Download a song respecting Grooveshark's API. :return: The raw song data.
def copy(self): return self.__class__(options=self.__options, attribute_options=self.__attribute_options)
Return a copy of this configuration.
def get_option(self, name): self.__validate_option_name(name) return self.__options.get(name, None)
Returns the value for the specified generic configuration option. :returns: configuration option value or `None`, if the option was not set.
def set_option(self, name, value): self.__validate_option_name(name) self.__options[name] = value
Sets the specified generic configuration option to the given value.
def set_attribute_option(self, attribute, option_name, option_value): self.__validate_attribute_option_name(option_name) attribute_key = self.__make_key(attribute) mp_options = self.__attribute_options.setdefault(attribute_key, {}) mp_options[option_name] = option_value
Sets the given attribute option to the given value for the specified attribute.
def get_attribute_option(self, attribute, option_name): self.__validate_attribute_option_name(option_name) attribute_key = self.__make_key(attribute) return self.__attribute_options[attribute_key].get(option_name)
Returns the value of the given attribute option for the specified attribute.
def get_attribute_options(self, attribute=None): attribute_key = self.__make_key(attribute) if attribute_key is None: opts = defaultdict(self._default_attributes_options.copy) for attr, mp_options in iteritems_(self.__attribute_options): opts[attr].update...
Returns a copy of the mapping options for the given attribute name or a copy of all mapping options, if no attribute name is provided. All options that were not explicitly configured are given a default value of `None`. :param tuple attribute_key: attribute name or tuple specifying an ...
def run(self, visitor): attr_option_map = self.__config.get_attribute_options() # Sorting the keys results in a depth-first traversal, which is just # what we want. for (key, key_attr_option_map) in sorted(iteritems_(attr_option_map)): if not self.__max_depth is None...
Traverses this representer configuration traverser with the given visitor. :param visitor: :class:`RepresenterConfigVisitorBase` instance.
def with_retry(cls, methods): retry_with_backoff = retry( retry_on_exception=lambda e: isinstance(e, BotoServerError), wait_exponential_multiplier=1000, wait_exponential_max=10000 ) for method in methods: m = getattr(cls, method, None) if isinstance(m, collection...
Wraps the given list of methods in a class with an exponential-back retry mechanism.
def string(value) -> str: return system_json.dumps(Json(value).safe_object(), ensure_ascii=False)
string dict/object/value to JSON
def parse(string, is_file=False, obj=False): try: if obj is False: if is_file: return system_json.load(string) return system_json.loads(string, encoding='utf8') else: if is_file: ret...
Convert a JSON string to dict/object
def from_file(file_path) -> dict: with io.open(file_path, 'r', encoding='utf-8') as json_stream: return Json.parse(json_stream, True)
Load JSON file
def safe_values(self, value): # TODO: override-able? string_val = "" if isinstance(value, datetime.date): try: string_val = value.strftime('{0}{1}{2}'.format( current_app.config['DATETIME']['DATE_FORMAT'], curre...
Parse non-string values that will not serialize
def camel_case(self, snake_case): components = snake_case.split('_') return components[0] + "".join(x.title() for x in components[1:])
Convert snake case to camel case
def __find_object_children(self, obj) -> dict: if hasattr(obj, 'items') and \ isinstance(obj.items, types.BuiltinFunctionType): return self.__construct_object(obj) elif isinstance(obj, (list, tuple, set)): return self.__construct_list(obj) ...
Convert object to flattened object
def __construct_list(self, list_value): array = [] for value in list_value: array.append(self.__iterate_value(value)) return array
Loop list/set/tuple and parse values
def __construct_object(self, obj, exclude_list=[]): new_obj = {} for key, value in obj.items(): if str(key).startswith('_') or \ key is 'json_exclude_list' or key in exclude_list: continue new_obj[self.camel_case(key)] = self.__...
Loop dict/class object and parse values
def __iterate_value(self, value): if hasattr(value, '__dict__') or isinstance(value, dict): return self.__find_object_children(value) # go through dict/class elif isinstance(value, (list, tuple, set)): return self.__construct_list(value) # go through list ...
Return value for JSON serialization
def parse_xml(self, key_xml): ''' Parse a VocabularyKey from an Xml as per Healthvault schema. :param key_xml: lxml.etree.Element representing a single VocabularyKey ''' xmlutils = XmlUtils(key_xml) self.name = xmlutils.get_string_by_xpath('name') ...
Parse a VocabularyKey from an Xml as per Healthvault schema. :param key_xml: lxml.etree.Element representing a single VocabularyKey
def print_and_exit(results): for success, value in results: if success: print value.encode(locale.getpreferredencoding()) else: value.printTraceback()
Print each result and stop the reactor.
def main(reactor): parser = argparse.ArgumentParser( description='Fetch a URI or series of URIs and print a title ' 'or summary for each.', epilog='If no URIs are passed on the command line, they are ' 'read from standard input, one per line.') parser.add_...
Main command line entry point.
def _topological_sort(self): sorted_graph = [] node_map = self._graph.get_nodes() nodes = [NodeVisitor(node_map[node]) for node in node_map] def get_pointers_for_edge_nodes(visitor_decorated_node): edges = [] edge_ids = visitor_decorated_node.get_node()...
Kahn's algorithm for Topological Sorting - Finds cycles in graph - Computes dependency weight
def __math(self, f, x): d = {} #operation with single number if isinstance(x, (int, long, float, complex)): for i in self.d: d[i] = f(self.d[i], x) return d #operation with other view (must have same size and partitions as self) or Field from same mesh a...
operator function :param f: operator.add/sub/mul... used operator :param x: other object view should be add/sub... with (other View, number, numpy.ndarray, Field) :return: dictionary (same shape as field.d) with result of operation
def add(self, x, axis): return self.__array_op(operator.add, x, axis)
Function to add 3D View with vector or 2D array (type = numpy.ndarray or 2D Field or 2D View) or 2D View with vector (type = numpy.ndarray) :param x: array(1D, 2D) or field (2D) or View(2D) :param axis: specifies axis, eg. axis = (1,2) plane lies in yz-plane, axis=0 vector along x axis :return: ...
def sub(self, x, axis): return self.__array_op(operator.sub, x, axis)
Function to sub 3D View with vector or 2D array (type = numpy.ndarray or 2D Field or 2D View) or 2D View with vector (type = numpy.ndarray) :param x: array(1D, 2D) or field (2D) or View(2D) :param axis: specifies axis, eg. axis = (1,2) plane lies in yz-plane, axis=0 vector along x axis :return: ...
def mul(self, x, axis): return self.__array_op(operator.mul, x, axis)
Function to multiply 3D View with vector or 2D array (type = numpy.ndarray or 2D Field or 2D View) or 2D View with vector (type = numpy.ndarray) :param x: array(1D, 2D) or field (2D) or View(2D) :param axis: specifies axis, eg. axis = (1,2) plane lies in yz-plane, axis=0 vector along x axis :ret...
def div(self, x, axis): return self.__array_op(operator.div, x, axis)
Function to divide 3D View by vector or 2D array (type = numpy.ndarray or 2D Field or 2D View) or 2D View with vector (type = numpy.ndarray) :param x: array(1D, 2D) or field (2D) or View(2D) :param axis: specifies axis, eg. axis = (1,2) plane lies in yz-plane, axis=0 vector along x axis :return:...
def mod(self, x, axis): return self.__array_op(operator.mod, x, axis)
Function to modulo 3D View with vector or 2D array (type = numpy.ndarray or 2D Field or 2D View) or 2D View with vector (type = numpy.ndarray) :param x: array(1D, 2D) or field (2D) or View(2D) :param axis: specifies axis, eg. axis = (1,2) plane lies in yz-plane, axis=0 vector along x axis :retur...
def pow(self, x, axis): return self.__array_op(operator.pow, x, axis)
Function to power 3D View with vector or 2D array (type = numpy.ndarray or 2D Field or 2D View) or 2D View with vector (type = numpy.ndarray) :param x: array(1D, 2D) or field (2D) or View(2D) :param axis: specifies axis, eg. axis = (1,2) plane lies in yz-plane, axis=0 vector along x axis :return...
def load_environment_vars(self): for k, v in os.environ.items(): if k.startswith(MACH9_PREFIX): _, config_key = k.split(MACH9_PREFIX, 1) self[config_key] = v
Looks for any MACH9_ prefixed environment variables and applies them to the configuration if present.
def copy(self, parent=None): new = Structure(None, parent=parent) new.key = self.key new.type_ = self.type_ new.val_guaranteed = self.val_guaranteed new.key_guaranteed = self.key_guaranteed for child in self.children: new.children.append(child.copy(ne...
Copies an existing structure and all of it's children
def generation(self): if not self.parent: return 0 elif self.parent.is_dict: return 1 + self.parent.generation else: return self.parent.generation
Returns the number of ancestors that are dictionaries
def type_string(self): if self.is_tuple: subtypes = [item.type_string for item in self.children] return '{}({})'.format( '' if self.val_guaranteed else '*', ', '.join(subtypes)) elif self.is_list: return '{}[{}]'.format( ...
Returns a string representing the type of the structure
def get_n_excluded_patches(self): base = self.get_patches_base() if not base: return 0 p = base.rfind('+') if p == -1: return 0 try: n = int(base[p+1:]) return n except TypeError: return 0
Gets number of excluded patches from patches_base: #patches_base=1.0.0+THIS_NUMBER
def set_field(obj, field_name, value): old = getattr(obj, field_name) field = obj._meta.get_field(field_name) # is_relation is Django 1.8 only if field.is_relation: # If field_name is the `_id` field, then there is no 'pk' attr and # old/value *is* the pk old_repr = None if ...
Fancy setattr with debugging.
def obj_update(obj, data: dict, *, update_fields=UNSET, save: bool=True) -> bool: for field_name, value in data.items(): set_field(obj, field_name, value) dirty_data = getattr(obj, DIRTY, None) if not dirty_data: return False logger.debug( human_log_formatter(dirty_data), ...
Fancy way to update `obj` with `data` dict. Parameters ---------- obj : Django model instance data The data to update ``obj`` with update_fields Use your ``update_fields`` instead of our generated one. If you need an auto_now or auto_now_add field to get updated, set this to...
def obj_update_or_create(model, defaults=None, update_fields=UNSET, **kwargs): obj, created = model.objects.get_or_create(defaults=defaults, **kwargs) if created: logger.debug('CREATED %s %s', model._meta.object_name, obj.pk, extra={'pk...
Mimic queryset.update_or_create but using obj_update.
def detect_scheme(filename): logger = logging.getLogger(__name__) logger.info('Detecting partitioning scheme') with open(filename, 'rb') as f: # Look for MBR signature first f.seek(mbr.MBR_SIG_OFFSET) data = f.read(mbr.MBR_SIG_SIZE) signature = struct.unpack("<H", data...
Detects partitioning scheme of the source Args: filename (str): path to file or device for detection of \ partitioning scheme. Returns: SCHEME_MBR, SCHEME_GPT or SCHEME_UNKNOWN Raises: IOError: The file doesn't exist or cannot be opened for reading >>> from rawdisk.sc...
def main(): '''Entry point''' if len(sys.argv) == 1: print("Usage: tyler [filename]") sys.exit(0) filename = sys.argv[1] if not os.path.isfile(filename): print("Specified file does not exists") sys.exit(8) my_tyler = Tyler(filename=filename) while True: ...
Entry point
def _has_file_rolled(self): # if the size is smaller then before, the file has # probabilly been rolled if self._fh: size = self._getsize_of_current_file() if size < self.oldsize: return True self.oldsize = size return False
Check if the file has been rolled
def _open_file(self, filename): if not self._os_is_windows: self._fh = open(filename, "rb") self.filename = filename self._fh.seek(0, os.SEEK_SET) self.oldsize = 0 return # if we're in Windows, we need to use the WIN32 API to open th...
Open a file to be tailed