if fmt is None:<EOL><INDENT>return {'<STR_LIT>': None, '<STR_LIT>': None, '<STR_LIT>': None}<EOL><DEDENT>tz_marker = None<EOL>match = re.search('<STR_LIT>', fmt)<EOL>if match:<EOL><INDENT>tz_marker = match.group('<STR_LIT>')<EOL>if len(set(tz_marker.strip())) != <NUM_LIT:1>:  <EOL><INDENT>raise ValueError(fmt)<EOL><DEDENT>fmt = fmt[:match.start()]<EOL><DEDENT>date_patterns = {<EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>"<STR_LIT>",  <EOL>}<EOL>time_patterns = {"<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>"}<EOL>translate = {<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT:M>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT:d>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>}<EOL>for dt_sep in '<STR_LIT>':  <EOL><INDENT>if dt_sep in fmt:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>dt_sep = None<EOL><DEDENT>if dt_sep:<EOL><INDENT>dfmt, tfmt = fmt.split(dt_sep)<EOL><DEDENT>elif no_date:<EOL><INDENT>dfmt, tfmt = None, fmt<EOL><DEDENT>else:<EOL><INDENT>dfmt, tfmt = fmt, None<EOL><DEDENT>msecs = None  <EOL>if tfmt and '<STR_LIT:.>' in tfmt:  <EOL><INDENT>tfmt, msecs = tfmt.split('<STR_LIT:.>')  <EOL>if set(msecs) != {'<STR_LIT:S>'}:  <EOL><INDENT>raise ValueError(fmt)<EOL><DEDENT>msecs = len(msecs)   <EOL><DEDENT>if (dfmt and dfmt not in date_patterns) or (tfmt and tfmt not in time_patterns):<EOL><INDENT>raise ValueError(fmt)<EOL><DEDENT>regex, format = '<STR_LIT>', '<STR_LIT>'  <EOL>if dfmt:<EOL><INDENT>for d_sep in '<STR_LIT>':  <EOL><INDENT>if d_sep in dfmt:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')  <EOL><DEDENT>for i, part in enumerate(dfmt.split(d_sep)):<EOL><INDENT>if i > <NUM_LIT:0>:<EOL><INDENT>format += d_sep<EOL>regex += re.escape(d_sep)<EOL><DEDENT>f, r = translate[part]<EOL>format += f<EOL>regex += r<EOL><DEDENT><DEDENT>if dt_sep:<EOL><INDENT>format += dt_sep<EOL>regex += re.escape(dt_sep)<EOL><DEDENT>if tfmt:<EOL><INDENT>for i, part in enumerate(tfmt.split('<STR_LIT::>')):<EOL><INDENT>if i > <NUM_LIT:0>:<EOL><INDENT>format += '<STR_LIT::>'<EOL>regex += re.escape('<STR_LIT::>')<EOL><DEDENT>f, r = translate[part]<EOL>format += f<EOL>regex += r<EOL><DEDENT><DEDENT>if msecs:<EOL><INDENT>format += '<STR_LIT>' % msecs<EOL>regex += '<STR_LIT>' % msecs<EOL><DEDENT>return {'<STR_LIT>': re.compile(regex), '<STR_LIT>': format, '<STR_LIT>': tz_marker}<EOL>


def write(self, _force=False, _exists_ok=False, **items):

if self.fname and self.fname.exists():<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>with self.connection() as db:<EOL><INDENT>for table in self.tables:<EOL><INDENT>db.execute(table.sql(translate=self.translate))<EOL><DEDENT>db.execute('<STR_LIT>')<EOL>db.commit()<EOL>refs = defaultdict(list)  <EOL>for t in self.tables:<EOL><INDENT>if t.name not in items:<EOL><INDENT>continue<EOL><DEDENT>rows, keys = [], []<EOL>cols = {c.name: c for c in t.columns}<EOL>for i, row in enumerate(items[t.name]):<EOL><INDENT>pk = row[t.primary_key[<NUM_LIT:0>]]if t.primary_key and len(t.primary_key) == <NUM_LIT:1> else None<EOL>values = []<EOL>for k, v in row.items():<EOL><INDENT>if k in t.many_to_many:<EOL><INDENT>assert pk<EOL>at = t.many_to_many[k]<EOL>atkey = tuple([at.name] + [c.name for c in at.columns])<EOL>for vv in v:<EOL><INDENT>fkey, context = self.association_table_context(t, k, vv)<EOL>refs[atkey].append((pk, fkey, context))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>col = cols[k]<EOL>if isinstance(v, list):<EOL><INDENT>v = (col.separator or '<STR_LIT:;>').join(<EOL>col.convert(vv) for vv in v)<EOL><DEDENT>else:<EOL><INDENT>v = col.convert(v) if v is not None else None<EOL><DEDENT>if i == <NUM_LIT:0>:<EOL><INDENT>keys.append(col.name)<EOL><DEDENT>values.append(v)<EOL><DEDENT><DEDENT>rows.append(tuple(values))<EOL><DEDENT>insert(db, self.translate, t.name, keys, *rows)<EOL><DEDENT>for atkey, rows in refs.items():<EOL><INDENT>insert(db, self.translate, atkey[<NUM_LIT:0>], atkey[<NUM_LIT:1>:], *rows)<EOL><DEDENT>db.commit()<EOL><DEDENT>

Creates a db file with the core schema.

:param force: If `True` an existing db file will be overwritten.


col_translate = partial(translate, self.name)<EOL>clauses = [col.sql(col_translate) for col in self.columns]<EOL>if self.primary_key:<EOL><INDENT>clauses.append('<STR_LIT>'.format(quoted(<EOL>*[col_translate(c) for c in self.primary_key])))<EOL><DEDENT>for fk, ref, refcols in self.foreign_keys:<EOL><INDENT>clauses.append('<STR_LIT>'.format(<EOL>quoted(*[col_translate(c) for c in fk]),<EOL>quoted(translate(ref)),<EOL>quoted(*[translate(ref, c) for c in refcols])))<EOL><DEDENT>return "<STR_LIT>".format(<EOL>translate(self.name), '<STR_LIT>'.join(clauses))<EOL>

:param translate:
:return: The SQL statement to create the table.


tables = {}<EOL>for tname, table in tg.tabledict.items():<EOL><INDENT>t = TableSpec.from_table_metadata(table)<EOL>tables[t.name] = t<EOL>for at in t.many_to_many.values():<EOL><INDENT>tables[at.name] = at<EOL><DEDENT><DEDENT>ordered = OrderedDict()<EOL>i = <NUM_LIT:0><EOL>while tables and i < <NUM_LIT:100>:<EOL><INDENT>i += <NUM_LIT:1><EOL>for table in list(tables.keys()):<EOL><INDENT>if all((ref[<NUM_LIT:1>] in ordered) or ref[<NUM_LIT:1>] == table for ref in tables[table].foreign_keys):<EOL><INDENT>ordered[table] = tables.pop(table)<EOL>break<EOL><DEDENT><DEDENT><DEDENT>if tables:  <EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return list(ordered.values())<EOL>

Convert the table and column descriptions of a `TableGroup` into specifications for the
DB schema.

:param ds:
:return: A pair (tables, reference_tables).


if not self.csvw:<EOL><INDENT>return<EOL><DEDENT>c, cname = self.csvw, translate(self.name)<EOL>constraints = []<EOL>if (c.minimum is not None) or (c.maximum is not None):<EOL><INDENT>func = {<EOL>'<STR_LIT:date>': '<STR_LIT:date>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>}.get(self.csvw_type)<EOL>if c.minimum is not None:<EOL><INDENT>if func:<EOL><INDENT>constraints.append("<STR_LIT>".format(cname, c.minimum, func))<EOL><DEDENT>else:<EOL><INDENT>constraints.append('<STR_LIT>'.format(cname, c.minimum))<EOL><DEDENT><DEDENT>if c.maximum is not None:<EOL><INDENT>if func:<EOL><INDENT>constraints.append("<STR_LIT>".format(cname, c.maximum, func))<EOL><DEDENT>else:<EOL><INDENT>constraints.append('<STR_LIT>'.format(cname, c.maximum))<EOL><DEDENT><DEDENT><DEDENT>elif any(cc is not None for cc in [c.length, c.minLength, c.maxLength]):<EOL><INDENT>if c.length:<EOL><INDENT>constraints.append('<STR_LIT>'.format(cname, c.length))<EOL><DEDENT>if c.minLength:<EOL><INDENT>constraints.append('<STR_LIT>'.format(cname, c.minLength))<EOL><DEDENT>if c.maxLength:<EOL><INDENT>constraints.append('<STR_LIT>'.format(cname, c.maxLength))<EOL><DEDENT><DEDENT>return '<STR_LIT>'.join(constraints)<EOL>

We try to convert as many data constraints as possible into SQLite CHECK constraints.

:param translate:
:return:


def filter_rows_as_dict(fname, filter_, **kw):

filter_ = DictFilter(filter_)<EOL>rewrite(fname, filter_, **kw)<EOL>return filter_.removed<EOL>

Rewrite a dsv file, filtering the rows.

    :param fname: Path to dsv file
    :param filter_: callable which accepts a `dict` with a row's data as single argument\
    returning a `Boolean` indicating whether to keep the row (`True`) or to discard it \
    `False`.
    :param kw: Keyword arguments to be passed `UnicodeReader` and `UnicodeWriter`.
    :return: The number of rows that have been removed.


<EOL>row = super(UnicodeReaderWithLineNumber, self).__next__()<EOL>return self.lineno + <NUM_LIT:1>, row<EOL>

:return: a pair (1-based line number in the input, row)


return self._fname.parent<EOL>

We only support data in the filesystem, thus we make sure `base` is a `pathlib.Path`.


return {tname: list(t.iterdicts()) for tname, t in self.tabledict.items()}<EOL>


if isinstance(v, text_type):<EOL><INDENT>return cls(base=v)<EOL><DEDENT>if isinstance(v, dict):<EOL><INDENT>return cls(**DescriptionBase.partition_properties(v))<EOL><DEDENT>if isinstance(v, cls):<EOL><INDENT>return v<EOL><DEDENT>raise ValueError(v)<EOL>

:param v: Initialization data for `cls`; either a single string that is the main datatype \
of the values of the cell or a datatype description object, i.e. a `dict` or a `cls`
instance.
:return: An instance of `cls`


dest = pathlib.Path(dest)<EOL>for table in self.tables:<EOL><INDENT>shutil.copy(str(table.url.resolve(self.base)), str(table.url.resolve(dest)))<EOL><DEDENT>self._fname = dest / self._fname.name<EOL>self.to_file(self._fname)<EOL>

Write a TableGroup's data and metadata to files relative to `dest`, adapting the `base`
attribute.

:param dest:
:return:


def slug(s, remove_whitespace=True, lowercase=True):

res = '<STR_LIT>'.join(c for c in unicodedata.normalize('<STR_LIT>', s)<EOL>if unicodedata.category(c) != '<STR_LIT>')<EOL>if lowercase:<EOL><INDENT>res = res.lower()<EOL><DEDENT>for c in string.punctuation:<EOL><INDENT>res = res.replace(c, '<STR_LIT>')<EOL><DEDENT>res = re.sub('<STR_LIT>', '<STR_LIT>' if remove_whitespace else '<STR_LIT:U+0020>', res)<EOL>res = res.encode('<STR_LIT:ascii>', '<STR_LIT:ignore>').decode('<STR_LIT:ascii>')<EOL>assert re.match('<STR_LIT>', res)<EOL>return res<EOL>

Condensed version of s, containing only lowercase alphanumeric characters.

    >>> str(slug('A B. \u00e4C'))
    'abac'


s = s.replace('<STR_LIT:->', '<STR_LIT:_>').replace('<STR_LIT:.>', '<STR_LIT:_>').replace('<STR_LIT:U+0020>', '<STR_LIT:_>')<EOL>if s in keyword.kwlist:<EOL><INDENT>return s + '<STR_LIT:_>'<EOL><DEDENT>s = '<STR_LIT:_>'.join(slug(ss, lowercase=False) for ss in s.split('<STR_LIT:_>'))<EOL>if not s:<EOL><INDENT>s = '<STR_LIT:_>'<EOL><DEDENT>if s[<NUM_LIT:0>] not in string.ascii_letters + '<STR_LIT:_>':<EOL><INDENT>s = '<STR_LIT:_>' + s<EOL><DEDENT>return s<EOL>

Convert a string into a valid python attribute name.
    This function is called to convert ASCII strings to something that can pass as
    python attribute name, to be used with namedtuples.

    >>> str(normalize_name('class'))
    'class_'
    >>> str(normalize_name('a-name'))
    'a_name'
    >>> str(normalize_name('a n\u00e4me'))
    'a_name'
    >>> str(normalize_name('Name'))
    'Name'
    >>> str(normalize_name(''))
    '_'
    >>> str(normalize_name('1'))
    '_1'


def to_zebra_value(value):<EOL><INDENT>transform_funcs = {<EOL>bool: lambda v: '<STR_LIT:true>' if v else '<STR_LIT:false>',<EOL>}<EOL>return transform_funcs.get(type(value), lambda v: v)(value)<EOL><DEDENT>return {param: to_zebra_value(value) for param, value in params.items()}<EOL>

Transforms the given `params` dict to values that are understood by Zebra (eg. False is represented as 'false')


message_type_kwargs = {<EOL>'<STR_LIT>': {'<STR_LIT>': '<STR_LIT>'},<EOL>'<STR_LIT:error>': {'<STR_LIT>': '<STR_LIT>'},<EOL>}<EOL>for message in response_json.get('<STR_LIT>', []):<EOL><INDENT>click.secho(message['<STR_LIT:text>'], **message_type_kwargs.get(message['<STR_LIT:type>'], {}))<EOL><DEDENT>

Show all messages in the `messages` key of the given dict.


if not data:<EOL><INDENT>return None<EOL><DEDENT>return Message(<EOL>id=data['<STR_LIT:message>']['<STR_LIT>'],<EOL>platform=self.platform,<EOL>text=data['<STR_LIT:message>']['<STR_LIT:text>'],<EOL>user=data['<STR_LIT>']['<STR_LIT:id>'],<EOL>timestamp=data['<STR_LIT>'],<EOL>raw=data,<EOL>chat=None,  <EOL>)<EOL>

Return a Message instance according to the data received from
Facebook Messenger API.


message = self.build_message(data)<EOL>if not message:<EOL><INDENT>logger.error(<EOL>'<STR_LIT>',<EOL>self.engine_name,<EOL>data<EOL>)<EOL>return<EOL><DEDENT>logger.info('<STR_LIT>', self.engine_name,<EOL>message.user, message.text)<EOL>response = await self.get_response(message)<EOL>if response:<EOL><INDENT>await self.send_response(response)<EOL><DEDENT>

For each new message, build its platform specific message
object and get a response.


for handler in self.registered_handlers:<EOL><INDENT>if handler.check(message):<EOL><INDENT>return handler.view<EOL><DEDENT><DEDENT>return None<EOL>

Use the new message to search for a registered view according
to its pattern.


for x in range(<NUM_LIT:1>, <NUM_LIT>): yield x<EOL>


if __PI_TEXT_CHECK_PATTERN.search(text):<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>

validates XML Processing Instruction text


if __COMMENT_TEXT_CHECK_PATTERN.search(text):<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>


for event, elt in et.iterparse(filename, events= ('<STR_LIT:start>', '<STR_LIT:end>', '<STR_LIT>', '<STR_LIT>'), huge_tree=True):<EOL><INDENT>if event == '<STR_LIT:start>':<EOL><INDENT>obj = _elt2obj(elt)<EOL>obj['<STR_LIT:type>'] = ENTER<EOL>yield obj<EOL>if elt.text:<EOL><INDENT>yield {'<STR_LIT:type>': TEXT, '<STR_LIT:text>': elt.text}<EOL><DEDENT><DEDENT>elif event == '<STR_LIT:end>':<EOL><INDENT>yield {'<STR_LIT:type>': EXIT}<EOL>if elt.tail:<EOL><INDENT>yield {'<STR_LIT:type>': TEXT, '<STR_LIT:text>': elt.tail}<EOL><DEDENT>elt.clear()<EOL><DEDENT>elif event == '<STR_LIT>':<EOL><INDENT>yield {'<STR_LIT:type>': COMMENT, '<STR_LIT:text>': elt.text}<EOL><DEDENT>elif event == '<STR_LIT>':<EOL><INDENT>yield {'<STR_LIT:type>': PI, '<STR_LIT:text>': elt.text}<EOL><DEDENT>else:<EOL><INDENT>assert False, (event, elt)<EOL><DEDENT><DEDENT>


if xml.tag is et.Comment:<EOL><INDENT>yield {'<STR_LIT:type>': COMMENT, '<STR_LIT:text>': xml.text}<EOL>return<EOL><DEDENT>if xml.tag is et.PI:<EOL><INDENT>if xml.text:<EOL><INDENT>yield {'<STR_LIT:type>': PI, '<STR_LIT:target>': xml.target, '<STR_LIT:text>': xml.text}<EOL><DEDENT>else:<EOL><INDENT>yield {'<STR_LIT:type>': PI, '<STR_LIT:target>': xml.target}<EOL><DEDENT>return<EOL><DEDENT>obj = _elt2obj(xml)<EOL>obj['<STR_LIT:type>'] = ENTER<EOL>yield obj<EOL>assert type(xml.tag) is str, xml<EOL>if xml.text:<EOL><INDENT>yield {'<STR_LIT:type>': TEXT, '<STR_LIT:text>': xml.text}<EOL><DEDENT>for c in xml:<EOL><INDENT>for x in scan(c): yield x<EOL>if c.tail:<EOL><INDENT>yield {'<STR_LIT:type>': TEXT, '<STR_LIT:text>': c.tail}<EOL><DEDENT><DEDENT>yield {'<STR_LIT:type>': EXIT}<EOL>


return '<STR_LIT>'.join(o['<STR_LIT:text>'] for o in events if o['<STR_LIT:type>']==TEXT)<EOL>


stack = []<EOL>for obj in events:<EOL><INDENT>if obj['<STR_LIT:type>'] == ENTER:<EOL><INDENT>stack.append(obj)<EOL>yield obj, None<EOL><DEDENT>elif obj['<STR_LIT:type>'] == EXIT:<EOL><INDENT>yield obj, stack.pop()<EOL><DEDENT>else:<EOL><INDENT>yield obj, None<EOL><DEDENT><DEDENT>

locates ENTER peer for each EXIT object. Convenient when selectively
    filtering out XML markup


def get_n_splits(self, X=None, y=None, groups=None):

return self.n_splits<EOL>

Returns the number of splitting iterations in the cross-validator
        Parameters
        ----------
        X : object
            Always ignored, exists for compatibility.
            ``np.zeros(n_samples)`` may be used as a placeholder.
        y : object
            Always ignored, exists for compatibility.
            ``np.zeros(n_samples)`` may be used as a placeholder.
        groups : array-like, with shape (n_samples,)
            Group labels for the samples used while splitting the dataset into
            train/test set.
        Returns
        -------
        n_splits : int
            Returns the number of splitting iterations in the cross-validator.


def split(self, X, y=None, groups=None):

X, y, groups = indexable(X, y, groups)<EOL>cgrs = [~r for r in X]<EOL>condition_structure = defaultdict(set)<EOL>for structure, condition in zip(cgrs, groups):<EOL><INDENT>condition_structure[condition].add(structure)<EOL><DEDENT>train_data = defaultdict(list)<EOL>test_data = []<EOL>for n, (structure, condition) in enumerate(zip(cgrs, groups)):<EOL><INDENT>train_data[structure].append(n)<EOL>if len(condition_structure[condition]) > <NUM_LIT:1>:<EOL><INDENT>test_data.append(n)<EOL><DEDENT><DEDENT>if self.n_splits > len(train_data):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% (self.n_splits, len(train_data)))<EOL><DEDENT>structures_weight = sorted(((x, len(y)) for x, y in train_data.items()), key=lambda x: x[<NUM_LIT:1>], reverse=True)<EOL>fold_mean_size = len(cgrs) // self.n_splits<EOL>if structures_weight[<NUM_LIT:0>][<NUM_LIT:1>] > fold_mean_size:<EOL><INDENT>warning('<STR_LIT>')<EOL><DEDENT>for idx in range(self.n_repeats):<EOL><INDENT>train_folds = [[] for _ in range(self.n_splits)]<EOL>for structure, structure_length in structures_weight:<EOL><INDENT>if self.shuffle:<EOL><INDENT>check_random_state(self.random_state).shuffle(train_folds)<EOL><DEDENT>for fold in train_folds[:-<NUM_LIT:1>]:<EOL><INDENT>if len(fold) + structure_length <= fold_mean_size:<EOL><INDENT>fold.extend(train_data[structure])<EOL>break<EOL><DEDENT>else:<EOL><INDENT>roulette_param = (structure_length - fold_mean_size + len(fold)) / structure_length<EOL>if random() > roulette_param:<EOL><INDENT>fold.extend(train_data[structure])<EOL>break<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>train_folds[-<NUM_LIT:1>].extend(train_data[structure])<EOL><DEDENT><DEDENT>test_folds = [[] for _ in range(self.n_splits)]<EOL>for test, train in zip(test_folds, train_folds):<EOL><INDENT>for index in train:<EOL><INDENT>if index in test_data:<EOL><INDENT>test.append(index)<EOL><DEDENT><DEDENT><DEDENT>for i in range(self.n_splits):<EOL><INDENT>train_index = []<EOL>for fold in train_folds[:i]:<EOL><INDENT>train_index.extend(fold)<EOL><DEDENT>for fold in train_folds[i+<NUM_LIT:1>:]:<EOL><INDENT>train_index.extend(fold)<EOL><DEDENT>test_index = test_folds[i]<EOL>yield array(train_index), array(test_index)<EOL><DEDENT><DEDENT>

