Package biblio :: Package webquery :: Module impl
[hide private]
[frames] | no frames]

Source Code for Module biblio.webquery.impl

 1  #! /usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3  """ 
 4  Various (fragile) implementation details and utilities. 
 5   
 6  Don't reply on these because they may go away. 
 7   
 8  """ 
 9  # TODO: error-handling logic is correct? 
10   
11  __docformat__ = 'restructuredtext en' 
12   
13   
14  ### IMPORTS ### 
15   
16  try:  
17     from xml.etree import ElementTree 
18  except: 
19     from elementtree import ElementTree 
20   
21  __all__ = [ 
22     'ElementTree', 
23     'ReprObj', 
24     'normalize_isbn', 
25     'assert_or_raise', 
26  ] 
27   
28   
29  ### CONSTANTS & DEFINES ### 
30   
31  ### IMPLEMENTATION ### 
32   
33 -class ReprObj (object):
34 """ 35 A class with an simple and consistent printable version. 36 """ 37 _repr_fields = [ 38 # override in derived classes 39 ] 40
41 - def __str__ (self):
42 return self.__unicode__().encode ('utf8')
43
44 - def __unicode__ (self):
45 repr_strs = ["%s: '%s'" % (field, getattr (self, field)) for field in 46 self._repr_fields] 47 return "%s (%s)" % (self.__class__.__name__, '; '.join (repr_strs))
48
49 - def __repr__ (self):
50 return str (self)
51 52
53 -def assert_or_raise (cond, error_cls, error_msg=None):
54 """ 55 If a condition is not met, raise a assertion with this message. 56 """ 57 if (not cond): 58 if error_msg: 59 error = error_cls (error_msg) 60 else: 61 error = error_cls() 62 raise error
63 64 65 ### TEST & DEBUG ### 66
67 -def _doctest ():
68 import doctest 69 doctest.testmod()
70 71 72 ### MAIN ### 73 74 if __name__ == '__main__': 75 _doctest() 76 77 78 ### END ###################################################################### 79