home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / softwareproperties / CountryInformation.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  1.7 KB  |  47 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import gettext
  6. from xml.etree.ElementTree import ElementTree
  7.  
  8. class CountryInformation(object):
  9.     
  10.     def __init__(self):
  11.         self.countries = { }
  12.         fname = '/usr/share/xml/iso-codes/iso_3166.xml'
  13.         if os.path.exists(fname):
  14.             et = ElementTree(file = fname)
  15.             it = et.getiterator('iso_3166_entry')
  16.             for elm in it:
  17.                 if elm.attrib.has_key('common_name'):
  18.                     descr = elm.attrib['common_name']
  19.                 else:
  20.                     descr = elm.attrib['name']
  21.                 if elm.attrib.has_key('alpha_2_code'):
  22.                     code = elm.attrib['alpha_2_code']
  23.                 else:
  24.                     code = elm.attrib['alpha_3_code']
  25.                 self.countries[code] = gettext.dgettext('iso_3166', descr)
  26.             
  27.         
  28.         self.country = None
  29.         self.code = None
  30.         locale = os.getenv('LANG', default = 'en.UK')
  31.         a = locale.find('_')
  32.         z = locale.find('.')
  33.         if z == -1:
  34.             z = len(locale)
  35.         
  36.         self.code = locale[a + 1:z]
  37.         self.country = self.get_country_name(self.code)
  38.  
  39.     
  40.     def get_country_name(self, code):
  41.         if self.countries.has_key(code):
  42.             name = self.countries[code]
  43.             return name
  44.         return code
  45.  
  46.  
  47.