ó
ø`9Sc           @   s­   d  Z  d d l Z d d l Z d d l Z d d l Z d „  Z d „  Z d „  Z d „  Z e	 e	 d „ Z
 e	 e	 d „ Z d	 „  Z d
 „  Z d „  Z d e f d „  ƒ  YZ d S(   s*   Miscellaneous text manipulation functions.iÿÿÿÿNc         C   s]   |  j  d d ƒ }  y t |  ƒ } Wn t k
 r6 d SXt j | ƒ sU t j | ƒ rY d S| S(   sv   Return a finite floating point number represented by 'string' or 'None'
    if the conversion can not be accomplished.t   ,t   .N(   t   replacet   floatt
   ValueErrort   Nonet   matht   isinft   isnan(   t   stringt   value(    (    s   code\common\utils\txt.pyt   stringToFloat   s    c         C   s)   y t  |  ƒ } Wn t k
 r$ d SX| S(   sb   Return an integer represented by 'string' or 'None' if the conversion
    can not be accomplished.N(   t   intR   R   (   R	   R
   (    (    s   code\common\utils\txt.pyt   stringToInt-   s
    c         C   s   t  |  ƒ }  t j j |  ƒ sQ t j ƒ  } t j | ƒ } t j j | |  ƒ }  n  t j j |  ƒ }  t j j	 |  ƒ \ } } | j
 ƒ  | }  |  S(   sM   Return an absolute and properly formatted version of the given file
    path.(   t   unicodet   ost   patht   isabst   getcwdut   win32apit   GetLongPathNameWt   joint   normpatht
   splitdrivet   upper(   R   t
   curDirPatht   drivet   tail(    (    s   code\common\utils\txt.pyt   absolutePath9   s    		c         C   s¥   t  |  ƒ } t  d ƒ } t j j | ƒ t j j | ƒ k r@ d S| t j 7} t j j | ƒ j t j j | ƒ ƒ s} | } n t j j | | ƒ } | j t j d ƒ S(   s   Return a version of the given file path that is suitable for storage in
    a settings file to be loaded during the next application startup.R   t   /(   R   R   R   t   normcaset   sept
   startswitht   relpathR   (   R   t   absPathR   t   portablePath(    (    s   code\common\utils\txt.pyR#   c   s    
$'	c         C   sF   |  j  d d ƒ }  |  j  d d ƒ }  |  j  d d ƒ }  t |  | | ƒ S(   sB   Return a copy of 'text' enclosed in boldface font tags and quotes.t   &s   &amp;t   <s   &lt;t   >s   &gt;(   R   t   quoteRichText(   t   textt   setBoldFontt	   addQuotes(    (    s   code\common\utils\txt.pyt   quote‹   s    c         C   s2   | r d |  d }  n  | r. d |  d }  n  |  S(   sD   Same as 'quote', but allow HTML formatting to be embedded in 'text'.u   â€œu   â€s   <b>s   </b>(    (   R(   R)   R*   (    (    s   code\common\utils\txt.pyR'   •   s
    c         C   s2   t  |  ƒ }  |  j t j t j d ƒ }  t |  ƒ S(   sx   Return an absolute and properly formatted version of the given file
    path, enclosed in boldface font tags and quotes.u   â€‹(   R   R   R   R   R+   (   R   (    (    s   code\common\utils\txt.pyt	   quotePathŸ   s    c         C   s   t  t |  ƒ d t ƒS(   sˆ   Same as 'quote', but take an integer or a floating point number as the
    argument and do not add quotes to it, just the boldface tags.R*   (   R+   t   strt   False(   t   number(    (    s   code\common\utils\txt.pyt   quoteNumber«   s    c         C   s   |  j  d d ƒ j  d d ƒ S(   se   Return a copy of 'text' without any of the formatting tags that might
    have been added by 'quote'.s   <b>t    s   </b>(   R   (   R(   (    (    s   code\common\utils\txt.pyt   unQuote±   s    t   Errorc           B   s   e  Z d  Z d „  Z RS(   s.   An 'Exception' that holds a rich text message.c         C   s   | |  _  d  S(   N(   R(   (   t   selfR(   (    (    s   code\common\utils\txt.pyt   __init__»   s    (   t   __name__t
   __module__t   __doc__R5   (    (    (    s   code\common\utils\txt.pyR3   ¸   s   (   R8   R   R   t   os.pathR   R   R   R   R#   t   TrueR+   R'   R,   R0   R2   t	   ExceptionR3   (    (    (    s   code\common\utils\txt.pyt   <module>   s   			*	(

			