diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2016-02-04 20:13:43 -0500 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2016-02-04 20:13:43 -0500 |
| commit | f555859455c9e9e262f6021dca538c73441093f2 (patch) | |
| tree | 84c4492b1364134ee8bb30be290c7c45770fa3dd /BibTeX.py | |
| parent | 5af5043ac67529aa2ecc05c6a3bbc22a4419b9cb (diff) | |
| download | anonbib-f555859455c9e9e262f6021dca538c73441093f2.tar.gz | |
More PEP8
Diffstat (limited to 'BibTeX.py')
| -rw-r--r-- | BibTeX.py | 62 |
1 files changed, 31 insertions, 31 deletions
@@ -58,8 +58,8 @@ class BibTeX: for k in cr.entries.keys(): if ent.entries.has_key(k): - print "ERROR: %s defined both in %s and in %s"%( - k,ent.key,cr.key) + print "ERROR: %s defined both in %s and in %s" % ( + k, ent.key, cr.key) else: ent.entries[k] = cr.entries[k] @@ -100,7 +100,7 @@ class FileIter: class Parser: """Parser class: reads BibTeX from a file and returns a BibTeX object.""" - ## Fields + # Fields # strings: maps entry string keys to their values. # newStrings: all string definitions not in config.INITIAL_STRINGS # invStrings: map from string values to their keys. @@ -116,7 +116,7 @@ class Parser: self.strings.update(initial_strings) self.newStrings = {} self.invStrings = {} - for k,v in config.INITIAL_STRINGS.items(): + for k, v in config.INITIAL_STRINGS.items(): self.invStrings[v]=k self.fileiter = fileiter if result is None: @@ -130,7 +130,7 @@ class Parser: line = _advance(it, line) m = KEY_RE.match(line) if not m: - raise ParseError("Expected key at line %s"%self.fileiter.lineno) + raise ParseError("Expected key at line %s" % self.fileiter.lineno) key, line = m.groups() return key, line @@ -138,14 +138,14 @@ class Parser: it = self.fileiter bracelevel = 0 data = [] - while 1: - line = _advance(it,line) + while True: + line = _advance(it, line) line = line.strip() assert line # Literal string? if line[0] == '"': - line=line[1:] + line = line[1:] self.litStringLine = it.lineno while 1: if bracelevel: @@ -178,31 +178,31 @@ class Parser: while bracelevel: m = BRACE_CLOSE_RE.match(line) if m: - #print bracelevel, "A", repr(m.group(1)) + # print bracelevel, "A", repr(m.group(1)) data.append(m.group(1)) bracelevel -= 1 if bracelevel > 0: - #print bracelevel, "- '}'" + # print bracelevel, "- '}'" data.append('}') line = m.group(2) continue m = BRACE_OPEN_RE.match(line) if m: bracelevel += 1 - #print bracelevel, "B", repr(m.group(1)) + # print bracelevel, "B", repr(m.group(1)) data.append(m.group(1)) line = m.group(2) continue else: - #print bracelevel, "C", repr(line) + # print bracelevel, "C", repr(line) data.append(line) data.append(" ") line = it.next() elif line[0] == '#': - print >>sys.stderr, "Weird concat on line %s"%it.lineno + print >>sys.stderr, "Weird concat on line %s" % it.lineno elif line[0] in "},": if not data: - print >>sys.stderr, "No data after field on line %s"%( + print >>sys.stderr, "No data after field on line %s" % ( it.lineno) else: m = RAW_DATA_RE.match(line) @@ -214,12 +214,12 @@ class Parser: data.append(m.group(1)) line = m.group(2) else: - raise ParseError("Questionable line at line %s"%it.lineno) + raise ParseError("Questionable line at line %s" % it.lineno) # Got a string, check for concatenation. if line.isspace() or not line: data.append(" ") - line = _advance(it,line) + line = _advance(it, line) line = line.strip() assert line if line[0] == '#': @@ -231,23 +231,21 @@ class Parser: data = re.sub(r'\s+$', '', data) return data, line - def _parseEntry(self, line): #name, strings, entries + def _parseEntry(self, line): # name, strings, entries it = self.fileiter self.entryLine = it.lineno - line = _advance(it,line) + line = _advance(it, line) m = BRACE_BEGIN_RE.match(line) if not m: - raise ParseError("Expected an opening brace at line %s"%it.lineno) + raise ParseError("Expected an opening brace at line %s" % it.lineno) line = m.group(1) - proto = { 'string' : 'p', - 'preamble' : 'v', - }.get(self.curEntType, 'kp*') + proto = {'string': 'p', 'preamble': 'v'}.get(self.curEntType, 'kp*') v = [] - while 1: - line = _advance(it,line) + while True: + line = _advance(it, line) m = BRACE_END_RE.match(line) if m: @@ -265,7 +263,7 @@ class Parser: elif proto[0] == 'p': key, line = self._parseKey(line) v.append(key) - line = _advance(it,line) + line = _advance(it, line) line = line.lstrip() if line[0] == '=': line = line[1:] @@ -291,7 +289,7 @@ class Parser: else: key = v[0] d = {} - for i in xrange(1,len(v),2): + for i in xrange(1, len(v), 2): d[v[i].lower()] = v[i+1] ent = BibTeXEntry(self.curEntType, key, d) ent.entryLine = self.entryLine @@ -334,7 +332,8 @@ class Parser: raise ParseError("Bad input at line %s (expected a new entry.)" % it.lineno) -def _advance(it,line): + +def _advance(it, line): while not line or line.isspace() or COMMENT_RE.match(line): line = it.next() return line @@ -379,13 +378,14 @@ def parseString(string, result=None): return r if __name__ == '__main__': - if len(sys.argv)>1: - fname=sys.argv[1] + if len(sys.argv) > 1: + fname = sys.argv[1] else: - fname="testbib/pdos.bib" + fname = "testbib/pdos.bib" r = parseFile(fname) for e in r.entries: - if e.type in ("proceedings", "journal"): continue + if e.type in ("proceedings", "journal"): + continue print e.to_html() |
