Extract a structure from a match object, while translating the types in the process.
336556
def translate(self, mo):
        """"""
        attrs = {}
        groupdict = mo.groupdict()
        for name, value in compat_iteritems(groupdict):
            if value is None:
                value = None
            elif self._int_re.match(value):
                value = int(value)
            elif self._float_re.match(value):
                value = float(value)
            attrs[name] = (value)
        return Struct(attrs)
458285
def _fetch_type_sub(cls, cls_in, match):
        

        if match.group(cls._SUBMATCH_INDEX_TYPE_SUB):
            return cls._str_to_type(
                cls_in,
                match.group(cls._SUBMATCH_INDEX_TYPE_SUB)
            )
        else:
            return None
184475
def fit(self, struct1, struct2):
        
        struct1, struct2 = self._process_species([struct1, struct2])

        if not self._subset and self._comparator.get_hash(struct1.composition) \
                != self._comparator.get_hash(struct2.composition):
            return None

        struct1, struct2, fu, s1_supercell = self._preprocess(struct1, struct2)
        match = self._match(struct1, struct2, fu, s1_supercell,
                            break_on_match=True)

        if match is None:
            return False
        else:
            return match[0] <= self.stol
938918
function extract(pattern, part) {
  if (!pattern) throw new Error('missing pattern');
  // no match
  if (!part) return STOP;

  let term = matchTerm(pattern);
  if (term) {
    // if single __any
    if (term.type === ANY) {
      if (term.name) {
        // if __any_foo
        // get result {foo: astNode}
        let r = {};
        r[term.name] = part;
        return r;
      }
      // always match
      return {};

    // if single __str_foo
    } else if (term.type === STR) {
      if (part.type === 'Literal') {
        if (term.name) {
          // get result {foo: value}
          let r = {};
          r[term.name] = part.value;
          return r;
        }
        // always match
        return {};
      }
      // no match
      return STOP;
    }
  }


  if (Array.isArray(pattern)) {
    // no match
    if (!Array.isArray(part)) return STOP;

    if (pattern.length === 1) {
      let arrTerm = matchTerm(pattern[0]);
      if (arrTerm) {
        // if single __arr_foo
        if (arrTerm.type === ARR) {
          // find all or partial Literals in an array
          let arr = part.filter(function(it) { return it.type === 'Literal'; })
                        .map(function(it) { return it.value; });
          if (arr.length) {
            if (arrTerm.name) {
              // get result {foo: array}
              let r = {};
              r[arrTerm.name] = arr;
              return r;
            }
            // always match
            return {};
          }
          // no match
          return STOP;
        } else if (arrTerm.type === ANL) {
          if (arrTerm.name) {
            // get result {foo: nodes array}
            let r = {};
            r[arrTerm.name] = part;
            return r;
          }

          // always match
          return {};
        }
      }
    }

    if (pattern.length !== part.length) {
      // no match
      return STOP;
    }
  }

  let allResult = {};

  for (let i = 0, keys = Object.keys(pattern); i < keys.length; i++) {
    let key = keys[i];
    if (IGNORED_KEYS.indexOf(key) !== -1) continue;

    let nextPattern = pattern[key];
    let nextPart = part[key];

    if (!nextPattern || typeof nextPattern !== 'object') {
      // primitive value. string or null
      if (nextPattern === nextPart) continue;

      // no match
      return STOP;
    }

    const result = extract(nextPattern, nextPart);
    // no match
    if (result === STOP) return STOP;
    if (result) Object.assign(allResult, result);
  }

  return allResult;
}
1180653
def fromstring(text, schema=None):
    """"""
    if schema:
        parser = objectify.makeparser(schema = schema.schema)
        return objectify.fromstring(text, parser=parser)
    else:
        return objectify.fromstring(text)
1330658
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'model_id' in _dict:
            args['model_id'] = _dict.get('model_id')
        if 'model_version' in _dict:
            args['model_version'] = _dict.get('model_version')
        if 'documents' in _dict:
            args['documents'] = [
                Document._from_dict(x) for x in (_dict.get('documents'))
            ]
        if 'aligned_elements' in _dict:
            args['aligned_elements'] = [
                AlignedElement._from_dict(x)
                for x in (_dict.get('aligned_elements'))
            ]
        if 'unaligned_elements' in _dict:
            args['unaligned_elements'] = [
                UnalignedElement._from_dict(x)
                for x in (_dict.get('unaligned_elements'))
            ]
        return cls(**args)
1038886
def parse_object_type_extension(lexer: Lexer) -> Node:
    """"""
    start = lexer.token
    expect_keyword(lexer, "extend")
    expect_keyword(lexer, "type")
    name = parse_name(lexer)
    interfaces = parse_implements_interfaces(lexer)
    directives = parse_directives(lexer, True)
    fields = parse_fields_definition(lexer)
    if not (interfaces or directives or fields):
        raise unexpected(lexer)
    return Node(
        name=name,
        interfaces=interfaces,
        directives=directives,
        fields=fields,
        loc=loc(lexer, start),
    )
