import re from Pyblio.Format.DSL import lazy def maybe(value, prefix="", postfix="", default=""): if value: return prefix + value + postfix return default def _lastFirst(record, authors): return ["%s%s" % (x.last, maybe(x.first, prefix=", ")) for x in authors(record)] lastFirst = lazy(_lastFirst) def _firstLast(record, authors): return ["%s%s" % (maybe(x.first, postfix=" "), x.last) for x in authors(record)] firstLast = lazy(_firstLast) _ini_re = re.compile(r"([.-]|\s+)") def initials(name): """ Normalizes a first name as an initial """ if not name:
import re from Pyblio.Format.DSL import lazy def _pagesLong (record, pages): pages = pages(record) if pages.find ('-') == -1: # no dash, a single page then return u'page\xa0' + pages else: return u'pages\xa0' + pages pagesLong = lazy (_pagesLong)
# Copyright (C) 1998-2006 Frederic GOBRY # Email : [email protected] # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # """ Date formatting functions. """ from Pyblio.Format.DSL import lazy def year(record, date): """ Format a date by simply returning the year.""" return str(date(record).year) year = lazy(year)
@param sequence: The sequence whose item count will be used to generate the output. @type sequence: list @param zero: value returned when the sequence is empty @param one: value returned when the sequence has one item @param two: value returned when the sequence has two items @param more: value returned when the sequence has more than two items @note when a given parameter is not provided but should be returned, then the default is to use the value of the L{more} parameter. """ l = len (sequence(record)) if l == 0 and zero is not None: return zero(record) elif l == 1 and one is not None: return one(record) elif l == 2 and two is not None: return two(record) else: return more(record) plural = lazy (plural)