Generate indices to split data into training and test set.
        Parameters
        ----------
        X : array-like, of length n_samples
            Training data, includes reaction's containers
        y : array-like, of length n_samples
            The target variable for supervised learning problems.
        groups : array-like, with shape (n_samples,)
            Group labels for the samples used while splitting the dataset into
            train/test set.
        Yields
        ------
        train : ndarray
            The training set indices for that split.
        test : ndarray
            The testing set indices for that split.


X, y, groups = indexable(X, y, groups)<EOL>cgrs = [~r for r in X]<EOL>structure_condition = defaultdict(set)<EOL>for structure, condition in zip(cgrs, groups):<EOL><INDENT>structure_condition[structure].add(condition)<EOL><DEDENT>train_data = defaultdict(list)<EOL>test_data = []<EOL>for n, (structure, condition) in enumerate(zip(cgrs, groups)):<EOL><INDENT>train_data[condition].append(n)<EOL>if len(structure_condition[structure]) > <NUM_LIT:1>:<EOL><INDENT>test_data.append(n)<EOL><DEDENT><DEDENT>for condition, indexes in train_data.items():<EOL><INDENT>test_index = [index for index in indexes if index in test_data]<EOL>if test_index:<EOL><INDENT>train_index = [i for cond, ind in train_data.items() if cond != condition for i in ind]<EOL>yield array(train_index), array(test_index)<EOL><DEDENT><DEDENT>


if isinstance(data, Path):<EOL><INDENT>with data.open('<STR_LIT:rb>') as f:<EOL><INDENT>data = f.read()<EOL><DEDENT><DEDENT>elif isinstance(data, StringIO):<EOL><INDENT>data = data.read().encode()<EOL><DEDENT>elif isinstance(data, BytesIO):<EOL><INDENT>data = data.read()<EOL><DEDENT>elif hasattr(data, '<STR_LIT>'):  <EOL><INDENT>data = data.read()<EOL>if isinstance(data, str):<EOL><INDENT>data = data.encode()<EOL><DEDENT><DEDENT>elif isinstance(data, str):<EOL><INDENT>data = data.encode()<EOL><DEDENT>elif not isinstance(data, bytes):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>p = run(['<STR_LIT>', '<STR_LIT>', '<STR_LIT>'], input=data, stdout=PIPE)<EOL><DEDENT>except FileNotFoundError as e:<EOL><INDENT>raise ConfigurationError from e<EOL><DEDENT>if p.returncode != <NUM_LIT:0>:<EOL><INDENT>raise ConfigurationError(p.stderr.decode())<EOL><DEDENT>with BytesIO(p.stdout) as f, MRVread(f) as r:<EOL><INDENT>return iter2array(r)<EOL><DEDENT>

molconvert wrapper
:param data: buffer or string or path to file
:return: array of molecules of reactions


<EOL>check_is_fitted(self, ['<STR_LIT>'])<EOL>X = check_array(X)<EOL>return self.tree.query(X)[<NUM_LIT:0>].flatten()<EOL>

Returns the value of the nearest neighbor from the training set.

        Parameters
        ----------
         X : array-like or sparse matrix, shape (n_samples, n_features)
            The input samples. Internally, it will be converted to
            ``dtype=np.float32`` and if a sparse matrix is provided
            to a sparse ``csr_matrix``.

        Returns
        -------
        y : array, shape (n_samples,)


<EOL>check_is_fitted(self, ['<STR_LIT>'])<EOL>X = check_array(X)<EOL>return self.tree.query(X)[<NUM_LIT:0>].flatten() <= self.threshold_value<EOL>

Predict if a particular sample is an outlier or not.

        Parameters
        ----------
         X : array-like or sparse matrix, shape (n_samples, n_features)
            The input samples. Internally, it will be converted to
            ``dtype=np.float32`` and if a sparse matrix is provided
            to a sparse ``csr_matrix``.

        Returns
        -------
        y : array, shape (n_samples,)
            For each observations, tells whether or not (True or False) it should
            be considered as an inlier according to the fitted model.


<EOL>X = check_array(X)<EOL>self.tree = BallTree(X, leaf_size=self.leaf_size, metric=self.metric)<EOL>dist_train = self.tree.query(X, k=<NUM_LIT:2>)[<NUM_LIT:0>]<EOL>if self.threshold == '<STR_LIT>':<EOL><INDENT>self.threshold_value = <NUM_LIT:0.5> * sqrt(var(dist_train[:, <NUM_LIT:1>])) + mean(dist_train[:, <NUM_LIT:1>])<EOL><DEDENT>elif self.threshold == '<STR_LIT>':<EOL><INDENT>if y is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>y = check_array(y, accept_sparse='<STR_LIT>', ensure_2d=False, dtype=None)<EOL>self.threshold_value = <NUM_LIT:0><EOL>score = <NUM_LIT:0><EOL>Y_pred, Y_true, AD = [], [], []<EOL>cv = KFold(n_splits=<NUM_LIT:5>, random_state=<NUM_LIT:1>, shuffle=True)<EOL>for train_index, test_index in cv.split(X):<EOL><INDENT>x_train = safe_indexing(X, train_index)<EOL>x_test = safe_indexing(X, test_index)<EOL>y_train = safe_indexing(y, train_index)<EOL>y_test = safe_indexing(y, test_index)<EOL>data_test = safe_indexing(dist_train[:, <NUM_LIT:1>], test_index)<EOL>if self.reg_model is None:<EOL><INDENT>reg_model = RandomForestRegressor(n_estimators=<NUM_LIT>, random_state=<NUM_LIT:1>).fit(x_train, y_train)<EOL><DEDENT>else:<EOL><INDENT>reg_model = clone(self.reg_model).fit(x_train, y_train)<EOL><DEDENT>Y_pred.append(reg_model.predict(x_test))<EOL>Y_true.append(y_test)<EOL>AD.append(data_test)<EOL><DEDENT>AD_ = unique(hstack(AD))<EOL>for z in AD_:<EOL><INDENT>AD_new = hstack(AD) <= z<EOL>if self.score == '<STR_LIT>':<EOL><INDENT>val = balanced_accuracy_score_with_ad(Y_true=hstack(Y_true), Y_pred=hstack(Y_pred), AD=AD_new)<EOL><DEDENT>elif self.score == '<STR_LIT>':<EOL><INDENT>val = rmse_score_with_ad(Y_true=hstack(Y_true), Y_pred=hstack(Y_pred), AD=AD_new)<EOL><DEDENT>if val >= score:<EOL><INDENT>score = val<EOL>self.threshold_value = z<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>self.threshold_value = self.threshold<EOL><DEDENT>return self<EOL>

Fit distance-based AD.

        Parameters
        ----------
        X : array-like or sparse matrix, shape (n_samples, n_features)
            The input samples. Use ``dtype=np.float32`` for maximum
            efficiency.

        Returns
        -------
        self : object
            Returns self.


<EOL>check_is_fitted(self, ['<STR_LIT>', '<STR_LIT>'])<EOL>X = check_array(X)<EOL>return ((X - self._x_min).min(axis=<NUM_LIT:1>) >= <NUM_LIT:0>) & ((self._x_max - X).min(axis=<NUM_LIT:1>) >= <NUM_LIT:0>)<EOL>

Predict if a particular sample is an outlier or not.

        Parameters
        ----------
        X : array-like or sparse matrix, shape (n_samples, n_features)
            The input samples. Internally, it will be converted to
            ``dtype=np.float32`` and if a sparse matrix is provided
            to a sparse ``csr_matrix``.

        Returns
        -------
        is_inlier : array, shape (n_samples,)
                   For each observations, tells whether or not (True or False) it should
                   be considered as an inlier according to the fitted model.


<EOL>X = check_array(X)<EOL>self.inverse_influence_matrix = self.__make_inverse_matrix(X)<EOL>if self.threshold == '<STR_LIT>':<EOL><INDENT>self.threshold_value = <NUM_LIT:3> * (<NUM_LIT:1> + X.shape[<NUM_LIT:1>]) / X.shape[<NUM_LIT:0>]<EOL><DEDENT>elif self.threshold == '<STR_LIT>':<EOL><INDENT>if y is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>y = check_array(y, accept_sparse='<STR_LIT>', ensure_2d=False, dtype=None)<EOL>self.threshold_value = <NUM_LIT:0><EOL>score = <NUM_LIT:0><EOL>Y_pred, Y_true, AD = [], [], []<EOL>cv = KFold(n_splits=<NUM_LIT:5>, random_state=<NUM_LIT:1>, shuffle=True)<EOL>for train_index, test_index in cv.split(X):<EOL><INDENT>x_train = safe_indexing(X, train_index)<EOL>x_test = safe_indexing(X, test_index)<EOL>y_train = safe_indexing(y, train_index)<EOL>y_test = safe_indexing(y, test_index)<EOL>if self.reg_model is None:<EOL><INDENT>reg_model = RandomForestRegressor(n_estimators=<NUM_LIT>, random_state=<NUM_LIT:1>).fit(x_train, y_train)<EOL><DEDENT>else:<EOL><INDENT>reg_model = clone(self.reg_model).fit(x_train, y_train)<EOL><DEDENT>Y_pred.append(reg_model.predict(x_test))<EOL>Y_true.append(y_test)<EOL>ad_model = self.__make_inverse_matrix(x_train)<EOL>AD.append(self.__find_leverages(x_test, ad_model))<EOL><DEDENT>AD_ = unique(hstack(AD))<EOL>for z in AD_:<EOL><INDENT>AD_new = hstack(AD) <= z<EOL>if self.score == '<STR_LIT>':<EOL><INDENT>val = balanced_accuracy_score_with_ad(Y_true=hstack(Y_true), Y_pred=hstack(Y_pred), AD=AD_new)<EOL><DEDENT>elif self.score == '<STR_LIT>':<EOL><INDENT>val = rmse_score_with_ad(Y_true=hstack(Y_true), Y_pred=hstack(Y_pred), AD=AD_new)<EOL><DEDENT>if val >= score:<EOL><INDENT>score = val<EOL>self.threshold_value = z<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>self.threshold_value = self.threshold<EOL><DEDENT>return self<EOL>

