1 import re
2
3 from Pyblio.Format.DSL import lazy
4
5
6 -def maybe (value, prefix = '', postfix = '', default = ''):
7 if value: return prefix + value + postfix
8 return default
9
11 return [ '%s%s' % (x.last, maybe (x.first, prefix = ', '))
12 for x in authors(record) ]
13
14 lastFirst = lazy (_lastFirst)
15
17 return [ '%s%s' % (maybe (x.first, postfix = ' '), x.last)
18 for x in authors(record) ]
19
20 firstLast = lazy (_firstLast)
21
22 _ini_re = re.compile (r'([.-]|\s+)')
23
25 """ Normalizes a first name as an initial """
26
27 if not name:
28 return None
29
30
31
32 if (name.upper() == name and
33 len(name) < 4 and
34 _ini_re.search(name) is None):
35 return '.'.join(name) + '.'
36
37 res = []
38
39 for p in _ini_re.split (name):
40 if not p.strip () or p == '.': continue
41
42 if p != '-': p = p [0] + '.'
43
44 res.append (p)
45
46 return ''.join (res)
47
49 return [ '%s%s' % (maybe (initials (x.first), postfix = ' '), x.last)
50 for x in authors(record) ]
51
52 initialLast = lazy (_initialLast)
53