Package Gnumed :: Module sitecustomize
[frames] | no frames]

Source Code for Module Gnumed.sitecustomize

 1  # -*- coding: utf8 -*- 
 2  """GNUmed site customization file. 
 3   
 4  This file sets up the default string encoding for Python. 
 5   
 6  Some countries will be able to get by without this file, 
 7  eg those using the 7-bit US-ASCII character set (without 
 8  those weird accents and stuff). Most others will need to 
 9  set the proper value here. 
10   
11  Most European countries will be OK with 'iso8859-1' or 
12  'iso8859-15'. On Linux you can find out a suitable encoding 
13  by running "locale charmap". On Windows, tough luck. 
14   
15  If you need this file you will see an error like this: 
16   
17  File "/usr/lib/python2.4/site-packages/Gnumed/business/gmPerson.py", line 836, in __normalize 
18          normalized =    aString.replace(u'ä'.encode('latin-1'), u'(Ä|AE|Ae|A|E)'.encode('latin-1')) 
19          UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: ordinal not in range(128) 
20   
21  when trying to search for a patient. There is a built-in test below 
22  but that approach may not be fool-proof. 
23  """ 
24  #============================================================== 
25  # $Source: /home/ncq/Projekte/cvs2git/vcs-mirror/gnumed/gnumed/client/sitecustomize.py,v $ 
26  # $Id: sitecustomize.py,v 1.8 2009-12-21 14:56:39 ncq Exp $ 
27  __version__ = "$Revision: 1.8 $" 
28  __author__  = "Karsten Hilbert <Karsten.Hilbert@gmx.net>" 
29  __license__ = "GPL v2 or later (details at http://www.gnu.org)" 
30   
31  import sys 
32   
33  # flip this flag if you need to set the encoding explicitly 
34  do_set_encoding = False 
35   
36  # - most European countries but shouldn't 
37  #   hurt in US-ASCII countries, either 
38  # - includes the EURO symbol 
39  def_encoding = 'iso8859-15' 
40   
41  # - for testing 
42  #def_encoding = 'ascii' 
43  #============================================================== 
44  if __name__ == '__main__': 
45          print "------------------------------------------------" 
46          print "This file is not intended to be run standalone." 
47          print "It is used in the Python/GNUmed startup process." 
48          print "Please consult the Python docs for details." 
49          print "------------------------------------------------" 
50          sys.exit() 
51   
52  if do_set_encoding: 
53          print "GNUmed startup: Setting Python string encoding to [%s]" % def_encoding 
54          try: 
55                  sys.setdefaultencoding(def_encoding) 
56          except LookupError: 
57                  print "GNUmed startup: Cannot set Python string encoding to invalid value [%s]" % def_encoding 
58                  print "GNUmed startup: Default Python string encoding is [%s]" % sys.getdefaultencoding() 
59                  print "GNUmed startup: GNUmed is likely to fail where non-7-bit-ASCII is involved" 
60          except AttributeError: 
61                  print "GNUmed startup: Python string encoding must have been set already ?!?" 
62   
63  #============================================================== 
64  # $Log: sitecustomize.py,v $ 
65  # Revision 1.8  2009-12-21 14:56:39  ncq 
66  # - typo fix 
67  # 
68  # Revision 1.7  2007/05/08 11:14:11  ncq 
69  # - make utf8 
70  # - some cleanup 
71  # 
72  # Revision 1.6  2006/10/23 13:27:37  ncq 
73  # - this is only an example, don't activate it by default 
74  # 
75  # Revision 1.5  2005/09/28 21:18:36  ncq 
76  # - need to explicitely set encoding on our reference platform 
77  #   (Debian Sarge with wx2.6 from testing) 
78  # 
79  # Revision 1.4  2005/06/20 20:55:00  ncq 
80  # - apparently wxPython or something messes with the encoding so 
81  #   while testing the encoding works the same code fails after 
82  #   wxPython startup, so don't test, use explicit flag, default False 
83  # 
84  # Revision 1.3  2005/06/20 20:41:30  ncq 
85  # - improved again, it might even work 
86  # 
87  # Revision 1.2  2005/06/20 19:42:25  ncq 
88  # - improved 
89  # 
90  # Revision 1.1  2005/06/20 18:54:32  ncq 
91  # - can be used as an example 
92  # 
93