diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2016-02-04 22:52:07 -0500 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2016-02-04 22:52:07 -0500 |
| commit | 9096b58187e2bffb5846d727c61aaf616fddc9bc (patch) | |
| tree | 2b6daf0890190c0c67a1553ee2e05cb647908f8d /BibTeX.py | |
| parent | e5f4e59bbbf65951631a79334b9c14211f193806 (diff) | |
| download | anonbib-9096b58187e2bffb5846d727c61aaf616fddc9bc.tar.gz | |
Also update rank.py and updateCache.py to new interface
Diffstat (limited to 'BibTeX.py')
| -rw-r--r-- | BibTeX.py | 37 |
1 files changed, 16 insertions, 21 deletions
@@ -24,17 +24,10 @@ class ParseError(Exception): class BibTeX: """A parsed BibTeX file""" + def __init__(self): self.entries = {} - def addEntry(self, ent): - """Add a BibTeX entry to this file.""" - k = ent.key - if k.lower() in self.entries: - print >> sys.stderr, "Already have an entry named %s" % k - return - self[k] = ent - def __contains__(self, key): return key.lower() in self.entries @@ -50,6 +43,13 @@ class BibTeX: def __iter__(self): return iter(self.entries.values()) + def add_entry(self, ent): + """Add a BibTeX entry to this file.""" + if ent.key in self: + print >> sys.stderr, "Already have an entry named %s" % ent.key + return + self[ent.key] = ent + def resolve(self): """Validate all entries in this file, and resolve cross-references""" seen = {} @@ -77,9 +77,9 @@ class BibTeX: ent[k] = cr[k] ent.resolve() - self.remove_unrequired() + self.sanitize() - def remove_unrequired(self): + def sanitize(self): rk = config.REQUIRE_KEY if rk is None: rk = "title" @@ -88,19 +88,14 @@ class BibTeX: if ent.type in config.OMIT_ENTRIES or rk not in ent: ent.check() del self[ent.key] - - for ent in self: - ent.check() + else: + ent.check() class FileIter: - def __init__(self, fname=None, file=None, it=None, string=None): - if fname: - file = open(fname, 'r') - if string: - file = cStringIO.StringIO(string) - if file: - self.iter = iter(file) + def __init__(self, fname): + file = open(fname, 'r') + self.iter = iter(file) assert self.iter self.lineno = 0 @@ -327,7 +322,7 @@ class Parser: d[v[i].lower()] = v[i+1] ent = BibTeXEntry(self.curEntType, key, d) ent.entryLine = self.entryLine - self.result.addEntry(ent) + self.result.add_entry(ent) return line |
