Пример #1
0
    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, _("key `%s' is malformed") % k
		_bibtex.set_string(self.parser, k,
                                   _bibtex.reverse(_base_fieldtype[Text],
                                                   Config.get('bibtex+/braces').data,
                                                   user [k][0]))
	finished = 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(_("%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))
Пример #2
0
    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))
Пример #3
0
                if self.dict.has_key(entry.key):
                    errors.append(_("%s:%d: key `%s' already defined") % (
                        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, _("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):
Пример #4
0
                        _(u"%s:%d: key “%s” already defined") %
                        (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