def __parsefile__(self): self.dict = {} # Ouvrir le fichier associe self.parser = _bibtex.open_file(Open.url_to_local(self.key), Config.get('bibtex/strict').data) # Incorporer les definitions de l'utilisateur if not Config.get('bibtex+/override').data: user = Config.get('bibtex/macros').data valid = re.compile('^\w+$') for k in user.keys(): if not valid.match(k): raise TypeError, _(u"key “%s” is malformed") % k _bibtex.set_string( self.parser, k, _bibtex.reverse(_base_fieldtype[Text], Config.get('bibtex+/braces').data, user[k][0])) errors = [] # Creer la base de cles iter = BibtexIterator(self, self.parser) try: entry = iter.first() if entry is not None: if entry.key is None: self.add(entry) else: if self.dict.has_key(entry.key): errors.append( _(u"%s:%d: key “%s” already defined") % (str(self.key), entry.line, entry.key.key)) else: self.dict[entry.key] = entry except Exceptions.ParserError, err: errors.append(str(err))
def __setitem__(self, key, value): # First, set the cache for free self.__text[key] = (value, 0) if isinstance(value, Date): return # then, convert as bibtex. if isinstance(value, Reference): value = string.join(map(lambda item: item.key, value.list), ', ') self.dict[key] = _bibtex.reverse(_fieldtype(Types.get_field(key)), Config.get('bibtex+/braces').data, value) return
def convert(text, t): field = _bibtex.reverse(t, True, text) return _bibtex.get_latex(parser, field, t)
def _nativify(field, fieldtype): '''Private method to convert from field to native format.''' obj = _bibtex.reverse(fieldtype, Config.get('bibtex+/braces').data, field) return _bibtex.get_native(obj)
(repr(self.key), entry.line, repr(entry.key.key))) else: self.dict[entry.key] = entry if len(errors) > 0: raise Exceptions.ParserError(errors) # Incorporer les definitions de l'utilisateur if Config.get('bibtex+/override').data: user = Config.get('bibtex/macros').data valid = re.compile('^\w+$') for k in user.keys(): if not valid.match(k): raise TypeError, _(u"key “%s” is malformed") % k _bibtex.set_string( self.parser, k, _bibtex.reverse(_base_fieldtype[Text], Config.get('bibtex+/braces').data, user[k][0])) return def __str__(self): ''' ''' return '<BibTeX database `%s\' (%d entries)>' % \ (self.key, len (self)) def get_native(self, entry): ''' Return the object in its native format ''' stream = Utils.StringStream() entry_write(entry, stream) return stream.text def create_native(self, value):