Use pybtex to validate that a reference is in proper BibTeX format

    Args:
        reference: A String reference in BibTeX format.

    Returns:
        Boolean indicating if reference is valid bibtex.
976142
def is_valid_bibtex(reference):
    
    # str is necessary since pybtex seems to have an issue with unicode. The
    # filter expression removes all non-ASCII characters.
    sio = StringIO(remove_non_ascii(reference))
    parser = bibtex.Parser()
    errors.set_strict_mode(False)
    bib_data = parser.parse_stream(sio)
    return len(bib_data.entries) > 0
1271522
def isValid(self):
        
        if self._callback_func_ref is not None and self._callback_func_ref():
            if self._callback_self_ref is None or self._callback_self_ref():
                return True
        return False
34020
def _is_reference(arg):
    '''
    
    '''
    return isinstance(arg, dict) and len(arg) == 1 and isinstance(next(six.itervalues(arg)), six.string_types)
669172
def get_plaintext_citations(bibtex):
    
    parser = BibTexParser()
    parser.customization = convert_to_unicode
    # Load the BibTeX
    if os.path.isfile(bibtex):
        with open(bibtex) as fh:
            bib_database = bibtexparser.load(fh, parser=parser)
    else:
        bib_database = bibtexparser.loads(bibtex, parser=parser)
    # Convert bibentries to plaintext
    bibentries = [bibentry_as_plaintext(bibentry)
                  for bibentry in bib_database.entries]
    # Return them
    return bibentries
431857
def references(self):
        
        refs = self.items.find('bibrecord/tail/bibliography', ns)
        if refs is not None:
            eids = [r.find("ref-info/refd-itemidlist/itemid", ns).text for r
                    in refs.findall("reference", ns)]
            return ["2-s2.0-" + eid for eid in eids]
        else:
            return None
890463
def set_pubnote(self, pubnote):
        """"""
        if 'publication_info' in self.obj.get('reference', {}):
            self.add_misc(u'Additional pubnote: {}'.format(pubnote))
            return

        if self.RE_VALID_PUBNOTE.match(pubnote):
            pubnote = split_pubnote(pubnote)
            pubnote = convert_old_publication_info_to_new([pubnote])[0]
            self._ensure_reference_field('publication_info', pubnote)
        else:
            self.add_misc(pubnote)
650819
def parse_package_ref(self, ref):
        
        if not ref:
            return None
        parsed = re.match('(.*)\ (.*)\ (.*)\ (.*)', ref)
        return parsed.groups()
791990
def _get_absolute_reference(self, ref_key):
        """"""

        key_str = u", ".join(map(str, ref_key))
        return u"S[" + key_str + u"]"
241395
def get_git_ref(self, ref):
        
        prefix = "/git/refs/"
        if not self._requester.FIX_REPO_GET_GIT_REF:
            prefix = "/git/"
        assert isinstance(ref, (str, unicode)), ref
        headers, data = self._requester.requestJsonAndCheck(
            "GET",
            self.url + prefix + ref
        )
        return github.GitRef.GitRef(self._requester, headers, data, completed=True)
310938
def isqref(object):
    
    return (
        isinstance(object, tuple) and
        len(object) == 2 and
        isinstance(object[0], basestring) and
        isinstance(object[1], basestring))
814195
def validate(self, value):
        
        ref_model = self.referenceModel()
        if isinstance(value, orb.Model):
            expected_schema = ref_model.schema().name()
            received_schema = value.schema().name()

            if expected_schema != received_schema:
                raise orb.errors.InvalidReference(self.name(),
                                                  expects=expected_schema,
                                                  received=received_schema)

        return super(ReferenceColumn, self).validate(value)
446894
def write_bib(refs):
    '''
    '''

    full_str = ''

    lib_citation_desc, lib_citations = get_library_citation()

    full_str += '%' * 80 + '\n'
    full_str += textwrap.indent(lib_citation_desc, '% ')
    full_str += '%' * 80 + '\n\n'

    for k, r in lib_citations.items():
        full_str += _ref_bib(k, r) + '\n\n'

    full_str += '%' * 80 + '\n'
    full_str += "% References for the basis set\n"
    full_str += '%' * 80 + '\n'

    # First, write out the element, description -> key mapping
    # Also make a dict of unique reference to output
    unique_refs = {}

    for ref in refs:
        full_str += '% {}\n'.format(compact_elements(ref['elements']))

        for ri in ref['reference_info']:
            full_str += '%     {}\n'.format(ri['reference_description'])

            refdata = ri['reference_data']

            if len(refdata) == 0:
                full_str += '%     (...no reference...)\n%\n'
            else:
                rkeys = [x[0] for x in ri['reference_data']]
                full_str += '%         {}\n%\n'.format(' '.join(rkeys))

            for k, r in refdata:
                unique_refs[k] = r

    full_str += '\n\n'

    # Go through them sorted alphabetically by key
    for k, r in sorted(unique_refs.items(), key=lambda x: x[0]):
        full_str += '{}\n\n'.format(_ref_bib(k, r))

    return full_str
1211459
def get_reference(self, rtype: str, label: str):
        

        # We are doing this instead of dictionary access in case we change
        # the storage later to a multidict thingy for optimization.

        reftype = self.data.get(rtype)
        if reftype:
            # The reftype might be "python" or "sphinx" or something else
            # from an Intersphinx registry, not something internal to
            # Kaybee.
            return reftype[label]
1196808
def addReference(self, reference):
        
        id_ = reference.getId()
        self._referenceIdMap[id_] = reference
        self._referenceNameMap[reference.getLocalId()] = reference
        self._referenceIds.append(id_)
275329
boolean documentReference(String reference) {
    if (!lazyInitDocumentation()) {
      return true;
    }

    if (documentation.sees == null) {
      documentation.sees = new ArrayList<>();
    }

    documentation.sees.add(reference);
    return true;
  }
128669
def calculate_reference(self, reference, sign=True):
        
        node = self.get_uri(reference.get('URI', ''), reference)
        transforms = reference.find(
            'ds:Transforms', namespaces=constants.NS_MAP
        )
        if transforms is not None:
            for transform in transforms.findall(
                    'ds:Transform', namespaces=constants.NS_MAP
            ):
                node = self.transform(transform, node)
        digest_value = self.digest(
            reference.find(
                'ds:DigestMethod', namespaces=constants.NS_MAP
            ).get('Algorithm'),
            node
        )
        if not sign:
            return digest_value.decode() == reference.find(
                'ds:DigestValue', namespaces=constants.NS_MAP
            ).text

        reference.find(
            'ds:DigestValue', namespaces=constants.NS_MAP
        ).text = digest_value
656775
def valid_ref?(ref, origin = nil)
      ref = ref.to_s
      origin = origin.to_s if origin

      return true if GLOBAL_REFS.key?(ref)

      return true if @Parameters && @Parameters.key?(ref)

      return !origin || !@_resource_refs || !@_resource_refs[ref] || !@_resource_refs[ref].key?(origin) if @Resources.key?(ref)

      false
    end