def parse(self, fd, db): self.db = db self.doctype = {} rs = db.rs.new() rs.name = _('Imported from BibTeX') for v in db.schema.txo['doctype'].values (): self.doctype [v.names ['C'].lower ()] = v for data in Parser.read (fd, self.charset): if isinstance (data, Parser.Comment): self.comment_add (data) continue self.record = None self.record_parse (data) if self.record: k = self.db.add (self.record) rs.add(k) return rs
def testArobasComment (self): comment = u'@comment (gronf' io = StringIO.StringIO (comment.encode ('utf-8')) re = list (Parser.read (io)) assert re == [Parser.Comment (' (gronf')], 'got %s' % re
def _cmp (self, bib, obj, charset='utf-8'): io = StringIO.StringIO(bib) re = list(Parser.read(io, charset=charset)) ri = eval(obj) assert ri == re, 'got\n\t %s\n instead of\n\t %s' % ( repr (re), repr (ri))
def testMixed (self): c = u''' toto @comment gronf tutu ''' io = StringIO.StringIO (c.encode ('utf-8')) re = [ type (x) for x in Parser.read (io)] assert re == [Parser.Comment, Parser.ATComment, Parser.Comment]
def testComment (self): comment = u''' % a simple test, héhé Random comments ''' io = StringIO.StringIO (comment.encode ('utf-8')) re = list (Parser.read (io)) assert re == [Parser.Comment (comment)]
def __init__(self, filename, charset='UTF-8'): self.charset = charset self.filename = filename self.content = _LinkedList() self.records = {} if self.filename: fh = open(filename) for record in Parser.read(fh, self.charset): l = self.content.Append(record) if isinstance(record, Parser.Record) and record.key: # yay, a real record! self.records[record.key.flat()] = l