Learning is to find the inverse matrix for X and calculate the threshold.

        Parameters
        ----------
        X : array-like or sparse matrix, shape (n_samples, n_features)
            The input samples. Use ``dtype=np.float32`` for maximum
            efficiency.
        y : array-like, shape = [n_samples] or [n_samples, n_outputs]
            The target values (real numbers in regression).

        Returns
        -------
        self : object


check_is_fitted(self, ['<STR_LIT>'])<EOL>X = iter2array(X, dtype=ReactionContainer)<EOL>return array([self.__get_signature(x) in self._train_signatures for x in X])<EOL>

Reaction is considered belonging to model’s AD
        if its reaction signature coincides with ones used in training set.

        Parameters
        ----------
        X : after read rdf file

        Returns
        -------
        self : array contains True (reaction in AD) and False (reaction residing outside AD).


return ['<STR_LIT>', '<STR_LIT>'] + [f'<STR_LIT>' for x in range(<NUM_LIT:1>, self.max_solvents + <NUM_LIT:1>)] +[f'<STR_LIT>' for x in range(<NUM_LIT:1>, self.max_solvents + <NUM_LIT:1>)]<EOL>

Get feature names.

        Returns
        -------
        feature_names : list of strings
            Names of the features produced by transform.


def __init__(self, templates, balance_groups=False):

self.templates = templates<EOL>self.balance_groups = balance_groups<EOL>self.__init()<EOL>

CGR standardization and reaction balancing

:param templates: CGRTemplates. list of rules for graph modifications.
:param balance_groups: if True: for unbalanced reactions contains multiple attached functional groups in
    products and one of them described in reagents - will be restored information about all equal groups.
    for example:

        R + B1-X-> B'1-R'-B'2 + X'

    where B' is transformed B, R and X same.
    we know what B'1 and B'2 is equal and B'1 is transformed B1 =>
    this groups most likely appeared from a single reagent. we can add copy of B-X to reagents.
    results will be:

        R + B1-X1 + B2-X2 -> B'1-R'-B'2 + X'1 + X'2


def __init__(self, fragment_type=<NUM_LIT:3>, min_length=<NUM_LIT:2>, max_length=<NUM_LIT:10>, cgr_dynbonds=<NUM_LIT:0>, doallways=False,<EOL>useformalcharge=False, header=None, workpath='<STR_LIT:.>', version=None, verbose=False, remove_rare_ratio=<NUM_LIT:0>,<EOL>return_domain=False):

self.fragment_type = fragment_type<EOL>self.min_length = min_length<EOL>self.max_length = max_length<EOL>self.cgr_dynbonds = cgr_dynbonds<EOL>self.doallways = doallways<EOL>self.useformalcharge = useformalcharge<EOL>self.version = version<EOL>self.verbose = verbose<EOL>self.header = header<EOL>self.remove_rare_ratio = remove_rare_ratio<EOL>self.return_domain = return_domain<EOL>self.__init_header()<EOL>self.set_work_path(workpath)<EOL>

ISIDA Fragmentor wrapper

:param workpath: path for temp files.
:param version: fragmentor version. need for selecting Fragmentor executables named as fragmentor-{version}
:param header: if None descriptors will be generated on train set
               if False Fragmentor will work in headless mode. in this mod fit unusable and Fragmentor return
                   all found descriptors
               else path string to existing header file acceptable
:param remove_rare_ratio: if descriptors found on train less then given ratio it will be removed from header.
                          if partial fit used, be sure to use finalize method.
                          unusable if headless mode set
:param return_domain: add AD bool column. if False molecule has new features


x = iter2array(x, dtype=(MoleculeContainer, CGRContainer))<EOL>if self.__head_less:<EOL><INDENT>warn(f'<STR_LIT>')<EOL>return self<EOL><DEDENT>self._reset()<EOL>self.__prepare(x)<EOL>return self<EOL>


