ó
‹²,]c           @  sí  d  Z  d d l m Z d d l Z d d l Z d d l j Z d d l Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l m Z d d l m Z m Z m Z m Z m Z m Z e j j d ƒ Z e j j d ƒ Z d „  Z e ró e
 j n e j d	 ƒ e
 j ƒ Z e
 j Z d
 „  Z  e  ƒ  Z! d „  Z" e
 j# j$ d ƒ rJd Z% n d Z% e rce% d Z% n  d „  Z& d „  Z' d d „ Z) d „  Z* d d d „ Z+ d d „ Z, d „  Z- g  a. d „  Z/ e/ e+ d d d ƒƒ d d „ Z0 e) d ƒ Z1 d Z2 i d d 6d  d! 6d" d# 6d$ d% 6d& d' 6d( d) 6d* d+ 6d, d- 6Z3 g  Z4 d. „  Z5 d/ „  Z6 d0 „  Z7 d1 „  Z8 d d2 „ Z9 e9 d ƒ Z: e; Z< d3 d4 d5 d6 d7 d8 d9 d: d; d< d= d> d? d@ dA dB dC dD dE g Z= dF Z> e rËdG Z? n dH Z? dI „  Z@ d] ZA d\ „  ZB d S(^   sß   
Spyder base configuration management

