예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
    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))
예제 #4
0
    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]
예제 #5
0
    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)]
예제 #6
0
    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