1
2
3 """
4 Classes for representing bibliographic records and authors.
5
6 These are not the intended major function of this module, but are necessary for translation
7 between formats.
8
9 Variously based upon:
10
11 * pymarc
12 * bibconverter
13 * bibliograph.core and bibliograph.parsing
14
15 """
16
17 __docformat__ = 'restructuredtext en'
18
19
20
21
22 import re
23
24 from biblio.webquery import impl
25
26
27
28
29 SHORT_TITLE_SPLIT_RE = re.compile ('[:\?]')
30
31
32
33
35
36
37 _repr_fields = [
38 'id',
39 'type',
40 'lang',
41 'title',
42 'authors',
43 'year',
44 'edited',
45 'abstract',
46 'keywords',
47 'publisher',
48 'journal',
49 'note',
50 'ext_references',
51 ]
53 """
54 C'tor.
55 """
56 self.id = u''
57 self.type = u''
58 self.title = u''
59 self.lang = u''
60 self.authors = []
61 self.year = None
62 self.edited = False
63 self.abstract = u''
64 self.keywords = []
65 self.publisher = u''
66 self.journal = u''
67 self.note = u''
68 self.ext_references = {}
69
71 refs = self.ext_references.get (key, [])
72 refs.extend (list (val))
73 self.ext_references[key] = refs
74
76 match = SHORT_TITLE_SPLIT_RE.search (self.title)
77 if (match):
78 return self.title[:match.start()].strip()
79 else:
80 return self.title
81
82 short_title = property (get_short_title)
83
84
85
87 """
88 A name, as used for authors and editors.
89
90 The terms 'given', 'other' and 'family' are used in preference to other
91 schemes, as they are more culture-neutral and do not assume any particular
92 ordering.
93
94 given
95 The first / christian or forename, e.g. 'John'.
96 other
97 Any middle names, e.g. 'James Richard'.
98 family
99 surname, last name, e.g. 'Smith'.
100
101 """
102
103
104 _repr_fields = [
105 'prefix',
106 'title',
107 'given',
108 'other',
109 'family',
110 'suffix',
111 ]
112
113 - def __init__ (self, given, other=None, family=None, title=None,
114 prefix=None, suffix=None):
115 """
116 C'tor, requiring only the given name.
117
118 Note that the only required argument is the given name, allowing single
119 names (e.g. 'Madonna'). Also the order of positional arguments allows a
120 a regular name to be passed as 'John', 'James', 'Smith'.
121
122 """
123 self.given = given
124 self.other = other
125 self.family = family
126 self.title = title
127 self.prefix = prefix
128 self.suffix = suffix
129
131 """
132 Return a readable formatted version of the name.
133 """
134 fields = [getattr (self, f, '') for f in self._repr_fields]
135 return u' '.join ([f for f in fields if f])
136
138 """
139 Return a representation of this object.
140 """
141
142 return impl.ReprObj.__repr__ (self)
143
144
145
146
147
149 import doctest
150 doctest.testmod()
151
152
153
154
155 if __name__ == '__main__':
156 _doctest()
157
158
159
160