if self.__head_less:<EOL><INDENT>warn(f'<STR_LIT>')<EOL><DEDENT>elif not self.__head_generate:<EOL><INDENT>warn(f'<STR_LIT>')<EOL><DEDENT>elif not self.__head_dict:<EOL><INDENT>raise NotFittedError(f'<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>if self.remove_rare_ratio:<EOL><INDENT>self.__clean_head(*self.__head_rare)<EOL>self.__prepare_header()<EOL>self.__head_rare = None<EOL><DEDENT>self.__head_generate = False<EOL><DEDENT>


if self.__head_less:<EOL><INDENT>raise AttributeError(f'<STR_LIT>')<EOL><DEDENT>elif not self.__head_dict:<EOL><INDENT>raise NotFittedError(f'<STR_LIT>')<EOL><DEDENT>return list(self.__head_dict.values())<EOL>


if not self.__head_less:<EOL><INDENT>if not self.__head_generate:<EOL><INDENT>self.__head_generate = True<EOL><DEDENT>if self.__head_dict:<EOL><INDENT>self.__head_dump = self.__head_dict = None<EOL><DEDENT>if self.__head_rare is not None:<EOL><INDENT>self.__head_rare = None<EOL><DEDENT>self.delete_work_path()<EOL><DEDENT>

Reset internal data-dependent state.
        __init__ parameters are not touched.


expr_stack = []<EOL>def push_first(strg, loc, toks):<EOL><INDENT>expr_stack.append(toks[<NUM_LIT:0>])<EOL><DEDENT>def push_u_minus(strg, loc, toks):<EOL><INDENT>if toks and toks[<NUM_LIT:0>] == '<STR_LIT:->':<EOL><INDENT>expr_stack.append('<STR_LIT>')<EOL><DEDENT><DEDENT>point = Literal('<STR_LIT:.>')<EOL>_e = CaselessLiteral('<STR_LIT:E>')<EOL>fnumber = Combine(Word('<STR_LIT>' + nums, nums) +<EOL>Optional(point + Optional(Word(nums))) +<EOL>Optional(_e + Word('<STR_LIT>' + nums, nums)))<EOL>ident = Word(alphas, alphas + nums + '<STR_LIT>')<EOL>plus = Literal("<STR_LIT:+>")<EOL>minus = Literal("<STR_LIT:->")<EOL>mult = Literal("<STR_LIT:*>")<EOL>div = Literal("<STR_LIT:/>")<EOL>lpar = Literal("<STR_LIT:(>").suppress()<EOL>rpar = Literal("<STR_LIT:)>").suppress()<EOL>addop = plus | minus<EOL>multop = mult | div<EOL>expop = Literal("<STR_LIT>")<EOL>_pi = CaselessLiteral("<STR_LIT>")<EOL>x = CaselessLiteral("<STR_LIT:X>")<EOL>expr = Forward()<EOL>atom = (Optional("<STR_LIT:->") + (x | _pi | _e | fnumber | ident + lpar + expr + rpar).setParseAction(push_first) |<EOL>(lpar + expr.suppress() + rpar)).setParseAction(push_u_minus)<EOL>factor = Forward()<EOL>factor << atom + ZeroOrMore((expop + factor).setParseAction(push_first))<EOL>term = factor + ZeroOrMore((multop + factor).setParseAction(push_first))<EOL>expr << term + ZeroOrMore((addop + term).setParseAction(push_first))<EOL>expr.parseString(expression)<EOL>return expr_stack<EOL>

adopted from Paul McGuire example. http://pyparsing.wikispaces.com/file/view/fourFn.py


return [f'<STR_LIT>']<EOL>


pass<EOL>

empty command to allow help messages to work


env_config = parse_env_config(config, args.environment)<EOL>helper.rebuild_environment(args.environment)<EOL>if not args.dont_wait:<EOL><INDENT>helper.wait_for_environments(args.environment, health='<STR_LIT>', status='<STR_LIT>')<EOL><DEDENT>


envs = config.get('<STR_LIT>', {}).get('<STR_LIT>', [])<EOL>out("<STR_LIT>")<EOL>for name, conf in list(envs.items()):<EOL><INDENT>out('<STR_LIT:\t>'+name)<EOL><DEDENT>envs = helper.get_environments()<EOL>out("<STR_LIT>")<EOL>for env in envs:<EOL><INDENT>if env['<STR_LIT>'] != '<STR_LIT>':<EOL><INDENT>out('<STR_LIT:\t>'+str(env['<STR_LIT>'])+'<STR_LIT>'+str(env['<STR_LIT>'])+'<STR_LIT:U+002CU+0020>'+str(env['<STR_LIT>'])+'<STR_LIT:)>')<EOL><DEDENT><DEDENT>


versions = helper.get_versions()<EOL>out("<STR_LIT>")<EOL>for version in versions:<EOL><INDENT>out(version)<EOL><DEDENT>


env = parse_env_config(config, args.environment)<EOL>option_settings = env.get('<STR_LIT>', {})<EOL>settings = parse_option_settings(option_settings)<EOL>for setting in settings:<EOL><INDENT>out(str(setting))<EOL><DEDENT>


parser.add_argument('<STR_LIT>', '<STR_LIT>', help='<STR_LIT>', required=True)<EOL>


__import__('<STR_LIT>' + name + '<STR_LIT>')<EOL>return sys.modules['<STR_LIT>' + name + '<STR_LIT>']<EOL>


ret = []<EOL>for f in os.listdir(COMMAND_MODULE_PATH):<EOL><INDENT>if os.path.isfile(os.path.join(COMMAND_MODULE_PATH, f)) and f.endswith(COMMAND_MODULE_SUFFIX):<EOL><INDENT>ret.append(f[:-len(COMMAND_MODULE_SUFFIX)])<EOL><DEDENT><DEDENT>return ret<EOL>

Returns a list of command names supported


version_label = args.version_label<EOL>archive = args.archive<EOL>env_config = parse_env_config(config, args.environment)<EOL>option_settings = parse_option_settings(env_config.get('<STR_LIT>', {}))<EOL>cname_prefix = env_config.get('<STR_LIT>', None)<EOL>tier_name = env_config.get('<STR_LIT>', '<STR_LIT>')<EOL>if tier_name != '<STR_LIT>':<EOL><INDENT>raise Exception(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (tier_name, ))<EOL><DEDENT>out("<STR_LIT>")<EOL>new_env_name = None<EOL>if not helper.environment_exists(args.environment):<EOL><INDENT>new_env_name = args.environment<EOL><DEDENT>else:<EOL><INDENT>for i in range(<NUM_LIT:10>):<EOL><INDENT>temp_env_name = args.environment + '<STR_LIT:->' + str(i)<EOL>if not helper.environment_exists(temp_env_name):<EOL><INDENT>new_env_name = temp_env_name<EOL>break<EOL><DEDENT><DEDENT><DEDENT>if new_env_name is None:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>out("<STR_LIT>" + new_env_name)<EOL>out("<STR_LIT>")<EOL>new_env_cname = None<EOL>for i in range(<NUM_LIT:10>):<EOL><INDENT>temp_cname = cname_prefix + '<STR_LIT:->' + str(i)<EOL>if not helper.environment_name_for_cname(temp_cname):<EOL><INDENT>new_env_cname = temp_cname<EOL>break<EOL><DEDENT><DEDENT>if new_env_cname is None:<EOL><INDENT>raise Exception("<STR_LIT>")<EOL><DEDENT>out("<STR_LIT>" + new_env_cname)<EOL>version_label = upload_application_archive(<EOL>helper, env_config, archive=args.archive, directory=args.directory, version_label=version_label)<EOL>helper.create_environment(new_env_name,<EOL>solution_stack_name=env_config.get('<STR_LIT>'),<EOL>cname_prefix=new_env_cname,<EOL>description=env_config.get('<STR_LIT:description>', None),<EOL>option_settings=option_settings,<EOL>version_label=version_label,<EOL>tier_name=tier_name,<EOL>tier_type=env_config.get('<STR_LIT>'),<EOL>tier_version=env_config.get('<STR_LIT>'))<EOL>helper.wait_for_environments(new_env_name, status='<STR_LIT>', health='<STR_LIT>', include_deleted=False)<EOL>old_env_name = helper.environment_name_for_cname(cname_prefix)<EOL>if old_env_name is None:<EOL><INDENT>raise Exception("<STR_LIT>" + cname_prefix)<EOL><DEDENT>out("<STR_LIT>" + old_env_name)<EOL>out("<STR_LIT>")<EOL>helper.swap_environment_cnames(old_env_name, new_env_name)<EOL>helper.wait_for_environments([old_env_name, new_env_name], status='<STR_LIT>', include_deleted=False)<EOL>if args.termination_delay:<EOL><INDENT>out("<STR_LIT>".format(args.termination_delay))<EOL>time.sleep(args.termination_delay)<EOL><DEDENT>out("<STR_LIT>".format(old_env_name))<EOL>helper.delete_environment(old_env_name)<EOL>helper.delete_unused_versions(versions_to_keep=int(get(config, '<STR_LIT>', <NUM_LIT:10>)))<EOL>


out("<STR_LIT>")<EOL>for stack in helper.list_available_solution_stacks():<EOL><INDENT>out("<STR_LIT:U+0020>"+str(stack))<EOL><DEDENT>return <NUM_LIT:0><EOL>


env_config = parse_env_config(config, args.environment)<EOL>environments_to_wait_for_term = []<EOL>environments = helper.get_environments()<EOL>for env in environments:<EOL><INDENT>if env['<STR_LIT>'] == args.environment:<EOL><INDENT>if env['<STR_LIT>'] != '<STR_LIT>':<EOL><INDENT>out("<STR_LIT>" + env['<STR_LIT>']<EOL>+ "<STR_LIT>"<EOL>+ env['<STR_LIT>'] + "<STR_LIT:)>")<EOL><DEDENT>else:<EOL><INDENT>out("<STR_LIT>"+env['<STR_LIT>'])<EOL>helper.delete_environment(env['<STR_LIT>'])<EOL>environments_to_wait_for_term.append(env['<STR_LIT>'])<EOL><DEDENT><DEDENT><DEDENT>if not args.dont_wait:<EOL><INDENT>helper.wait_for_environments(environments_to_wait_for_term,<EOL>status='<STR_LIT>',<EOL>include_deleted=True)<EOL><DEDENT>out("<STR_LIT>")<EOL>return <NUM_LIT:0><EOL>


parser.add_argument('<STR_LIT>', '<STR_LIT>',  help='<STR_LIT>', required=False, nargs='<STR_LIT:+>')<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', help='<STR_LIT>', action='<STR_LIT:store_true>')<EOL>


environments = []<EOL>if args.environment:<EOL><INDENT>for env_name in args.environment:<EOL><INDENT>environments.append(env_name)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for env_name, env_config in list(get(config, '<STR_LIT>').items()):<EOL><INDENT>environments.append(env_name)<EOL><DEDENT><DEDENT>wait_environments = []<EOL>for env_name in environments:<EOL><INDENT>env = parse_env_config(config, env_name)<EOL>option_settings = parse_option_settings(env.get('<STR_LIT>', {}))<EOL>helper.update_environment(env_name,<EOL>description=env.get('<STR_LIT:description>', None),<EOL>option_settings=option_settings,<EOL>tier_type=env.get('<STR_LIT>'),<EOL>tier_name=env.get('<STR_LIT>'),<EOL>tier_version=env.get('<STR_LIT>'))<EOL>wait_environments.append(env_name)<EOL><DEDENT>if not args.dont_wait:<EOL><INDENT>helper.wait_for_environments(wait_environments, health='<STR_LIT>', status='<STR_LIT>')<EOL><DEDENT>


parser.add_argument('<STR_LIT>', '<STR_LIT>', help='<STR_LIT>', required=True)<EOL>parser.add_argument('<STR_LIT>', '<STR_LIT>', help='<STR_LIT>', required=True)<EOL>

adds arguments for the swap urls command


out("<STR_LIT>" + str(self.app_name))<EOL>self.ebs.create_application(self.app_name, description=description)<EOL>

Creats an application and sets the helpers current
app_name to the created application


<EOL>environments = self.ebs.describe_environments(application_name=self.app_name, include_deleted=False)<EOL>environments = environments['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']<EOL>versions_in_use = []<EOL>for env in environments:<EOL><INDENT>versions_in_use.append(env['<STR_LIT>'])<EOL><DEDENT>versions = self.ebs.describe_application_versions(application_name=self.app_name)<EOL>versions = versions['<STR_LIT>']['<STR_LIT>'][<EOL>'<STR_LIT>']<EOL>versions = sorted(versions, reverse=True, key=functools.cmp_to_key(lambda x, y: (x['<STR_LIT>'] > y['<STR_LIT>']) - (x['<STR_LIT>'] < y['<STR_LIT>'])))<EOL>for version in versions[versions_to_keep:]:<EOL><INDENT>if version['<STR_LIT>'] in versions_in_use:<EOL><INDENT>out("<STR_LIT>" + version["<STR_LIT>"] + "<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>out("<STR_LIT>" + version["<STR_LIT>"])<EOL>self.ebs.delete_application_version(application_name=self.app_name,<EOL>version_label=version['<STR_LIT>'])<EOL>sleep(<NUM_LIT:2>)<EOL><DEDENT><DEDENT>


val = vals<EOL>for part in key.split('<STR_LIT:.>'):<EOL><INDENT>if isinstance(val, dict):<EOL><INDENT>val = val.get(part, None)<EOL>if val is None:<EOL><INDENT>return default_val<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return default_val<EOL><DEDENT><DEDENT>return val<EOL>


out("<STR_LIT>" + str(self.app_name))<EOL>self.ebs.delete_application(self.app_name, terminate_env_by_force=True)<EOL>


response = self.ebs.describe_applications(application_names=[self.app_name])<EOL>return len(response['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']) > <NUM_LIT:0><EOL>

Returns whether or not the given app_name exists


ret = []<EOL>for namespace, params in list(option_settings.items()):<EOL><INDENT>for key, value in list(params.items()):<EOL><INDENT>ret.append((namespace, key, value))<EOL><DEDENT><DEDENT>return ret<EOL>

Parses option_settings as they are defined in the configuration file


def deploy_version(self, environment_name, version_label):

out("<STR_LIT>" + str(version_label) + "<STR_LIT>" + str(environment_name))<EOL>self.ebs.update_environment(environment_name=environment_name, version_label=version_label)<EOL>


response = self.ebs.describe_environments(application_name=self.app_name, include_deleted=False)<EOL>return response['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']<EOL>


self.ebs.terminate_environment(environment_name=environment_name, terminate_resources=True)<EOL>


def swap_environment_cnames(self, from_env_name, to_env_name):

self.ebs.swap_environment_cnames(source_environment_name=from_env_name,<EOL>destination_environment_name=to_env_name)<EOL>


def update_environment(self, environment_name, description=None, option_settings=[], tier_type=None, tier_name=None,<EOL>tier_version='<STR_LIT:1.0>'):

out("<STR_LIT>" + str(environment_name))<EOL>messages = self.ebs.validate_configuration_settings(self.app_name, option_settings,<EOL>environment_name=environment_name)<EOL>messages = messages['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']<EOL>ok = True<EOL>for message in messages:<EOL><INDENT>if message['<STR_LIT>'] == '<STR_LIT:error>':<EOL><INDENT>ok = False<EOL><DEDENT>out("<STR_LIT:[>" + message['<STR_LIT>'] + "<STR_LIT>" + str(environment_name) + "<STR_LIT>"+ message['<STR_LIT>'] + "<STR_LIT::>" + message['<STR_LIT>'] + "<STR_LIT>" + message['<STR_LIT>'])<EOL><DEDENT>self.ebs.update_environment(<EOL>environment_name=environment_name,<EOL>description=description,<EOL>option_settings=option_settings,<EOL>tier_type=tier_type,<EOL>tier_name=tier_name,<EOL>tier_version=tier_version)<EOL>


def __init__(self, aws, wait_time_secs, app_name=None,):

self.aws = aws<EOL>self.ebs = connect_to_region(aws.region, aws_access_key_id=aws.access_key,<EOL>aws_secret_access_key=aws.secret_key,<EOL>security_token=aws.security_token)<EOL>self.s3 = S3Connection(<EOL>aws_access_key_id=aws.access_key, <EOL>aws_secret_access_key=aws.secret_key, <EOL>security_token=aws.security_token,<EOL>host=(lambda r: '<STR_LIT>' if r == '<STR_LIT>' else '<STR_LIT>' + r + '<STR_LIT>')(aws.region))<EOL>self.app_name = app_name<EOL>self.wait_time_secs = wait_time_secs<EOL>


out("<STR_LIT>" + str(env_name))<EOL>self.ebs.rebuild_environment(environment_name=env_name)<EOL>


sys.stdout.write(message + "<STR_LIT:\n>")<EOL>sys.stdout.flush()<EOL>


rule = string.letters + string.digits<EOL>str = random.sample(rule, <NUM_LIT:16>)<EOL>return "<STR_LIT>".join(str)<EOL>

随机生成16位字符串
        @return: 16位字符串


raise exception_class(message)<EOL>


def getSHA1(self, token, timestamp, nonce, encrypt):

try:<EOL><INDENT>sortlist = [token, timestamp, nonce, encrypt]<EOL>sortlist.sort()<EOL>sha = hashlib.sha1()<EOL>sha.update("<STR_LIT>".join(sortlist))<EOL>return WXBizMsgCrypt_OK, sha.hexdigest()<EOL><DEDENT>except Exception:<EOL><INDENT>return WXBizMsgCrypt_ComputeSignature_Error, None<EOL><DEDENT>

用SHA1算法生成安全签名
        @param token:  票据
        @param timestamp: 时间戳
        @param encrypt: 密文
        @param nonce: 随机字符串
        @return: 安全签名


def generate(self, encrypt, signature, timestamp, nonce):

resp_dict = {<EOL>'<STR_LIT>': encrypt,<EOL>'<STR_LIT>': signature,<EOL>'<STR_LIT>': timestamp,<EOL>'<STR_LIT>': nonce,<EOL>}<EOL>resp_xml = self.AES_TEXT_RESPONSE_TEMPLATE % resp_dict<EOL>return resp_xml<EOL>

生成xml消息
        @param encrypt: 加密后的消息密文
        @param signature: 安全签名
        @param timestamp: 时间戳
        @param nonce: 随机字符串
        @return: 生成的xml字符串


def md_table(table, *, padding=DEFAULT_PADDING, divider='<STR_LIT:|>', header_div='<STR_LIT:->'):

table = normalize_cols(table)<EOL>table = pad_cells(table)<EOL>header = table[<NUM_LIT:0>]<EOL>body = table[<NUM_LIT:1>:]<EOL>col_widths = [len(cell) for cell in header]<EOL>horiz = horiz_div(col_widths, header_div, divider, padding)<EOL>header = add_dividers(header, divider, padding)<EOL>body = [add_dividers(row, divider, padding) for row in body]<EOL>table = [header, horiz]<EOL>table.extend(body)<EOL>table = [row.rstrip() for row in table]<EOL>return '<STR_LIT:\n>'.join(table)<EOL>

Convert a 2D array of items into a Markdown table.

padding: the number of padding spaces on either side of each divider
divider: the vertical divider to place between columns
header_div: the horizontal divider to place between the header row and
    body cells


self.vis.delete()<EOL>v = self.vis["<STR_LIT>"]<EOL>filename = os.path.join(meshcat.viewer_assets_path(),<EOL>"<STR_LIT>")<EOL>with open(filename, "<STR_LIT:r>") as f:<EOL><INDENT>fio = StringIO(f.read())<EOL>v["<STR_LIT>"].set_object(g.Mesh(g.ObjMeshGeometry.from_stream(fio)))<EOL>v["<STR_LIT>"].set_transform(tf.translation_matrix([<NUM_LIT:0>, <NUM_LIT:0.0>, <NUM_LIT:0>]))<EOL><DEDENT>filename = os.path.join(meshcat.viewer_assets_path(),<EOL>"<STR_LIT>")<EOL>with open(filename, "<STR_LIT:r>") as f:<EOL><INDENT>fio = StringIO(f.read())<EOL>v["<STR_LIT>"].set_object(g.Mesh(g.StlMeshGeometry.from_stream(fio)))<EOL>v["<STR_LIT>"].set_transform(tf.translation_matrix([<NUM_LIT:0>, -<NUM_LIT:0.5>, <NUM_LIT:0>]))<EOL><DEDENT>filename = os.path.join(meshcat.viewer_assets_path(),<EOL>"<STR_LIT>")<EOL>with open(filename, "<STR_LIT:rb>") as f:<EOL><INDENT>fio = BytesIO(f.read())<EOL>v["<STR_LIT>"].set_object(g.Mesh(g.StlMeshGeometry.from_stream(fio)))<EOL>v["<STR_LIT>"].set_transform(tf.translation_matrix([<NUM_LIT:0>, -<NUM_LIT:1.0>, <NUM_LIT:0>]))<EOL><DEDENT>filename = os.path.join(meshcat.viewer_assets_path(),<EOL>"<STR_LIT>")<EOL>with open(filename, "<STR_LIT:r>") as f:<EOL><INDENT>fio = StringIO(f.read())<EOL>v["<STR_LIT>"].set_object(g.Mesh(g.DaeMeshGeometry.from_stream(fio)))<EOL>v["<STR_LIT>"].set_transform(tf.translation_matrix([<NUM_LIT:0>, -<NUM_LIT>, <NUM_LIT:0>]))<EOL><DEDENT>

Applications using meshcat may already have meshes loaded in memory. It is
        more efficient to load these meshes with streams rather than going to and then
        from a file on disk. To test this we are importing meshes from disk and
        converting them into streams so it kind of defeats the intended purpose! But at
        least it tests the functionality.


def convert_frames_to_video(tar_file_path, output_path="<STR_LIT>", framerate=<NUM_LIT>, overwrite=False):

output_path = os.path.abspath(output_path)<EOL>if os.path.isfile(output_path) and not overwrite:<EOL><INDENT>raise ValueError("<STR_LIT>".format(output_path))<EOL><DEDENT>with tempfile.TemporaryDirectory() as tmp_dir:<EOL><INDENT>with tarfile.open(tar_file_path) as tar:<EOL><INDENT>tar.extractall(tmp_dir)<EOL><DEDENT>args = ["<STR_LIT>",<EOL>"<STR_LIT>", str(framerate),<EOL>"<STR_LIT>", r"<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>", "<STR_LIT>"]<EOL>if overwrite:<EOL><INDENT>args.append("<STR_LIT>")<EOL><DEDENT>args.append(output_path)<EOL>try:<EOL><INDENT>subprocess.check_call(args, cwd=tmp_dir)<EOL><DEDENT>except subprocess.CalledProcessError as e:<EOL><INDENT>print("""<STR_LIT>""")<EOL>raise<EOL><DEDENT><DEDENT>print("<STR_LIT>".format(output_path))<EOL>return output_path<EOL>

Try to convert a tar file containing a sequence of frames saved by the
meshcat viewer into a single video file.

This relies on having `ffmpeg` installed on your system.


M = numpy.identity(<NUM_LIT:4>)<EOL>M[:<NUM_LIT:3>, <NUM_LIT:3>] = direction[:<NUM_LIT:3>]<EOL>return M<EOL>

Return matrix to translate by direction vector.

    >>> v = numpy.random.random(3) - 0.5
    >>> numpy.allclose(v, translation_matrix(v)[:3, 3])
    True


return quaternion_matrix(self._qnow)<EOL>


self._constrain = bool(value)<EOL>


def scale_matrix(factor, origin=None, direction=None):

if direction is None:<EOL><INDENT>M = numpy.diag([factor, factor, factor, <NUM_LIT:1.0>])<EOL>if origin is not None:<EOL><INDENT>M[:<NUM_LIT:3>, <NUM_LIT:3>] = origin[:<NUM_LIT:3>]<EOL>M[:<NUM_LIT:3>, <NUM_LIT:3>] *= <NUM_LIT:1.0> - factor<EOL><DEDENT><DEDENT>else:<EOL><INDENT>direction = unit_vector(direction[:<NUM_LIT:3>])<EOL>factor = <NUM_LIT:1.0> - factor<EOL>M = numpy.identity(<NUM_LIT:4>)<EOL>M[:<NUM_LIT:3>, :<NUM_LIT:3>] -= factor * numpy.outer(direction, direction)<EOL>if origin is not None:<EOL><INDENT>M[:<NUM_LIT:3>, <NUM_LIT:3>] = (factor * numpy.dot(origin[:<NUM_LIT:3>], direction)) * direction<EOL><DEDENT><DEDENT>return M<EOL>

Return matrix to scale by factor around origin in direction.

    Use factor -1 for point symmetry.

    >>> v = (numpy.random.rand(4, 5) - 0.5) * 20
    >>> v[3] = 1
    >>> S = scale_matrix(-1.234)
    >>> numpy.allclose(numpy.dot(S, v)[:3], -1.234*v[:3])
    True
    >>> factor = random.random() * 10 - 5
    >>> origin = numpy.random.random(3) - 0.5
    >>> direct = numpy.random.random(3) - 0.5
    >>> S = scale_matrix(factor, origin)
    >>> S = scale_matrix(factor, origin, direct)


return self._constrain<EOL>


M = numpy.array(matrix, dtype=numpy.float64, copy=False)<EOL>M33 = M[:<NUM_LIT:3>, :<NUM_LIT:3>]<EOL>w, V = numpy.linalg.eig(M)<EOL>i = numpy.where(abs(numpy.real(w) - <NUM_LIT:1.0>) < <NUM_LIT>)[<NUM_LIT:0>]<EOL>if not pseudo and len(i):<EOL><INDENT>point = numpy.real(V[:, i[-<NUM_LIT:1>]]).squeeze()<EOL>point /= point[<NUM_LIT:3>]<EOL>w, V = numpy.linalg.eig(M33)<EOL>i = numpy.where(abs(numpy.real(w)) < <NUM_LIT>)[<NUM_LIT:0>]<EOL>if not len(i):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>direction = numpy.real(V[:, i[<NUM_LIT:0>]]).squeeze()<EOL>direction /= vector_norm(direction)<EOL>w, V = numpy.linalg.eig(M33.T)<EOL>i = numpy.where(abs(numpy.real(w)) < <NUM_LIT>)[<NUM_LIT:0>]<EOL>if len(i):<EOL><INDENT>normal = numpy.real(V[:, i[<NUM_LIT:0>]]).squeeze()<EOL>normal /= vector_norm(normal)<EOL>return point, normal, direction, None, False<EOL><DEDENT>else:<EOL><INDENT>return point, direction, None, None, False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>i = numpy.where(abs(numpy.real(w)) > <NUM_LIT>)[<NUM_LIT:0>]<EOL>if not len(i):<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>")<EOL><DEDENT>point = numpy.real(V[:, i[-<NUM_LIT:1>]]).squeeze()<EOL>point /= point[<NUM_LIT:3>]<EOL>normal = - M[<NUM_LIT:3>, :<NUM_LIT:3>]<EOL>perspective = M[:<NUM_LIT:3>, <NUM_LIT:3>] / numpy.dot(point[:<NUM_LIT:3>], normal)<EOL>if pseudo:<EOL><INDENT>perspective -= normal<EOL><DEDENT>return point, normal, None, perspective, pseudo<EOL><DEDENT>

Return projection plane and perspective point from projection matrix.

    Return values are same as arguments for projection_matrix function:
    point, normal, direction, perspective, and pseudo.

    >>> point = numpy.random.random(3) - 0.5
    >>> normal = numpy.random.random(3) - 0.5
    >>> direct = numpy.random.random(3) - 0.5
    >>> persp = numpy.random.random(3) - 0.5
    >>> P0 = projection_matrix(point, normal)
    >>> result = projection_from_matrix(P0)
    >>> P1 = projection_matrix(*result)
    >>> is_same_transform(P0, P1)
    True
    >>> P0 = projection_matrix(point, normal, direct)
    >>> result = projection_from_matrix(P0)
    >>> P1 = projection_matrix(*result)
    >>> is_same_transform(P0, P1)
    True
    >>> P0 = projection_matrix(point, normal, perspective=persp, pseudo=False)
    >>> result = projection_from_matrix(P0, pseudo=False)
    >>> P1 = projection_matrix(*result)
    >>> is_same_transform(P0, P1)
    True
    >>> P0 = projection_matrix(point, normal, perspective=persp, pseudo=True)
    >>> result = projection_from_matrix(P0, pseudo=True)
    >>> P1 = projection_matrix(*result)
    >>> is_same_transform(P0, P1)
    True


if axes is None:<EOL><INDENT>self._axes = None<EOL><DEDENT>else:<EOL><INDENT>self._axes = [unit_vector(axis) for axis in axes]<EOL><DEDENT>


matrix0 = numpy.array(matrix0, dtype=numpy.float64, copy=True)<EOL>matrix0 /= matrix0[<NUM_LIT:3>, <NUM_LIT:3>]<EOL>matrix1 = numpy.array(matrix1, dtype=numpy.float64, copy=True)<EOL>matrix1 /= matrix1[<NUM_LIT:3>, <NUM_LIT:3>]<EOL>return numpy.allclose(matrix0, matrix1)<EOL>

Return True if two matrices perform same transformation.

    >>> is_same_transform(numpy.identity(4), numpy.identity(4))
    True
    >>> is_same_transform(numpy.identity(4), random_rotation_matrix())
    False


M = numpy.array(matrix, dtype=numpy.float64, copy=False)<EOL>w, V = numpy.linalg.eig(M[:<NUM_LIT:3>, :<NUM_LIT:3>])<EOL>i = numpy.where(abs(numpy.real(w) + <NUM_LIT:1.0>) < <NUM_LIT>)[<NUM_LIT:0>]<EOL>if not len(i):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>normal = numpy.real(V[:, i[<NUM_LIT:0>]]).squeeze()<EOL>w, V = numpy.linalg.eig(M)<EOL>i = numpy.where(abs(numpy.real(w) - <NUM_LIT:1.0>) < <NUM_LIT>)[<NUM_LIT:0>]<EOL>if not len(i):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>point = numpy.real(V[:, i[-<NUM_LIT:1>]]).squeeze()<EOL>point /= point[<NUM_LIT:3>]<EOL>return point, normal<EOL>

Return mirror plane point and normal vector from reflection matrix.

    >>> v0 = numpy.random.random(3) - 0.5
    >>> v1 = numpy.random.random(3) - 0.5
    >>> M0 = reflection_matrix(v0, v1)
    >>> point, normal = reflection_from_matrix(M0)
    >>> M1 = reflection_matrix(point, normal)
    >>> is_same_transform(M0, M1)
    True


M = numpy.array(matrix, dtype=numpy.float64, copy=False)[:<NUM_LIT:4>, :<NUM_LIT:4>]<EOL>if isprecise:<EOL><INDENT>q = numpy.empty((<NUM_LIT:4>, ))<EOL>t = numpy.trace(M)<EOL>if t > M[<NUM_LIT:3>, <NUM_LIT:3>]:<EOL><INDENT>q[<NUM_LIT:0>] = t<EOL>q[<NUM_LIT:3>] = M[<NUM_LIT:1>, <NUM_LIT:0>] - M[<NUM_LIT:0>, <NUM_LIT:1>]<EOL>q[<NUM_LIT:2>] = M[<NUM_LIT:0>, <NUM_LIT:2>] - M[<NUM_LIT:2>, <NUM_LIT:0>]<EOL>q[<NUM_LIT:1>] = M[<NUM_LIT:2>, <NUM_LIT:1>] - M[<NUM_LIT:1>, <NUM_LIT:2>]<EOL><DEDENT>else:<EOL><INDENT>i, j, k = <NUM_LIT:1>, <NUM_LIT:2>, <NUM_LIT:3><EOL>if M[<NUM_LIT:1>, <NUM_LIT:1>] > M[<NUM_LIT:0>, <NUM_LIT:0>]:<EOL><INDENT>i, j, k = <NUM_LIT:2>, <NUM_LIT:3>, <NUM_LIT:1><EOL><DEDENT>if M[<NUM_LIT:2>, <NUM_LIT:2>] > M[i, i]:<EOL><INDENT>i, j, k = <NUM_LIT:3>, <NUM_LIT:1>, <NUM_LIT:2><EOL><DEDENT>t = M[i, i] - (M[j, j] + M[k, k]) + M[<NUM_LIT:3>, <NUM_LIT:3>]<EOL>q[i] = t<EOL>q[j] = M[i, j] + M[j, i]<EOL>q[k] = M[k, i] + M[i, k]<EOL>q[<NUM_LIT:3>] = M[k, j] - M[j, k]<EOL><DEDENT>q *= <NUM_LIT:0.5> / math.sqrt(t * M[<NUM_LIT:3>, <NUM_LIT:3>])<EOL><DEDENT>else:<EOL><INDENT>m00 = M[<NUM_LIT:0>, <NUM_LIT:0>]<EOL>m01 = M[<NUM_LIT:0>, <NUM_LIT:1>]<EOL>m02 = M[<NUM_LIT:0>, <NUM_LIT:2>]<EOL>m10 = M[<NUM_LIT:1>, <NUM_LIT:0>]<EOL>m11 = M[<NUM_LIT:1>, <NUM_LIT:1>]<EOL>m12 = M[<NUM_LIT:1>, <NUM_LIT:2>]<EOL>m20 = M[<NUM_LIT:2>, <NUM_LIT:0>]<EOL>m21 = M[<NUM_LIT:2>, <NUM_LIT:1>]<EOL>m22 = M[<NUM_LIT:2>, <NUM_LIT:2>]<EOL>K = numpy.array([[m00-m11-m22, <NUM_LIT:0.0>,         <NUM_LIT:0.0>,         <NUM_LIT:0.0>],<EOL>[m01+m10,     m11-m00-m22, <NUM_LIT:0.0>,         <NUM_LIT:0.0>],<EOL>[m02+m20,     m12+m21,     m22-m00-m11, <NUM_LIT:0.0>],<EOL>[m21-m12,     m02-m20,     m10-m01,     m00+m11+m22]])<EOL>K /= <NUM_LIT><EOL>w, V = numpy.linalg.eigh(K)<EOL>q = V[[<NUM_LIT:3>, <NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:2>], numpy.argmax(w)]<EOL><DEDENT>if q[<NUM_LIT:0>] < <NUM_LIT:0.0>:<EOL><INDENT>numpy.negative(q, q)<EOL><DEDENT>return q<EOL>

Return quaternion from rotation matrix.

    If isprecise is True, the input matrix is assumed to be a precise rotation
    matrix and a faster algorithm is used.

    >>> q = quaternion_from_matrix(numpy.identity(4), True)
    >>> numpy.allclose(q, [1, 0, 0, 0])
    True
    >>> q = quaternion_from_matrix(numpy.diag([1, -1, -1, 1]))
    >>> numpy.allclose(q, [0, 1, 0, 0]) or numpy.allclose(q, [0, -1, 0, 0])
    True
    >>> R = rotation_matrix(0.123, (1, 2, 3))
    >>> q = quaternion_from_matrix(R, True)
    >>> numpy.allclose(q, [0.9981095, 0.0164262, 0.0328524, 0.0492786])
    True
    >>> R = [[-0.545, 0.797, 0.260, 0], [0.733, 0.603, -0.313, 0],
    ...      [-0.407, 0.021, -0.913, 0], [0, 0, 0, 1]]
    >>> q = quaternion_from_matrix(R)
    >>> numpy.allclose(q, [0.19069, 0.43736, 0.87485, -0.083611])
    True
    >>> R = [[0.395, 0.362, 0.843, 0], [-0.626, 0.796, -0.056, 0],
    ...      [-0.677, -0.498, 0.529, 0], [0, 0, 0, 1]]
    >>> q = quaternion_from_matrix(R)
    >>> numpy.allclose(q, [0.82336615, -0.13610694, 0.46344705, -0.29792603])
    True
    >>> R = random_rotation_matrix()
    >>> q = quaternion_from_matrix(R)
    >>> is_same_transform(R, quaternion_matrix(q))
    True
    >>> R = euler_matrix(0.0, 0.0, numpy.pi/2.0)
    >>> numpy.allclose(quaternion_from_matrix(R, isprecise=False),
    ...                quaternion_from_matrix(R, isprecise=True))
    True


def vector_norm(data, axis=None, out=None):

data = numpy.array(data, dtype=numpy.float64, copy=True)<EOL>if out is None:<EOL><INDENT>if data.ndim == <NUM_LIT:1>:<EOL><INDENT>return math.sqrt(numpy.dot(data, data))<EOL><DEDENT>data *= data<EOL>out = numpy.atleast_1d(numpy.sum(data, axis=axis))<EOL>numpy.sqrt(out, out)<EOL>return out<EOL><DEDENT>else:<EOL><INDENT>data *= data<EOL>numpy.sum(data, axis=axis, out=out)<EOL>numpy.sqrt(out, out)<EOL><DEDENT>

Return length, i.e. Euclidean norm, of ndarray along axis.

    >>> v = numpy.random.random(3)
    >>> n = vector_norm(v)
    >>> numpy.allclose(n, numpy.linalg.norm(v))
    True
    >>> v = numpy.random.rand(6, 5, 3)
    >>> n = vector_norm(v, axis=-1)
    >>> numpy.allclose(n, numpy.sqrt(numpy.sum(v*v, axis=2)))
    True
    >>> n = vector_norm(v, axis=1)
    >>> numpy.allclose(n, numpy.sqrt(numpy.sum(v*v, axis=1)))
    True
    >>> v = numpy.random.rand(5, 4, 3)
    >>> n = numpy.empty((5, 3))
    >>> vector_norm(v, axis=1, out=n)
    >>> numpy.allclose(n, numpy.sqrt(numpy.sum(v*v, axis=1)))
    True
    >>> vector_norm([])
    0.0
    >>> vector_norm([1])
    1.0


def unit_vector(data, axis=None, out=None):

if out is None:<EOL><INDENT>data = numpy.array(data, dtype=numpy.float64, copy=True)<EOL>if data.ndim == <NUM_LIT:1>:<EOL><INDENT>data /= math.sqrt(numpy.dot(data, data))<EOL>return data<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if out is not data:<EOL><INDENT>out[:] = numpy.array(data, copy=False)<EOL><DEDENT>data = out<EOL><DEDENT>length = numpy.atleast_1d(numpy.sum(data*data, axis))<EOL>numpy.sqrt(length, length)<EOL>if axis is not None:<EOL><INDENT>length = numpy.expand_dims(length, axis)<EOL><DEDENT>data /= length<EOL>if out is None:<EOL><INDENT>return data<EOL><DEDENT>

Return ndarray normalized by length, i.e. Euclidean norm, along axis.

    >>> v0 = numpy.random.random(3)
    >>> v1 = unit_vector(v0)
    >>> numpy.allclose(v1, v0 / numpy.linalg.norm(v0))
    True
    >>> v0 = numpy.random.rand(5, 4, 3)
    >>> v1 = unit_vector(v0, axis=-1)
    >>> v2 = v0 / numpy.expand_dims(numpy.sqrt(numpy.sum(v0*v0, axis=2)), 2)
    >>> numpy.allclose(v1, v2)
    True
    >>> v1 = unit_vector(v0, axis=1)
    >>> v2 = v0 / numpy.expand_dims(numpy.sqrt(numpy.sum(v0*v0, axis=1)), 1)
    >>> numpy.allclose(v1, v2)
    True
    >>> v1 = numpy.empty((5, 4, 3))
    >>> unit_vector(v0, axis=1, out=v1)
    >>> numpy.allclose(v1, v2)
    True
    >>> list(unit_vector([]))
    []
    >>> list(unit_vector([1]))
    [1.0]


w0, x0, y0, z0 = quaternion0<EOL>w1, x1, y1, z1 = quaternion1<EOL>return numpy.array([-x1*x0 - y1*y0 - z1*z0 + w1*w0,<EOL>x1*w0 + y1*z0 - z1*y0 + w1*x0,<EOL>-x1*z0 + y1*w0 + z1*x0 + w1*y0,<EOL>x1*y0 - y1*x0 + z1*w0 + w1*z0], dtype=numpy.float64)<EOL>

Return multiplication of two quaternions.

    >>> q = quaternion_multiply([4, 1, -2, 3], [8, -5, 6, 7])
    >>> numpy.allclose(q, [28, -44, -14, 48])
    True


def affine_matrix_from_points(v0, v1, shear=True, scale=True, usesvd=True):

v0 = numpy.array(v0, dtype=numpy.float64, copy=True)<EOL>v1 = numpy.array(v1, dtype=numpy.float64, copy=True)<EOL>ndims = v0.shape[<NUM_LIT:0>]<EOL>if ndims < <NUM_LIT:2> or v0.shape[<NUM_LIT:1>] < ndims or v0.shape != v1.shape:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>t0 = -numpy.mean(v0, axis=<NUM_LIT:1>)<EOL>M0 = numpy.identity(ndims+<NUM_LIT:1>)<EOL>M0[:ndims, ndims] = t0<EOL>v0 += t0.reshape(ndims, <NUM_LIT:1>)<EOL>t1 = -numpy.mean(v1, axis=<NUM_LIT:1>)<EOL>M1 = numpy.identity(ndims+<NUM_LIT:1>)<EOL>M1[:ndims, ndims] = t1<EOL>v1 += t1.reshape(ndims, <NUM_LIT:1>)<EOL>if shear:<EOL><INDENT>A = numpy.concatenate((v0, v1), axis=<NUM_LIT:0>)<EOL>u, s, vh = numpy.linalg.svd(A.T)<EOL>vh = vh[:ndims].T<EOL>B = vh[:ndims]<EOL>C = vh[ndims:<NUM_LIT:2>*ndims]<EOL>t = numpy.dot(C, numpy.linalg.pinv(B))<EOL>t = numpy.concatenate((t, numpy.zeros((ndims, <NUM_LIT:1>))), axis=<NUM_LIT:1>)<EOL>M = numpy.vstack((t, ((<NUM_LIT:0.0>,)*ndims) + (<NUM_LIT:1.0>,)))<EOL><DEDENT>elif usesvd or ndims != <NUM_LIT:3>:<EOL><INDENT>u, s, vh = numpy.linalg.svd(numpy.dot(v1, v0.T))<EOL>R = numpy.dot(u, vh)<EOL>if numpy.linalg.det(R) < <NUM_LIT:0.0>:<EOL><INDENT>R -= numpy.outer(u[:, ndims-<NUM_LIT:1>], vh[ndims-<NUM_LIT:1>, :]*<NUM_LIT>)<EOL>s[-<NUM_LIT:1>] *= -<NUM_LIT:1.0><EOL><DEDENT>M = numpy.identity(ndims+<NUM_LIT:1>)<EOL>M[:ndims, :ndims] = R<EOL><DEDENT>else:<EOL><INDENT>xx, yy, zz = numpy.sum(v0 * v1, axis=<NUM_LIT:1>)<EOL>xy, yz, zx = numpy.sum(v0 * numpy.roll(v1, -<NUM_LIT:1>, axis=<NUM_LIT:0>), axis=<NUM_LIT:1>)<EOL>xz, yx, zy = numpy.sum(v0 * numpy.roll(v1, -<NUM_LIT:2>, axis=<NUM_LIT:0>), axis=<NUM_LIT:1>)<EOL>N = [[xx+yy+zz, <NUM_LIT:0.0>,      <NUM_LIT:0.0>,      <NUM_LIT:0.0>],<EOL>[yz-zy,    xx-yy-zz, <NUM_LIT:0.0>,      <NUM_LIT:0.0>],<EOL>[zx-xz,    xy+yx,    yy-xx-zz, <NUM_LIT:0.0>],<EOL>[xy-yx,    zx+xz,    yz+zy,    zz-xx-yy]]<EOL>w, V = numpy.linalg.eigh(N)<EOL>q = V[:, numpy.argmax(w)]<EOL>q /= vector_norm(q)  <EOL>M = quaternion_matrix(q)<EOL><DEDENT>if scale and not shear:<EOL><INDENT>v0 *= v0<EOL>v1 *= v1<EOL>M[:ndims, :ndims] *= math.sqrt(numpy.sum(v1) / numpy.sum(v0))<EOL><DEDENT>M = numpy.dot(numpy.linalg.inv(M1), numpy.dot(M, M0))<EOL>M /= M[ndims, ndims]<EOL>return M<EOL>

Return affine transform matrix to register two point sets.

    v0 and v1 are shape (ndims, *) arrays of at least ndims non-homogeneous
    coordinates, where ndims is the dimensionality of the coordinate space.

    If shear is False, a similarity transformation matrix is returned.
    If also scale is False, a rigid/Euclidean transformation matrix
    is returned.

    By default the algorithm by Hartley and Zissermann [15] is used.
    If usesvd is True, similarity and Euclidean transformation matrices
    are calculated by minimizing the weighted sum of squared deviations
    (RMSD) according to the algorithm by Kabsch [8].
    Otherwise, and if ndims is 3, the quaternion based algorithm by Horn [9]
    is used, which is slower when using this Python implementation.

    The returned matrix performs rotation, translation and uniform scaling
    (if specified).

    >>> v0 = [[0, 1031, 1031, 0], [0, 0, 1600, 1600]]
    >>> v1 = [[675, 826, 826, 677], [55, 52, 281, 277]]
    >>> affine_matrix_from_points(v0, v1)
    array([[   0.14549,    0.00062,  675.50008],
           [   0.00048,    0.14094,   53.24971],
           [   0.     ,    0.     ,    1.     ]])
    >>> T = translation_matrix(numpy.random.random(3)-0.5)
    >>> R = random_rotation_matrix(numpy.random.random(3))
    >>> S = scale_matrix(random.random())
    >>> M = concatenate_matrices(T, R, S)
    >>> v0 = (numpy.random.rand(4, 100) - 0.5) * 20
    >>> v0[3] = 1
    >>> v1 = numpy.dot(M, v0)
    >>> v0[:3] += numpy.random.normal(0, 1e-8, 300).reshape(3, -1)
    >>> M = affine_matrix_from_points(v0[:3], v1[:3])
    >>> numpy.allclose(v1, numpy.dot(M, v0))
    True

    More examples in superimposition_matrix()


self._radius = float(radius)<EOL>self._center[<NUM_LIT:0>] = center[<NUM_LIT:0>]<EOL>self._center[<NUM_LIT:1>] = center[<NUM_LIT:1>]<EOL>

Place Arcball, e.g. when window size changes.

        center : sequence[2]
            Window coordinates of trackball center.
        radius : float
            Radius of trackball in window coordinates.


v = numpy.array(point, dtype=numpy.float64, copy=True)<EOL>a = numpy.array(axis, dtype=numpy.float64, copy=True)<EOL>v -= a * numpy.dot(a, v)  <EOL>n = vector_norm(v)<EOL>if n > _EPS:<EOL><INDENT>if v[<NUM_LIT:2>] < <NUM_LIT:0.0>:<EOL><INDENT>numpy.negative(v, v)<EOL><DEDENT>v /= n<EOL>return v<EOL><DEDENT>if a[<NUM_LIT:2>] == <NUM_LIT:1.0>:<EOL><INDENT>return numpy.array([<NUM_LIT:1.0>, <NUM_LIT:0.0>, <NUM_LIT:0.0>])<EOL><DEDENT>return unit_vector([-a[<NUM_LIT:1>], a[<NUM_LIT:0>], <NUM_LIT:0.0>])<EOL>

Return sphere point perpendicular to axis.


def arcball_map_to_sphere(point, center, radius):

v0 = (point[<NUM_LIT:0>] - center[<NUM_LIT:0>]) / radius<EOL>v1 = (center[<NUM_LIT:1>] - point[<NUM_LIT:1>]) / radius<EOL>n = v0*v0 + v1*v1<EOL>if n > <NUM_LIT:1.0>:<EOL><INDENT>n = math.sqrt(n)<EOL>return numpy.array([v0/n, v1/n, <NUM_LIT:0.0>])<EOL><DEDENT>else:<EOL><INDENT>return numpy.array([v0, v1, math.sqrt(<NUM_LIT:1.0> - n)])<EOL><DEDENT>

Return unit sphere coordinates from window coordinates.


return numpy.linalg.inv(matrix)<EOL>

Return inverse of square transformation matrix.

    >>> M0 = random_rotation_matrix()
    >>> M1 = inverse_matrix(M0.T)
    >>> numpy.allclose(M1, numpy.linalg.inv(M0.T))
    True
    >>> for size in range(1, 7):
    ...     M0 = numpy.random.rand(size, size)
    ...     M1 = inverse_matrix(M0)
    ...     if not numpy.allclose(M1, numpy.linalg.inv(M0)): print(size)


q = quaternion_slerp(self._qpre, self._qnow, <NUM_LIT>+acceleration, False)<EOL>self._qpre, self._qnow = self._qnow, q<EOL>

Continue rotation in direction of last drag.


M = numpy.identity(<NUM_LIT:4>)<EOL>for i in matrices:<EOL><INDENT>M = numpy.dot(M, i)<EOL><DEDENT>return M<EOL>

Return concatenation of series of transformation matrices.

    >>> M = numpy.random.rand(16).reshape((4, 4)) - 0.5
    >>> numpy.allclose(M, concatenate_matrices(M))
    True
    >>> numpy.allclose(numpy.dot(M, M.T), concatenate_matrices(M, M.T))
    True


def vector_product(v0, v1, axis=<NUM_LIT:0>):

return numpy.cross(v0, v1, axis=axis)<EOL>


M = numpy.array(matrix, dtype=numpy.float64, copy=True).T<EOL>if abs(M[<NUM_LIT:3>, <NUM_LIT:3>]) < _EPS:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>M /= M[<NUM_LIT:3>, <NUM_LIT:3>]<EOL>P = M.copy()<EOL>P[:, <NUM_LIT:3>] = <NUM_LIT:0.0>, <NUM_LIT:0.0>, <NUM_LIT:0.0>, <NUM_LIT:1.0><EOL>if not numpy.linalg.det(P):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>scale = numpy.zeros((<NUM_LIT:3>, ))<EOL>shear = [<NUM_LIT:0.0>, <NUM_LIT:0.0>, <NUM_LIT:0.0>]<EOL>angles = [<NUM_LIT:0.0>, <NUM_LIT:0.0>, <NUM_LIT:0.0>]<EOL>if any(abs(M[:<NUM_LIT:3>, <NUM_LIT:3>]) > _EPS):<EOL><INDENT>perspective = numpy.dot(M[:, <NUM_LIT:3>], numpy.linalg.inv(P.T))<EOL>M[:, <NUM_LIT:3>] = <NUM_LIT:0.0>, <NUM_LIT:0.0>, <NUM_LIT:0.0>, <NUM_LIT:1.0><EOL><DEDENT>else:<EOL><INDENT>perspective = numpy.array([<NUM_LIT:0.0>, <NUM_LIT:0.0>, <NUM_LIT:0.0>, <NUM_LIT:1.0>])<EOL><DEDENT>translate = M[<NUM_LIT:3>, :<NUM_LIT:3>].copy()<EOL>M[<NUM_LIT:3>, :<NUM_LIT:3>] = <NUM_LIT:0.0><EOL>row = M[:<NUM_LIT:3>, :<NUM_LIT:3>].copy()<EOL>scale[<NUM_LIT:0>] = vector_norm(row[<NUM_LIT:0>])<EOL>row[<NUM_LIT:0>] /= scale[<NUM_LIT:0>]<EOL>shear[<NUM_LIT:0>] = numpy.dot(row[<NUM_LIT:0>], row[<NUM_LIT:1>])<EOL>row[<NUM_LIT:1>] -= row[<NUM_LIT:0>] * shear[<NUM_LIT:0>]<EOL>scale[<NUM_LIT:1>] = vector_norm(row[<NUM_LIT:1>])<EOL>row[<NUM_LIT:1>] /= scale[<NUM_LIT:1>]<EOL>shear[<NUM_LIT:0>] /= scale[<NUM_LIT:1>]<EOL>shear[<NUM_LIT:1>] = numpy.dot(row[<NUM_LIT:0>], row[<NUM_LIT:2>])<EOL>row[<NUM_LIT:2>] -= row[<NUM_LIT:0>] * shear[<NUM_LIT:1>]<EOL>shear[<NUM_LIT:2>] = numpy.dot(row[<NUM_LIT:1>], row[<NUM_LIT:2>])<EOL>row[<NUM_LIT:2>] -= row[<NUM_LIT:1>] * shear[<NUM_LIT:2>]<EOL>scale[<NUM_LIT:2>] = vector_norm(row[<NUM_LIT:2>])<EOL>row[<NUM_LIT:2>] /= scale[<NUM_LIT:2>]<EOL>shear[<NUM_LIT:1>:] /= scale[<NUM_LIT:2>]<EOL>if numpy.dot(row[<NUM_LIT:0>], numpy.cross(row[<NUM_LIT:1>], row[<NUM_LIT:2>])) < <NUM_LIT:0>:<EOL><INDENT>numpy.negative(scale, scale)<EOL>numpy.negative(row, row)<EOL><DEDENT>angles[<NUM_LIT:1>] = math.asin(-row[<NUM_LIT:0>, <NUM_LIT:2>])<EOL>if math.cos(angles[<NUM_LIT:1>]):<EOL><INDENT>angles[<NUM_LIT:0>] = math.atan2(row[<NUM_LIT:1>, <NUM_LIT:2>], row[<NUM_LIT:2>, <NUM_LIT:2>])<EOL>angles[<NUM_LIT:2>] = math.atan2(row[<NUM_LIT:0>, <NUM_LIT:1>], row[<NUM_LIT:0>, <NUM_LIT:0>])<EOL><DEDENT>else:<EOL><INDENT>angles[<NUM_LIT:0>] = math.atan2(-row[<NUM_LIT:2>, <NUM_LIT:1>], row[<NUM_LIT:1>, <NUM_LIT:1>])<EOL>angles[<NUM_LIT:2>] = <NUM_LIT:0.0><EOL><DEDENT>return scale, shear, angles, translate, perspective<EOL>

Return sequence of transformations from transformation matrix.

    matrix : array_like
        Non-degenerative homogeneous transformation matrix

    Return tuple of:
        scale : vector of 3 scaling factors
        shear : list of shear factors for x-y, x-z, y-z axes
        angles : list of Euler angles about static x, y, z axes
        translate : translation vector along x, y, z axes
        perspective : perspective partition of matrix

    Raise ValueError if matrix is of wrong type or degenerative.

    >>> T0 = translation_matrix([1, 2, 3])
    >>> scale, shear, angles, trans, persp = decompose_matrix(T0)
    >>> T1 = translation_matrix(trans)
    >>> numpy.allclose(T0, T1)
    True
    >>> S = scale_matrix(0.123)
    >>> scale, shear, angles, trans, persp = decompose_matrix(S)
    >>> scale[0]
    0.123
    >>> R0 = euler_matrix(1, 2, 3)
    >>> scale, shear, angles, trans, persp = decompose_matrix(R0)
    >>> R1 = euler_matrix(*angles)
    >>> numpy.allclose(R0, R1)
    True


def compose_matrix(scale=None, shear=None, angles=None, translate=None,<EOL>perspective=None):

M = numpy.identity(<NUM_LIT:4>)<EOL>if perspective is not None:<EOL><INDENT>P = numpy.identity(<NUM_LIT:4>)<EOL>P[<NUM_LIT:3>, :] = perspective[:<NUM_LIT:4>]<EOL>M = numpy.dot(M, P)<EOL><DEDENT>if translate is not None:<EOL><INDENT>T = numpy.identity(<NUM_LIT:4>)<EOL>T[:<NUM_LIT:3>, <NUM_LIT:3>] = translate[:<NUM_LIT:3>]<EOL>M = numpy.dot(M, T)<EOL><DEDENT>if angles is not None:<EOL><INDENT>R = euler_matrix(angles[<NUM_LIT:0>], angles[<NUM_LIT:1>], angles[<NUM_LIT:2>], '<STR_LIT>')<EOL>M = numpy.dot(M, R)<EOL><DEDENT>if shear is not None:<EOL><INDENT>Z = numpy.identity(<NUM_LIT:4>)<EOL>Z[<NUM_LIT:1>, <NUM_LIT:2>] = shear[<NUM_LIT:2>]<EOL>Z[<NUM_LIT:0>, <NUM_LIT:2>] = shear[<NUM_LIT:1>]<EOL>Z[<NUM_LIT:0>, <NUM_LIT:1>] = shear[<NUM_LIT:0>]<EOL>M = numpy.dot(M, Z)<EOL><DEDENT>if scale is not None:<EOL><INDENT>S = numpy.identity(<NUM_LIT:4>)<EOL>S[<NUM_LIT:0>, <NUM_LIT:0>] = scale[<NUM_LIT:0>]<EOL>S[<NUM_LIT:1>, <NUM_LIT:1>] = scale[<NUM_LIT:1>]<EOL>S[<NUM_LIT:2>, <NUM_LIT:2>] = scale[<NUM_LIT:2>]<EOL>M = numpy.dot(M, S)<EOL><DEDENT>M /= M[<NUM_LIT:3>, <NUM_LIT:3>]<EOL>return M<EOL>

Return transformation matrix from sequence of transformations.

    This is the inverse of the decompose_matrix function.

    Sequence of transformations:
        scale : vector of 3 scaling factors
        shear : list of shear factors for x-y, x-z, y-z axes
        angles : list of Euler angles about static x, y, z axes
        translate : translation vector along x, y, z axes
        perspective : perspective partition of matrix

    >>> scale = numpy.random.random(3) - 0.5
    >>> shear = numpy.random.random(3) - 0.5
    >>> angles = (numpy.random.random(3) - 0.5) * (2*math.pi)
    >>> trans = numpy.random.random(3) - 0.5
    >>> persp = numpy.random.random(4) - 0.5
    >>> M0 = compose_matrix(scale, shear, angles, trans, persp)
    >>> result = decompose_matrix(M0)
    >>> M1 = compose_matrix(*result)
    >>> is_same_transform(M0, M1)
    True


def superimposition_matrix(v0, v1, scale=False, usesvd=True):

v0 = numpy.array(v0, dtype=numpy.float64, copy=False)[:<NUM_LIT:3>]<EOL>v1 = numpy.array(v1, dtype=numpy.float64, copy=False)[:<NUM_LIT:3>]<EOL>return affine_matrix_from_points(v0, v1, shear=False,<EOL>scale=scale, usesvd=usesvd)<EOL>

Return matrix to transform given 3D point set into second point set.

    v0 and v1 are shape (3, *) or (4, *) arrays of at least 3 points.

    The parameters scale and usesvd are explained in the more general
    affine_matrix_from_points function.

    The returned matrix is a similarity or Euclidean transformation matrix.
    This function has a fast C implementation in transformations.c.

    >>> v0 = numpy.random.rand(3, 10)
    >>> M = superimposition_matrix(v0, v0)
    >>> numpy.allclose(M, numpy.identity(4))
    True
    >>> R = random_rotation_matrix(numpy.random.random(3))
    >>> v0 = [[1,0,0], [0,1,0], [0,0,1], [1,1,1]]
    >>> v1 = numpy.dot(R, v0)
    >>> M = superimposition_matrix(v0, v1)
    >>> numpy.allclose(v1, numpy.dot(M, v0))
    True
    >>> v0 = (numpy.random.rand(4, 100) - 0.5) * 20
    >>> v0[3] = 1
    >>> v1 = numpy.dot(R, v0)
    >>> M = superimposition_matrix(v0, v1)
    >>> numpy.allclose(v1, numpy.dot(M, v0))
    True
    >>> S = scale_matrix(random.random())
    >>> T = translation_matrix(numpy.random.random(3)-0.5)
    >>> M = concatenate_matrices(T, R, S)
    >>> v1 = numpy.dot(M, v0)
    >>> v0[:3] += numpy.random.normal(0, 1e-9, 300).reshape(3, -1)
    >>> M = superimposition_matrix(v0, v1, scale=True)
    >>> numpy.allclose(v1, numpy.dot(M, v0))
    True
    >>> M = superimposition_matrix(v0, v1, scale=True, usesvd=False)
    >>> numpy.allclose(v1, numpy.dot(M, v0))
    True
    >>> v = numpy.empty((4, 100, 3))
    >>> v[:, :, 0] = v0
    >>> M = superimposition_matrix(v0, v1, scale=True, usesvd=False)
    >>> numpy.allclose(v1, numpy.dot(M, v[:, :, 0]))
    True


def dump_pathlib_mate_path(self, obj, class_name=pathlib_mate_path_class_name):

return {"<STR_LIT:$>" + class_name: str(obj)}<EOL>


def dump_nparray(self, obj, class_name=numpy_ndarray_class_name):

return {"<STR_LIT:$>" + class_name: self._json_convert(obj.tolist())}<EOL>


def load_nparray(self, dct, class_name=numpy_ndarray_class_name):

return np.array(dct["<STR_LIT:$>" + class_name])<EOL>


def load_datetime(self, dct, class_name="<STR_LIT>"):

return parse(dct["<STR_LIT:$>" + class_name])<EOL>


def dump_OrderedDict(self, obj, class_name="<STR_LIT>"):

return {<EOL>"<STR_LIT:$>" + class_name: [<EOL>(key, self._json_convert(value)) for key, value in iteritems(obj)<EOL>]<EOL>}<EOL>


def load_date(self, dct, class_name="<STR_LIT>"):

return datetime.strptime(dct["<STR_LIT:$>" + class_name], "<STR_LIT>").date()<EOL>


def dump_date(self, obj, class_name="<STR_LIT>"):


if getfullargspec(func).args == ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>


def load_pathlib_path(self, dct, class_name=pathlib_path_class_name):

return Path(dct["<STR_LIT:$>" + class_name])<EOL>

``pathlib.Path`` or ``pathlib2.Path`` loader.


def strip_comments(string, comment_symbols=frozenset(('<STR_LIT:#>', '<STR_LIT>'))):

lines = string.splitlines()<EOL>for k in range(len(lines)):<EOL><INDENT>for symbol in comment_symbols:<EOL><INDENT>lines[k] = strip_comment_line_with_symbol(lines[k], start=symbol)<EOL><DEDENT><DEDENT>return '<STR_LIT:\n>'.join(lines)<EOL>

Strip comments from json string.

    :param string: A string containing json with comments started by comment_symbols.
    :param comment_symbols: Iterable of symbols that start a line comment (default # or //).
    :return: The string with the comments removed.


self.__get_module(fullname)  <EOL>return None<EOL>

Return None

        Required, if is_package is implemented


try:<EOL><INDENT>delattr(_MovedItems, name)<EOL><DEDENT>except AttributeError:<EOL><INDENT>try:<EOL><INDENT>del moves.__dict__[name]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise AttributeError("<STR_LIT>" % (name,))<EOL><DEDENT><DEDENT>


return hasattr(self.__get_module(fullname), "<STR_LIT>")<EOL>

Return true, if the named module is a package.

We need this method to get correct spec objects with
Python 3.4 (see PEP451)


if PY2:<EOL><INDENT>if '<STR_LIT>' not in klass.__dict__:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>" %<EOL>klass.__name__)<EOL><DEDENT>klass.__unicode__ = klass.__str__<EOL>klass.__str__ = lambda self: self.__unicode__().encode('<STR_LIT:utf-8>')<EOL><DEDENT>return klass<EOL>

A decorator that defines __unicode__ and __str__ methods under Python 2.
Under Python 3 it does nothing.

To support Python 2 and 3 with a single code base, define a __str__ method
returning text and apply this decorator to the class.


setattr(_MovedItems, move.name, move)<EOL>


def wrapper(cls):<EOL><INDENT>orig_vars = cls.__dict__.copy()<EOL>slots = orig_vars.get('<STR_LIT>')<EOL>if slots is not None:<EOL><INDENT>if isinstance(slots, str):<EOL><INDENT>slots = [slots]<EOL><DEDENT>for slots_var in slots:<EOL><INDENT>orig_vars.pop(slots_var)<EOL><DEDENT><DEDENT>orig_vars.pop('<STR_LIT>', None)<EOL>orig_vars.pop('<STR_LIT>', None)<EOL>return metaclass(cls.__name__, cls.__bases__, orig_vars)<EOL><DEDENT>return wrapper<EOL>

Class decorator for creating a class with a metaclass.


<EOL>class metaclass(meta):<EOL><INDENT>def __new__(cls, name, this_bases, d):<EOL><INDENT>return meta(name, bases, d)<EOL><DEDENT><DEDENT>return type.__new__(metaclass, '<STR_LIT>', (), {})<EOL>


def atomic_write(path, writer_cls=AtomicWriter, **cls_kwargs):

return writer_cls(path, **cls_kwargs).open()<EOL>

Simple atomic writes. This wraps :py:class:`AtomicWriter`::

    with atomic_write(path) as f:
        f.write(...)

:param path: The target path to write to.
:param writer_cls: The writer class to use. This parameter is useful if you
    subclassed :py:class:`AtomicWriter` to change some behavior and want to
    use that new subclass.

Additional keyword arguments are passed to the writer class. See
:py:class:`AtomicWriter`.


return _replace_atomic(src, dst)<EOL>

Move ``src`` to ``dst``. If ``dst`` exists, it will be silently
overwritten.

Both paths must reside on the same filesystem for the operation to be
atomic.


os.unlink(f.name)<EOL>


f.flush()<EOL>_proper_fsync(f.fileno())<EOL>

responsible for clearing as many file caches as possible before
        commit


if self._overwrite:<EOL><INDENT>replace_atomic(f.name, self._path)<EOL><DEDENT>else:<EOL><INDENT>move_atomic(f.name, self._path)<EOL><DEDENT>

Move the temporary file to the target location.


def get_fileobject(self, dir=None, **kwargs):

if dir is None:<EOL><INDENT>dir = os.path.normpath(os.path.dirname(self._path))<EOL><DEDENT>descriptor, name = tempfile.mkstemp(dir=dir)<EOL>os.close(descriptor)<EOL>kwargs['<STR_LIT>'] = self._mode<EOL>kwargs['<STR_LIT:file>'] = name<EOL>return io.open(**kwargs)<EOL>


return self._open(self.get_fileobject)<EOL>


return zlib.compress(b, level)<EOL>


return zlib.compress(pickle.dumps(obj, protocol=<NUM_LIT:2>), level)<EOL>


if self._len is None:<EOL><INDENT>for x in self:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>return self._len<EOL>

Returns the number of recurrences in this set. It will have go
            trough the whole recurrence, if this hasn't been done before.


def between(self, after, before, inc=False, count=<NUM_LIT:1>):

if self._cache_complete:<EOL><INDENT>gen = self._cache<EOL><DEDENT>else:<EOL><INDENT>gen = self<EOL><DEDENT>started = False<EOL>l = []<EOL>if inc:<EOL><INDENT>for i in gen:<EOL><INDENT>if i > before:<EOL><INDENT>break<EOL><DEDENT>elif not started:<EOL><INDENT>if i >= after:<EOL><INDENT>started = True<EOL>l.append(i)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>l.append(i)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for i in gen:<EOL><INDENT>if i >= before:<EOL><INDENT>break<EOL><DEDENT>elif not started:<EOL><INDENT>if i > after:<EOL><INDENT>started = True<EOL>l.append(i)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>l.append(i)<EOL><DEDENT><DEDENT><DEDENT>return l<EOL>

Returns all the occurrences of the rrule between after and before.
        The inc keyword defines what happens if after and/or before are
        themselves occurrences. With inc=True, they will be included in the
        list, if they are found in the recurrence set.


if self._cache_complete:<EOL><INDENT>gen = self._cache<EOL><DEDENT>else:<EOL><INDENT>gen = self<EOL><DEDENT>if inc:<EOL><INDENT>for i in gen:<EOL><INDENT>if i >= dt:<EOL><INDENT>return i<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for i in gen:<EOL><INDENT>if i > dt:<EOL><INDENT>return i<EOL><DEDENT><DEDENT><DEDENT>return None<EOL>

Returns the first recurrence after the given datetime instance. The
            inc keyword defines what happens if dt is an occurrence. With
            inc=True, if dt itself is an occurrence, it will be returned.


Include the given :py:class:`rrule` instance in the recurrence set
            generation.


def xafter(self, dt, count=None, inc=False):

if self._cache_complete:<EOL><INDENT>gen = self._cache<EOL><DEDENT>else:<EOL><INDENT>gen = self<EOL><DEDENT>if inc:<EOL><INDENT>def comp(dc, dtc): return dc >= dtc<EOL><DEDENT>else:<EOL><INDENT>def comp(dc, dtc): return dc > dtc<EOL><DEDENT>n = <NUM_LIT:0><EOL>for d in gen:<EOL><INDENT>if comp(d, dt):<EOL><INDENT>if count is not None:<EOL><INDENT>n += <NUM_LIT:1><EOL>if n > count:<EOL><INDENT>break<EOL><DEDENT><DEDENT>yield d<EOL><DEDENT><DEDENT>

Generator which yields up to `count` recurrences after the given
datetime instance, equivalent to `after`.

:param dt:
    The datetime at which to start generating recurrences.

:param count:
    The maximum number of recurrences to generate. If `None` (default),
    dates are generated until the recurrence rule is exhausted.

:param inc:
    If `dt` is an instance of the rule and `inc` is `True`, it is
    included in the output.

:yields: Yields a sequence of `datetime` objects.


output = []<EOL>h, m, s = [None] * <NUM_LIT:3><EOL>if self._dtstart:<EOL><INDENT>output.append(self._dtstart.strftime('<STR_LIT>'))<EOL>h, m, s = self._dtstart.timetuple()[<NUM_LIT:3>:<NUM_LIT:6>]<EOL><DEDENT>parts = ['<STR_LIT>' + FREQNAMES[self._freq]]<EOL>if self._interval != <NUM_LIT:1>:<EOL><INDENT>parts.append('<STR_LIT>' + str(self._interval))<EOL><DEDENT>if self._wkst:<EOL><INDENT>parts.append('<STR_LIT>' + repr(weekday(self._wkst))[<NUM_LIT:0>:<NUM_LIT:2>])<EOL><DEDENT>if self._count is not None:<EOL><INDENT>parts.append('<STR_LIT>' + str(self._count))<EOL><DEDENT>if self._until:<EOL><INDENT>parts.append(self._until.strftime('<STR_LIT>'))<EOL><DEDENT>if self._original_rule.get('<STR_LIT>') is not None:<EOL><INDENT>original_rule = dict(self._original_rule)<EOL>wday_strings = []<EOL>for wday in original_rule['<STR_LIT>']:<EOL><INDENT>if wday.n:<EOL><INDENT>wday_strings.append('<STR_LIT>'.format(<EOL>n=wday.n,<EOL>wday=repr(wday)[<NUM_LIT:0>:<NUM_LIT:2>]))<EOL><DEDENT>else:<EOL><INDENT>wday_strings.append(repr(wday))<EOL><DEDENT><DEDENT>original_rule['<STR_LIT>'] = wday_strings<EOL><DEDENT>else:<EOL><INDENT>original_rule = self._original_rule<EOL><DEDENT>partfmt = '<STR_LIT>'<EOL>for name, key in [('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>'),<EOL>('<STR_LIT>', '<STR_LIT>')]:<EOL><INDENT>value = original_rule.get(key)<EOL>if value:<EOL><INDENT>parts.append(partfmt.format(name=name, vals=('<STR_LIT:U+002C>'.join(str(v)<EOL>for v in value))))<EOL><DEDENT><DEDENT>output.append('<STR_LIT:;>'.join(parts))<EOL>return '<STR_LIT:\n>'.join(output)<EOL>

Output a string that would generate this RRULE if passed to rrulestr.
This is mostly compatible with RFC2445, except for the
dateutil-specific extension BYEASTER.


return nextchar.isspace()<EOL>

Whether the next character is whitespace


return nextchar.isalpha()<EOL>

Whether or not the next character is part of a word


dt = dt.replace(tzinfo=self)<EOL>wall_0 = enfold(dt, fold=<NUM_LIT:0>)<EOL>wall_1 = enfold(dt, fold=<NUM_LIT:1>)<EOL>same_offset = wall_0.utcoffset() == wall_1.utcoffset()<EOL>same_dt = wall_0.replace(tzinfo=None) == wall_1.replace(tzinfo=None)<EOL>return same_dt and not same_offset<EOL>

Whether or not the "wall time" of a given datetime is ambiguous in this
zone.

:param dt:
    A :py:class:`datetime.datetime`, naive or time zone aware.

:return:
    Returns ``True`` if ambiguous, ``False`` otherwise.

.. versionadded:: 2.6.0


def _fold_status(self, dt_utc, dt_wall):

if self.is_ambiguous(dt_wall):<EOL><INDENT>delta_wall = dt_wall - dt_utc<EOL>_fold = int(delta_wall == (dt_utc.utcoffset() - dt_utc.dst()))<EOL><DEDENT>else:<EOL><INDENT>_fold = <NUM_LIT:0><EOL><DEDENT>return _fold<EOL>

Determine the fold status of a "wall" datetime, given a representation
of the same datetime as a (naive) UTC datetime. This is calculated based
on the assumption that ``dt.utcoffset() - dt.dst()`` is constant for all
datetimes, and that this offset is the actual number of hours separating
``dt_utc`` and ``dt_wall``.

:param dt_utc:
    Representation of the datetime as UTC

:param dt_wall:
    Representation of the datetime as "wall time". This parameter must
    either have a `fold` attribute or have a fold-naive
    :class:`datetime.tzinfo` attached, otherwise the calculation may
    fail.


resource = self.p_wchar()<EOL>lpBuffer = ctypes.cast(ctypes.byref(resource), wintypes.LPWSTR)<EOL>nchar = self.LoadStringW(self._tzres._handle, offset, lpBuffer, <NUM_LIT:0>)<EOL>return resource[:nchar]<EOL>

Load a timezone name from a DLL offset (integer).

>>> from dateutil.tzwin import tzres
>>> tzr = tzres()
>>> print(tzr.load_name(112))
'Eastern Standard Time'

:param offset:
    A positive integer value referring to a string from the tzres dll.

..note:
    Offsets found in the registry are generally of the form
    `@tzres.dll,-114`. The offset in this case if 114, not -114.


dout = {}<EOL>size = winreg.QueryInfoKey(key)[<NUM_LIT:1>]<EOL>tz_res = None<EOL>for i in range(size):<EOL><INDENT>key_name, value, dtype = winreg.EnumValue(key, i)<EOL>if dtype == winreg.REG_DWORD or dtype == winreg.REG_DWORD_LITTLE_ENDIAN:<EOL><INDENT>if value & (<NUM_LIT:1> << <NUM_LIT>):<EOL><INDENT>value = value - (<NUM_LIT:1> << <NUM_LIT:32>)<EOL><DEDENT><DEDENT>elif dtype == winreg.REG_SZ:<EOL><INDENT>if value.startswith('<STR_LIT>'):<EOL><INDENT>tz_res = tz_res or tzres()<EOL>value = tz_res.name_from_string(value)<EOL><DEDENT>value = value.rstrip('<STR_LIT:\x00>')    <EOL><DEDENT>dout[key_name] = value<EOL><DEDENT>return dout<EOL>

Convert a registry key's values to a dictionary.


with winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE) as handle:<EOL><INDENT>with winreg.OpenKey(handle, TZKEYNAME) as tzkey:<EOL><INDENT>result = [winreg.EnumKey(tzkey, i)<EOL>for i in range(winreg.QueryInfoKey(tzkey)[<NUM_LIT:0>])]<EOL><DEDENT><DEDENT>return result<EOL>

Return a list of all time zones known to the system.


if not tzname_str.startswith('<STR_LIT:@>'):<EOL><INDENT>return tzname_str<EOL><DEDENT>name_splt = tzname_str.split('<STR_LIT>')<EOL>try:<EOL><INDENT>offset = int(name_splt[<NUM_LIT:1>])<EOL><DEDENT>except:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return self.load_name(offset)<EOL>

Parse strings as returned from the Windows registry into the time zone
name as defined in the registry.

>>> from dateutil.tzwin import tzres
>>> tzr = tzres()
>>> print(tzr.name_from_string('@tzres.dll,-251'))
'Dateline Daylight Time'
>>> print(tzr.name_from_string('Eastern Standard Time'))
'Eastern Standard Time'

:param tzname_str:
    A timezone name string as returned from a Windows registry key.

:return:
    Returns the localized timezone string from tzres.dll if the string
    is of the form `@tzres.dll,-offset`, else returns the input string.


return False<EOL>


if not self.hasdst:<EOL><INDENT>return None<EOL><DEDENT>base_year = datetime.datetime(year, <NUM_LIT:1>, <NUM_LIT:1>)<EOL>start = base_year + self._start_delta<EOL>end = base_year + self._end_delta<EOL>return (start, end)<EOL>

For a given year, get the DST on and off transition times, expressed
always on the standard time side. For zones with no transitions, this
function returns ``None``.

:param year:
    The year whose transitions you would like to query.

:return:
    Returns a :class:`tuple` of :class:`datetime.datetime` objects,
    ``(dston, dstoff)`` for zones with an annual DST transition, or
    ``None`` for fixed offset zones.


naive_dst = self._naive_is_dst(dt)<EOL>return (not naive_dst and<EOL>(naive_dst != self._naive_is_dst(dt - self._dst_saved)))<EOL>


if idx is None:<EOL><INDENT>idx = self._find_last_transition(dt)<EOL><DEDENT>timestamp = _datetime_to_timestamp(dt)<EOL>tti = self._get_ttinfo(idx)<EOL>if idx is None or idx <= <NUM_LIT:0>:<EOL><INDENT>return False<EOL><DEDENT>od = self._get_ttinfo(idx - <NUM_LIT:1>).offset - tti.offset<EOL>tt = self._trans_list[idx]          <EOL>return timestamp < tt + od<EOL>


if tz is None:<EOL><INDENT>if dt.tzinfo is None:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>tz = dt.tzinfo<EOL><DEDENT>is_ambiguous_fn = getattr(tz, '<STR_LIT>', None)<EOL>if is_ambiguous_fn is not None:<EOL><INDENT>try:<EOL><INDENT>return tz.is_ambiguous(dt)<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>dt = dt.replace(tzinfo=tz)<EOL>wall_0 = enfold(dt, fold=<NUM_LIT:0>)<EOL>wall_1 = enfold(dt, fold=<NUM_LIT:1>)<EOL>same_offset = wall_0.utcoffset() == wall_1.utcoffset()<EOL>same_dst = wall_0.dst() == wall_1.dst()<EOL>return not (same_offset and same_dst)<EOL>

Given a datetime and a time zone, determine whether or not a given datetime
is ambiguous (i.e if there are two times differentiated only by their DST
status).

:param dt:
    A :class:`datetime.datetime` (whose time zone will be ignored if ``tz``
    is provided.)

:param tz:
    A :class:`datetime.tzinfo` with support for the ``fold`` attribute. If
    ``None`` or not provided, the datetime's own time zone will be used.

:return:
    Returns a boolean value whether or not the "wall time" is ambiguous in
    ``tz``.

.. versionadded:: 2.6.0


return list(self._vtz.keys())<EOL>

Retrieves the available time zones as a list.


<EOL>days = int(self.days)<EOL>hours_f = round(self.hours + <NUM_LIT> * (self.days - days), <NUM_LIT:11>)<EOL>hours = int(hours_f)<EOL>minutes_f = round(self.minutes + <NUM_LIT> * (hours_f - hours), <NUM_LIT:10>)<EOL>minutes = int(minutes_f)<EOL>seconds_f = round(self.seconds + <NUM_LIT> * (minutes_f - minutes), <NUM_LIT:8>)<EOL>seconds = int(seconds_f)<EOL>microseconds = round(self.microseconds + <NUM_LIT> * (seconds_f - seconds))<EOL>return self.__class__(years=self.years, months=self.months,<EOL>days=days, hours=hours, minutes=minutes,<EOL>seconds=seconds, microseconds=microseconds,<EOL>leapdays=self.leapdays, year=self.year,<EOL>month=self.month, day=self.day,<EOL>weekday=self.weekday, hour=self.hour,<EOL>minute=self.minute, second=self.second,<EOL>microsecond=self.microsecond)<EOL>

Return a version of this object represented entirely using integer
values for the relative attributes.

>>> relativedelta(days=1.5, hours=2).normalized()
relativedelta(days=1, hours=14)

:return:
    Returns a :class:`dateutil.relativedelta.relativedelta` object.


return self.zones.get(name, default)<EOL>

Wrapper for :func:`ZoneInfoFile.zones.get`. This is a convenience method
for retrieving zones from the zone dictionary.

:param name:
    The name of the zone to retrieve. (Generally IANA zone names)

:param default:
    The value to return in the event of a missing key.

.. versionadded:: 2.6.0


if new_instance:<EOL><INDENT>zif = None<EOL><DEDENT>else:<EOL><INDENT>zif = getattr(get_zonefile_instance, '<STR_LIT>', None)<EOL><DEDENT>if zif is None:<EOL><INDENT>zif = ZoneInfoFile(getzoneinfofile_stream())<EOL>get_zonefile_instance._cached_instance = zif<EOL><DEDENT>return zif<EOL>

This is a convenience function which provides a :class:`ZoneInfoFile`
instance using the data provided by the ``dateutil`` package. By default, it
caches a single instance of the ZoneInfoFile object and returns that.

:param new_instance:
    If ``True``, a new instance of :class:`ZoneInfoFile` is instantiated and
    used as the cached instance for the next call. Otherwise, new instances
    are created only as necessary.

:return:
    Returns a :class:`ZoneInfoFile` object.

.. versionadded:: 2.6


Get the zonefile metadata

    See `zonefile_metadata`_

    :returns:
        A dictionary with the database metadata

    .. deprecated:: 2.6
        See deprecation warning in :func:`zoneinfo.gettz`. To get metadata,
        query the attribute ``zoneinfo.ZoneInfoFile.metadata``.


This retrieves a time zone from the local zoneinfo tarball that is packaged
with dateutil.

:param name:
    An IANA-style time zone name, as found in the zoneinfo file.

:return:
    Returns a :class:`dateutil.tz.tzfile` time zone object.

.. warning::
    It is generally inadvisable to use this function, and it is only
    provided for API compatibility with earlier versions. This is *not*
    equivalent to ``dateutil.tz.gettz()``, which selects an appropriate
    time zone based on the inputs, favoring system zoneinfo. This is ONLY
    for accessing the dateutil-specific zoneinfo (which may be out of
    date compared to the system zoneinfo).

.. deprecated:: 2.6
    If you need to use a specific zoneinfofile over the system zoneinfo,
    instantiate a :class:`dateutil.zoneinfo.ZoneInfoFile` object and call
    :func:`dateutil.zoneinfo.ZoneInfoFile.get(name)` instead.

    Use :func:`get_zonefile_instance` to retrieve an instance of the
    dateutil-provided zoneinfo.


def rebuild(filename, tag=None, format="<STR_LIT>", zonegroups=[], metadata=None):

tmpdir = tempfile.mkdtemp()<EOL>zonedir = os.path.join(tmpdir, "<STR_LIT>")<EOL>moduledir = os.path.dirname(__file__)<EOL>try:<EOL><INDENT>with tar_open(filename) as tf:<EOL><INDENT>for name in zonegroups:<EOL><INDENT>tf.extract(name, tmpdir)<EOL><DEDENT>filepaths = [os.path.join(tmpdir, n) for n in zonegroups]<EOL>try:<EOL><INDENT>check_call(["<STR_LIT>", "<STR_LIT>", zonedir] + filepaths)<EOL><DEDENT>except OSError as e:<EOL><INDENT>_print_on_nosuchfile(e)<EOL>raise<EOL><DEDENT><DEDENT>with open(os.path.join(zonedir, METADATA_FN), '<STR_LIT:w>') as f:<EOL><INDENT>json.dump(metadata, f, indent=<NUM_LIT:4>, sort_keys=True)<EOL><DEDENT>target = os.path.join(moduledir, ZONEFILENAME)<EOL>with tar_open(target, "<STR_LIT>" % format) as tf:<EOL><INDENT>for entry in os.listdir(zonedir):<EOL><INDENT>entrypath = os.path.join(zonedir, entry)<EOL>tf.add(entrypath, entry)<EOL><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>shutil.rmtree(tmpdir)<EOL><DEDENT>

Rebuild the internal timezone info in dateutil/zoneinfo/zoneinfo*tar*

    filename is the timezone tarball from ftp.iana.org/tz.


if not (<NUM_LIT:1> <= method <= <NUM_LIT:3>):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>y = year<EOL>g = y % <NUM_LIT><EOL>e = <NUM_LIT:0><EOL>if method < <NUM_LIT:3>:<EOL><INDENT>i = (<NUM_LIT> * g + <NUM_LIT:15>) % <NUM_LIT:30><EOL>j = (y + y // <NUM_LIT:4> + i) % <NUM_LIT:7><EOL>if method == <NUM_LIT:2>:<EOL><INDENT>e = <NUM_LIT:10><EOL>if y > <NUM_LIT>:<EOL><INDENT>e = e + y // <NUM_LIT:100> - <NUM_LIT:16> - (y // <NUM_LIT:100> - <NUM_LIT:16>) // <NUM_LIT:4><EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>c = y // <NUM_LIT:100><EOL>h = (c - c // <NUM_LIT:4> - (<NUM_LIT:8> * c + <NUM_LIT>) // <NUM_LIT> + <NUM_LIT> * g + <NUM_LIT:15>) % <NUM_LIT:30><EOL>i = h - (h // <NUM_LIT>) * (<NUM_LIT:1> - (h // <NUM_LIT>) *<EOL>(<NUM_LIT> // (h + <NUM_LIT:1>)) * ((<NUM_LIT> - g) // <NUM_LIT:11>))<EOL>j = (y + y // <NUM_LIT:4> + i + <NUM_LIT:2> - c + c // <NUM_LIT:4>) % <NUM_LIT:7><EOL><DEDENT>p = i - j + e<EOL>d = <NUM_LIT:1> + (p + <NUM_LIT> + (p + <NUM_LIT:6>) // <NUM_LIT>) % <NUM_LIT><EOL>m = <NUM_LIT:3> + (p + <NUM_LIT>) // <NUM_LIT:30><EOL>return datetime.date(int(y), int(m), int(d))<EOL>

This method was ported from the work done by GM Arts,
on top of the algorithm by Claus Tondering, which was
based in part on the algorithm of Ouding (1940), as
quoted in "Explanatory Supplement to the Astronomical
Almanac", P.  Kenneth Seidelmann, editor.

This algorithm implements three different easter
calculation methods:

1 - Original calculation in Julian calendar, valid in
    dates after 326 AD
2 - Original method, with date converted to Gregorian
    calendar, valid in years 1583 to 4099
3 - Revised method, in Gregorian calendar, valid in
    years 1583 to 4099 as well

These methods are represented by the constants:

* ``EASTER_JULIAN   = 1``
* ``EASTER_ORTHODOX = 2``
* ``EASTER_WESTERN  = 3``

The default method is method 3.

More about the algorithm may be found at:

http://users.chariot.net.au/~gmarts/eastalg.htm

and

http://www.tondering.dk/claus/calendar.html


if verbose:<EOL><INDENT>logger.info(message)<EOL><DEDENT>

Print message to console, if ``verbose`` is True.


<EOL>try:<EOL><INDENT>import sentry_sdk<EOL>from sentry_sdk.integrations.pyramid import PyramidIntegration<EOL>from sentry_sdk.integrations.celery import CeleryIntegration<EOL><DEDENT>except ImportError:<EOL><INDENT>warnings.warn(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>",<EOL>UserWarning,<EOL>)<EOL>return  <EOL><DEDENT>try:<EOL><INDENT>dsn = os.environ['<STR_LIT>']<EOL><DEDENT>except KeyError:<EOL><INDENT>warnings.warn(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>",<EOL>UserWarning,<EOL>)<EOL><DEDENT>else:<EOL><INDENT>sentry_sdk.init(<EOL>dsn=dsn,<EOL>integrations=[PyramidIntegration(), CeleryIntegration()],<EOL>)<EOL><DEDENT>

\
    Used to optionally initialize the Sentry service with this app.
    See https://docs.sentry.io/platforms/python/pyramid/


return dict(<EOL>(key, os.path.expandvars(value))<EOL>for key, value in settings.iteritems()<EOL>)<EOL>

Expands all environment variables in a settings dictionary.


cursor.execute("""<STR_LIT>""",<EOL>(uuid_,))<EOL>return cursor.fetchone()[<NUM_LIT:0>]<EOL>

Inserts a UUID value into the ``document_controls`` table.


user_ids = set([])<EOL>for role_attr in cnxepub.ATTRIBUTED_ROLE_KEYS:<EOL><INDENT>for role in model.metadata.get(role_attr, []):<EOL><INDENT>user_ids.add(role['<STR_LIT:id>'])<EOL><DEDENT><DEDENT>cursor.execute("<STR_LIT>",<EOL>(list(user_ids),))<EOL>try:<EOL><INDENT>existing_user_ids = [x[<NUM_LIT:0>] for x in cursor.fetchall()]<EOL><DEDENT>except TypeError:<EOL><INDENT>existing_user_ids = []<EOL><DEDENT>new_user_ids = [u for u in user_ids if u not in existing_user_ids]<EOL>for user_id in new_user_ids:<EOL><INDENT>cursor.execute("""<STR_LIT>""", (user_id,))<EOL><DEDENT>


<EOL>model.set_uri('<STR_LIT>', model.ident_hash)<EOL>

Set the model's cnx-archive-uri to the model's ident_hash.