mς
ΌΉEFc           @   sX   d  Z  d k Z d k Z d k l Z d Z d e f d     YZ d f  d     YZ d S(   sό  Generate binary message catalog from textual translation description.

This program converts a textual Uniforum-style message catalog (.po file) into
a binary GNU catalog (.mo file).  This is essentially the same function as the
GNU msgfmt program, however, it is a simpler implementation.

This file was taken from Python-2.3.2/Tools/i18n and altered in several ways.
Now you can simply use it from another python module:

  from msgfmt import Msgfmt
  mo = Msgfmt(po).get()

where po is path to a po file as string, an opened po file ready for reading or
a list of strings (readlines of a po file) and mo is the compiled mo
file as binary string.

Exceptions:

  * IOError if the file couldn't be read

  * msgfmt.PoSyntaxError if the po file has syntax errors

N(   s   StringIOs   1.1ptst   PoSyntaxErrorc           B   s    t  Z d  Z d   Z d   Z RS(   s    Syntax error in a po file c         C   s   | |  _  d  S(   N(   t   msgt   self(   R   R   (    (    tQ   /home2/kennisonb/webapps/zope/Zope/Products/PlacelessTranslationService/msgfmt.pyt   __init__)   s    c         C   s   d |  i S(   Ns   Po file syntax error: %s(   R   R   (   R   (    (    R   t   __str__,   s    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    R   R    '   s    	t   Msgfmtc           B   sP   t  Z d  Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(	   t    t   unknownc         C   s   | |  _  | |  _ h  |  _ d  S(   N(   t   poR   t   namet   messages(   R   R   R   (    (    R   R   1   s    		c         C   s°   g  } t |  i t  o# |  i i d  |  i i   } n t |  i t  o |  i } n t |  i t  o t	 |  i d  i   } n | p t
 d t |  i   n | S(   s8    read po data from self.po and store it in self.poLines i    t   rbs   self.po is invalid! %sN(   t   outputt
   isinstanceR   R   t   filet   seekt	   readlinest   listt   strt   opent
   ValueErrort   type(   R   R   (    (    R   t
   readPoData6   s     c         C   s$   | o | o | |  i | <n d S(   s<   Add a non-empty and non-fuzzy translation to the dictionary.N(   R   t   fuzzyR   R   t   id(   R   R   R   R   (    (    R   t   addD   s     c      	   C   s  |  i i   } | i   g  } d } } xi | D]a } | i t	 |  t	 |  t	 |  t	 |  i |  f  | | d 7} | |  i | d 7} q0 Wd } d d d t	 |  } | t	 |  } g  }	 g  } xB | D]: \ } }
 } } |	 |
 | | g 7}	 | | | | g 7} qΦ W|	 | } t i d d d t	 |  d d d d t	 |  d	 d d  } | t i d
 |  i   7} | | 7} | | 7} | S(   s   Return the generated output.t    t    i   i   i   t   Iiiiiiil   ή* i    i   t   iN(   R   R   t   keyst   sortt   offsetst   idst   strsR   t   appendt   lenR   t   keystartt
   valuestartt   koffsetst   voffsetst   o1t   l1t   o2t   l2t   structt   packt   arrayt   tostring(   R   R/   R$   R"   R*   R%   R,   R&   R0   R+   R.   R   R   R-   R)   (    (    R   t   generateI   s>     

 8 
		

c         C   s  d }
 d } d } d } |  i   } d } x±| D]©} | d 7} | d d j p | i
 d  o0 | | j o# |  i | |	 |  d } d } n | d  d j o d | j o
 d } n | d d j o q1 n | i
 d  o |
 } | d } d	 } }	 n% | i
 d
  o | } | d } n | i   } | p q1 n y t | t    } Wn4 t j
 o( } t d | | |  i | f   n X| |
 j o | | 7} q1 | | j o |	 | 7}	 q1 t d | |  i f   q1 W| | j o |  i | |	 |  n |  i   S(   R
   i   i   i    t   #t   msgids   #,R   i   R   t   msgstri   s   %s (line %d of po file %s): 
%ss   error in line %d of po file %sN(   t   IDt   STRt   Nonet   sectionR   R   R   t   linest   lnot   lt
   startswithR   R7   R8   t   stript   evalt   globalst	   ExceptionR   R    R   R5   (   R   R7   R=   R?   R>   R:   R<   R   R   R8   R9   (    (    R   t   getr   sP      
.


$c         C   s   t  |  i    S(   N(   t   StringIOR   RE   (   R   (    (    R   t	   getAsFile―   s    c         C   s
   |  i   S(   N(   R   RG   (   R   (    (    R   t   __call__²   s    (
   R   R   R   R   R   R   R5   RE   RG   RH   (    (    (    R   R	   /   s    			)	=	(	   R   R1   R3   t	   cStringIORF   t   __version__RD   R    R	   (   R1   RF   R	   R    R3   RJ   (    (    R   t   ?    s   		