Ńň
RüLc           @   s~  d  d k  Z  d  d k Z d  d k Z d  d k l Z d  d k Z d e f d     YZ d e f d     YZ d e f d     YZ	 d	 e
 f d
     YZ e d j oŐ e   Z d Ge i   GHy e i   Z Wn e j
 o d GHn Xd Ge i d  GHd Ge i   GHy d Ge i   GHWn e	 j
 o d GHn Xd GHe i   y e i   Z d GHWqze j
 o d GHqzXn d S(   i˙˙˙˙N(   t
   LocaleInfot   ExceptionMultipleConfigurationsc           B   s   e  Z d  Z RS(   s-    error when multiple languages are symlinked (   t   __name__t
   __module__t   __doc__(    (    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/FontConfig.pyR      s   t   ExceptionUnconfiguredc           B   s   e  Z d  Z RS(   s"    error if no configuration is set (   R   R   R   (    (    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/FontConfig.pyR      s   t   ExceptionNoConfigForLocalec           B   s   e  Z d  Z RS(   s2    error if there is no config for the given locale (   R   R   R   (    (    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/FontConfig.pyR      s   t   FontConfigHackc           B   sS   e  Z d  Z d d d  Z d   Z d   Z d   Z d   Z d   Z d	   Z	 RS(
   s    abstract the fontconfig hack s   /usr/share/language-selector/s
   /etc/fontsc         C   s5   d | |  _  | |  _ | |  _ t d |  |  _ d  S(   Ns   %s/fontconfigt   languagelist(   t   datadirt   _datadirt   globalConfDirR    t   li(   t   selfR	   R   (    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/FontConfig.pyt   __init__    s    		c         C   sT   t  i i t  i i |   d } t i | d d  \ } } } d | | i   f S(   sŢ    
        internal helper to extracr from our fontconfig filenames
        of the form 69-language-selector-zh-tw.conf the locale
        and country

        returns string of the form locale_COUTNRY (e.g. zh_TW)
        i    t   -i   s   %s_%s(   t   ost   patht   splitextt   basenamet   stringt   rsplitt   upper(   R   t   namet   fnamet   headt   llt   cc(    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/FontConfig.pyt   _getLocaleCountryFromFileName'   s    "c         C   sG   g  } d |  i  } x- t i |  D] } | i |  i |   q# W| S(   sq    get the configurations we have as a list of languages
            (returns a list of ['zh_CN','zh_TW'])
        s$   %s/conf.avail/69-language-selector-*(   R   t   globt   appendR   (   R   t   rest   patternR   (    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/FontConfig.pyt   getAvailableConfigs2   s     c         C   sm   d |  i  } t i |  } t |  d j o t    n t |  d j o t    n |  i | d  S(   s   returns the current language configuration as a string (e.g. zh_CN)
        
            if the configfile is not a symlink it raises a
             ExceptionNotSymlink exception
            if the file dosn't exists raise a
             ExceptionUnconfigured exception
        s    %s/conf.d/69-language-selector-*i    i   (   R   R   t   lenR   R   R   (   R   R    t   current_config(    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/FontConfig.pyt   getCurrentConfig;   s    c         C   sO   d |  i  } x; t i |  D]* } t i i |  o t i |  q q Wd S(   se    removes the current fontconfig-voodoo configuration
            and do some sanity checking
        s   %s/conf.d/*-language-selector-*N(   R   R   R   R   t   existst   unlink(   R   R    t   f(    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/FontConfig.pyt   removeConfigK   s
     c   	      C   s  t  i |  i |  } | d } | |  i   j o t    n |  i   d |  i } xľ d | d | d i   f d | d g D] } x~ t i t	 i
 i | |   D]^ } t	 i
 i |  } t	 i
 i |  i d |  } t	 i
 i |  i d |  } t	 i | |  q¨ Wq Wt S(	   s    set the configuration for 'locale'. if locale can't be
            found a NoConfigurationForLocale exception it thrown
        t   LOCALEs   %s/conf.avail/s   *-language-selector-%s-%s.conft   LCODEt   CCODEs   *-language-selector-%s.confs
   conf.avails   conf.d(   t   macrost   LangpackMacrosR
   R!   R   R(   R   t   lowerR   R   R   t   joinR   t   symlinkt   True(	   R   t   localet   macrt   basedirR    R'   R   t	   from_linkt   to_link(    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/FontConfig.pyt	   setConfigT   s     

  c         C   sa   |  i  i   d } t |  d j o |  i  i   d } n | i d  d } |  i |  d S(   sŔ    set the configuration based on the locale in LocaleInfo. If
            no configuration is found the fontconfig config is set to
            'none'
            Can throw a exception
        i   i    t   :N(   R   t   getUserDefaultLanguageR"   t   getSystemDefaultLanguaget   splitR7   (   R   t   lang(    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/FontConfig.pyt   setConfigBasedOnLocalek   s
    (
   R   R   R   R   R   R!   R$   R(   R7   R=   (    (    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/FontConfig.pyR      s   							t   __main__s   available: t   unconfigureds   set config: t   zh_CNs	   current: s   run auto mode: s   no config for this locales   removeConfig()s/   ERROR: have config after calling removeConfig()s   unconfigured (as expected)(   R   R   t   os.pathR   R    R,   t	   ExceptionR   R   R   t   objectR   R   t   fcR!   R$   t   configR7   R=   R(   (    (    (    s?   /usr/lib/python2.6/dist-packages/LanguageSelector/FontConfig.pyt   <module>   s8   Z	


	