Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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))
Exemplo n.º 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]
Exemplo n.º 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)]
Exemplo n.º 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