523272
function processOtherSpecifier() {
                    const leftBrace = sourceCode.getFirstToken(node, 1)
                    const rightBrace = sourceCode.getLastToken(
                        node,
                        hasSemi ? 3 : 2
                    )
                    setOffsetToToken(leftBrace, 0, importToken)
                    processNodeList(node.specifiers, leftBrace, rightBrace, 1)
                    tokens.push(
                        sourceCode.getLastToken(node, hasSemi ? 2 : 1), // from
                        sourceCode.getLastToken(node, hasSemi ? 1 : 0) // "foo"
                    )
                }
552285
def from_structure(cls, original, filter_residues):
        
        P = cls(original.id)
        P.full_id = original.full_id
        
        for child in original.child_dict.values():
            copycat = deepcopy(child)
            P.add(copycat)
        
        # Discriminate non-residues (is_aa function)
        remove_list = []
        if filter_residues:
            for model in P:
                for chain in model:
                    for residue in chain:
                        if residue.get_id()[0] != ' ' or not is_aa(residue):
                            remove_list.append(residue)
            
            for residue in remove_list:
                residue.parent.detach_child(residue.id)
            
            for chain in P.get_chains(): # Remove empty chains
                if not len(chain.child_list):
                    model.detach_child(chain.id)
                    
        P.header = deepcopy(original.header)
        P.xtra = deepcopy(original.xtra)
        
        return P
569732
def extract(text, default=UNKNOWN):
        """"""
        if not text:
            return default
        found = CALLING_CONVENTION_TYPES.pattern.match(text)
        if found:
            return found.group('cc')

        return default
1107272
def translate(self, closed_regex=True):
        
        """
        if closed_regex:
            return self.regex
        else:
            return translate(self.pattern, closed_regex=False, **self.flags)
1071568
def convert_to_match_query(ir_blocks):
    """"""
    output_block = ir_blocks[-1]
    if not isinstance(output_block, ConstructResult):
        raise AssertionError(u'Expected last IR block to be ConstructResult, found: '
                             u'{} {}'.format(output_block, ir_blocks))
    ir_except_output = ir_blocks[:-1]

    folds, ir_except_output_and_folds = extract_folds_from_ir_blocks(ir_except_output)

    # Extract WHERE Filter
    global_operation_ir_blocks_tuple = _extract_global_operations(ir_except_output_and_folds)
    global_operation_blocks, pruned_ir_blocks = global_operation_ir_blocks_tuple
    if len(global_operation_blocks) > 1:
        raise AssertionError(u'Received IR blocks with multiple global operation blocks. Only one '
                             u'is allowed: {} {}'.format(global_operation_blocks, ir_blocks))
    if len(global_operation_blocks) == 1:
        if not isinstance(global_operation_blocks[0], Filter):
            raise AssertionError(u'Received non-Filter global operation block. {}'
                                 .format(global_operation_blocks[0]))
        where_block = global_operation_blocks[0]
    else:
        where_block = None

    match_steps = _split_ir_into_match_steps(pruned_ir_blocks)

    match_traversals = _split_match_steps_into_match_traversals(match_steps)

    return MatchQuery(
        match_traversals=match_traversals,
        folds=folds,
        output_block=output_block,
        where_block=where_block,
    )
385019
def _process_structures(structures):
        
        input_structures = structures
        structures = [input_structures[0]]
        for s in input_structures[1:]:
            prev = structures[-1]
            for i in range(len(s)):
                t = np.round(prev[i].frac_coords - s[i].frac_coords)
                if np.any(np.abs(t) > 0.5):
                    s.translate_sites([i], t, to_unit_cell=False)
            structures.append(s)
        return structures
361413
function (node, match) {
      do {
        if (!node || node.nodeName.toLowerCase() === match) {
          break
        }
        node = node.parentNode
      } while (node)

      return node
    }
1136361
def translate(patterns, flags):
    """"""

    positive = []
    negative = []
    if isinstance(patterns, (str, bytes)):
        patterns = [patterns]

    flags |= _TRANSLATE

    for pattern in patterns:
        for expanded in expand_braces(pattern, flags):
            (negative if is_negative(expanded, flags) else positive).append(
                WcParse(expanded, flags & FLAG_MASK).parse()
            )

    if patterns and flags & REALPATH and negative and not positive:
        positive.append(_compile(b'**' if isinstance(patterns[0], bytes) else '**', flags))

    return positive, negative
526615
def _from_match(match):
        """"""
        addr_beg, addr_end, r, w, x, p, offset, dev, inode, pathname = match.groups()
        return MemoryRegion(addr_beg=int(addr_beg, 16),
                            addr_end=int(addr_end, 16),
                            readable=(r == "r"),
                            writable=(w == "w"),
                            executable=(x == "x"),
                            private=(p == "p"),
                            offset=int(offset, 16),
                            dev=dev,
                            inode=int(inode),
                            pathname=pathname)
601270
def _fn_matches(fn, glob):
    """"""
    if glob not in _pattern_cache:
        pattern = _pattern_cache[glob] = re.compile(fnmatch.translate(glob))
        return pattern.match(fn)
    return _pattern_cache[glob].match(fn)