This file only deals with non-GUI configuration features
(in other words, we won't import any PyQt object here, avoiding any
sip API incompatibility issue in spyder's non-gui modules)
iÿÿÿÿ(   t   print_functionN(   t   encoding(   t
   is_unicodet
   TEXT_TYPESt	   INT_TYPESt   PY3t   to_text_stringt   is_text_stringt
   SPYDER_DEVt   SPYDER_SAFE_MODEc           C  s   t  t j j d ƒ ƒ S(   s½   
    Return True if currently running under py.test.

    This function is used to do some adjustment for testing. The environment
    variable SPYDER_PYTEST is defined in conftest.py.
    t   SPYDER_PYTEST(   t   boolt   ost   environt   get(    (    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   running_under_pytest,   s    s   utf-8c          C  s:   t  j j d d ƒ }  |  j ƒ  s0 t |  ƒ }  n  t |  ƒ S(   Nt   SPYDER_DEBUGt    (   R   R   R   t   isdigitR   t   int(   t	   debug_env(    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   _get_debug_env<   s    c          G  sl   t  rh t } t rU x- |  D]% } | j j t | ƒ j d ƒ ƒ q Wt d d | ƒqh t d | |  Œ n  d S(   s   Output debug messages to stdouts   utf-8R   t   fileN(   t   DEBUGt   STDOUTR   t   buffert   writet   strt   encodet   print(   t   messaget   sst   m(    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   debug_printC   s    #t   linuxt   spyders   .spyders   -py3c          C  sª   y t  j t j d ƒ ƒ }  Wn t k
 r5 d }  n Xt j |  ƒ rI |  SxE d D]= } t  j t j j | d ƒ ƒ }  t j |  ƒ r‡ |  Sd }  qP W|  s¦ t	 d ƒ ‚ n  d S(	   s$   
    Return user home directory
    t   ~R   t   HOMEt   USERPROFILEt   TMPsg   Please set the environment variable HOME to your user/home directory path so Spyder can start properly.N(   R%   R&   R'   (
   R   t   to_unicode_from_fst   ospt
   expandusert	   Exceptiont   isdirR   R   R   t   RuntimeError(   t   patht   env_var(    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   get_home_dirg   s    

c          C  s_   t  j j d ƒ r d }  n d t t j ƒ  ƒ }  t j t t j	 ƒ  ƒ d j
 |  ƒ t ƒ } | S(   sU   
    Return the path to a temp clean configuration dir, for tests and safe mode.
    t   winR   t   -s   pytest-spyder{0!s}(   t   syst   platformt
   startswithR   t   getpasst   getuserR)   t   joint   tempfilet
   gettempdirt   formatt	   SUBFOLDER(   t   current_usert   conf_dir(    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   get_clean_conf_dir‡   s    		c         C  s  t  ƒ  s t r t ƒ  } nŽ t j j d ƒ r” t j j d d ƒ } | s` t	 j
 t ƒ  d ƒ } n  t	 j | ƒ s t j | ƒ n  t	 j
 | t ƒ } n t	 j
 t ƒ  t ƒ } t	 j | ƒ sç t  ƒ  sÇ t r× t j | ƒ qç t j | ƒ n  |  d k r÷ | St	 j
 | |  ƒ Sd S(   sD   Return absolute path to the config file with the specified filename.R"   t   XDG_CONFIG_HOMER   s   .configN(   R   t	   SAFE_MODER?   R3   R4   R5   R   R   R   R)   R8   R0   R,   t   makedirsR<   t   mkdirt   None(   t   filenameR>   t   xdg_config_home(    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   get_conf_path–   s"    c         C  s    t  j t  j t j |  j ƒ ƒ S(   s!   Return module *modname* base path(   R)   t   abspatht   dirnameR3   t   modulest   __file__(   t   modname(    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   get_module_path´   s    t   DATAPATHc         C  s²   t  t j |  | d ƒ } | r# | St |  ƒ } t j | t j ƒ } t j | ƒ r€ t j t j t j | t j ƒ |  ƒ ƒ } n  | d k	 rª t j t j | | ƒ ƒ } n  | Sd S(   s›   Return module *modname* data path
    Note: relpath is ignored if module has an attribute named *attr_name*
    
    Handles py2exe/cx_Freeze distributionsR   N(
   t   getattrR3   RJ   RM   R)   R8   t   pardirt   isfileRH   RD   (   RL   t   relpatht	   attr_namet   datapatht	   parentdir(    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   get_module_data_path¹   s    c         C  s‹   t  |  ƒ } t j | t j ƒ } t j | ƒ r] t j t j t j | t j ƒ |  ƒ ƒ } n  | d k	 r‡ t j t j | | ƒ ƒ } n  | S(   sC  Return module *modname* source path
    If *basename* is specified, return *modname.basename* path where 
    *modname* is a package containing the module *basename*
    
    *basename* is a filename (not a module name), so it must include the
    file extension: .py or .pyw
    
    Handles py2exe/cx_Freeze distributionsN(   RM   R)   R8   RP   RQ   RH   RD   (   RL   t   basenamet   srcpathRU   (    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   get_module_source_pathÎ   s    	c           C  s"   t  j t  j t d ƒ t  j ƒ ƒ S(   s@   Return True if this is a py2exe/cx_Freeze distribution of SpyderR#   (   R)   RQ   R8   RM   RP   (    (    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   is_py2exe_or_cx_Freezeã   s    c         C  sq   t  j |  ƒ s d  St j |  ƒ xJ t j |  ƒ D]9 \ } } } x' | D] } t j t  j | | ƒ ƒ qF Wq0 Wd  S(   N(   R)   R,   t   IMG_PATHt   appendR   t   walkR8   (   R.   t   dirpatht   dirnamest
   _filenamesRI   (    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   add_image_pathì   s    RR   t   imagess   not_found.pngc         C  s€   x< t  D]4 } t j | |  ƒ } t j | ƒ r t j | ƒ Sq W| d k	 r| t j t d ƒ d ƒ } t j t j | | ƒ ƒ Sd S(   s   Return image absolute pathR#   Rb   N(   R[   R)   R8   RQ   RH   RD   RM   (   t   namet   defaultt   img_patht	   full_path(    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   get_image_path÷   s    t
   langconfigt   enu   Englishu   Deutscht   deu	   FranÃ§aist   fru   EspaÃ±olt   esu   Magyart   huu
   PortuguÃªst   pt_BRu   Ð ÑƒÑÑÐºÐ¸Ð¹t   ruu	   æ—¥æœ¬èªžt   jac          C  s¼   t  d d d d d ƒ}  t j |  ƒ } g  | D]' } t j t j |  | ƒ ƒ r. | ^ q. } t g | } t t | ƒ t t	 ƒ ƒ } x1 | D]) } | t
 k r‹ d } t | ƒ d g Sq‹ W| S(   s  
    List available translations for spyder based on the folders found in the
    locale folder. This function checks if LANGUAGE_CODES contain the same
    information that is found in the 'locale' folder to ensure that when a new
    language is added, LANGUAGE_CODES is updated.
    R#   RR   t   localeRS   t
   LOCALEPATHs[   Update LANGUAGE_CODES (inside config/base.py) if a new translation has been added to SpyderRi   (   RV   R   t   listdirR)   R,   R8   t   DEFAULT_LANGUAGEt   listt   sett   DISABLED_LANGUAGESt   LANGUAGE_CODESR   (   t   locale_pathRs   t   dt   langst   langt   error(    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   get_available_translations  s    	4
c          C  s±   y t  j ƒ  d }  Wn t k
 r- t }  n Xt ƒ  r@ t }  n  t } |  d k	 r­ t ƒ  } xO | D]D } |  | k r~ |  } Pqb |  j | ƒ sœ | j |  ƒ rb | } Pqb qb Wn  | S(   s  
    If Spyder has a translation available for the locale language, it will
    return the version provided by Spyder adjusted for language subdifferences,
    otherwise it will return DEFAULT_LANGUAGE.

    Example:
    1.) Spyder provides ('en',  'de', 'fr', 'es' 'hu' and 'pt_BR'), if the
    locale is either 'en_US' or 'en' or 'en_UK', this function will return 'en'

    2.) Spyder provides ('en',  'de', 'fr', 'es' 'hu' and 'pt_BR'), if the
    locale is either 'pt' or 'pt_BR', this function will return 'pt_BR'
    i    N(   Rq   t   getdefaultlocalet
   ValueErrorRt   R   RD   R~   R5   (   t   locale_languaget   languaget   spyder_languagesR|   (    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   get_interface_language2  s$    
			c         C  sA   y) t  t d ƒ  } | j |  ƒ Wd QXWn t k
 r< n Xd S(   s-   Save language setting to language config filet   wN(   t   opent	   LANG_FILER   t   EnvironmentError(   t   valuet   f(    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   save_lang_confZ  s
    c          C  su   t  j t ƒ r6 t t d ƒ  }  |  j ƒ  } Wd QXn t ƒ  } t | ƒ | j d ƒ t k rq t	 } t | ƒ n  | S(   sË   
    Load language setting from language config file if it exists, otherwise
    try to use the local settings if Spyder provides a translation, or
    return the default if no translation provided.
    t   rNs   
(
   R)   RQ   R‡   R†   t   readR„   R‹   t   stripRw   Rt   (   RŠ   R|   (    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   load_lang_conff  s    	
c           sá   | d
 k r |  } n  d „  } t | d d d d ƒ} t ƒ  } t j d k rw y | t j d <Wq„ t k
 rs | SXn | t j d <d	 d
 l } y8 | j |  | d d ƒ} | j	 ‰  ‡  f d †  } | SWn t k
 rÜ | SXd
 S(   s0   Return translation callback for module *modname*c         S  s   t  |  ƒ s t |  d ƒ S|  S(   s&   Dumb function to not use translations.s   utf-8(   R   R   (   t   x(    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   translate_dumb€  s    RR   Rq   RS   Rr   t   ntt   LANGt   LANGUAGEiÿÿÿÿNt   codesets   utf-8c           sX   t  r% t |  ƒ r% |  j d ƒ }  n  ˆ  |  ƒ } t | ƒ rG t  rG | St | d ƒ Sd  S(   Ns   utf-8(   R   R   R   R   R   (   R   t   y(   t   lgettext(    s1   lib/python2.7/site-packages/spyder/config/base.pyt   translate_gettext›  s    (
   RD   RV   R   R   Rc   R   R+   t   gettextt   translationR—   (   RL   RI   R‘   Ry   R‚   R™   t   _transR˜   (    (   R—   s1   lib/python2.7/site-packages/spyder/config/base.pyt   get_translation{  s(    					t   nant   inft   inftyt   little_endiant   colorbar_doct	   typecodest   __builtins__t   __main__t   __doc__t   NaNt   Inft   Infinityt   sctypest   rcParamst   rcParamsDefaultt   sctypeNAt   typeNAt   False_t   True_i   s
   Spyder.apps   Spyder-Py2.appc           C  s'   t  j d k r t t k r t St Sd  S(   Nt   darwin(   R3   R4   t   MAC_APP_NAMERK   t   Truet   False(    (    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   running_in_mac_appÃ  s    t   helpt
   onlinehelpR.   s   pylint.resultss
   spyder.inis   temp.pys   temp.spydatas   template.pys
   history.pys   history_internal.pyt
   workingdirs	   .projectss   .spyprojects   .ropeprojects   monitor.logs   monitor_debug.logs   rope.logs   spyder.lockc          C  s”   t  d d t ƒx} t D]u }  t |  ƒ } t j | ƒ sG t j | ƒ rW t j | ƒ n" t j	 | ƒ r t
 j | ƒ n q t  d | d t ƒq Wd S(   s   Remove all config filess)   *** Reset Spyder settings to defaults ***R   s	   removing:N(   R   t   STDERRt   SAVED_CONFIG_FILESRG   R)   RQ   t   islinkR   t   removeR,   t   shutilt   rmtree(   t   fnamet	   cfg_fname(    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   reset_config_filesÕ  s    (   Rµ   R¶   R.   s   pylint.resultss
   spyder.inis   temp.pys   temp.spydatas   template.pys
   history.pys   history_internal.pyR·   s	   .projectss   .spyprojects   .ropeprojects   monitor.logs   monitor_debug.logs   rope.logRh   s   spyder.lock(C   R¥   t
   __future__R    t   codecsRq   t   os.pathR.   R)   R   R¼   R3   R6   R9   t   spyder.utilsR   t   spyder.py3compatR   R   R   R   R   R   R   R   t   DEVRA   R   t   stdoutt	   getwriterR   t   stderrR¸   R   R   R!   R4   R5   R<   R0   R?   RD   RG   RM   RV   RY   RZ   R[   Ra   Rg   R‡   Rt   Rx   Rw   R~   R„   R‹   R   Rœ   t   _R³   t	   CHECK_ALLt   EXCLUDED_NAMESt   PICKLE_PROTOCOLR±   R´   R¹   RÀ   (    (    (    s1   lib/python2.7/site-packages/spyder/config/base.pyt   <module>   sŠ   .		'						 					

		(		-		
     