ó
Ò¬Qc           @   s  d  Z  d d l m Z e d d d ƒd d l Z d d l Z d d l Td d l m Z d d l Td d l Z d d l	 Z d d l
 Z
 d d	 l
 m Z m Z i	 e e 6e e 6e e 6e e 6e e 6e e 6e e 6e e 6e e 6Z e j Z y e j j Z Wn$ e k
 r d
 d" d „  ƒ  YZ n Xe j j Z e j j  Z  d „  Z! d d „ Z# d d „ Z$ d „  Z% d „  Z& d „  Z' d „  Z( d „  Z) d „  Z* d „  Z+ d „  Z, d „  Z- d „  Z. d „  Z/ d „  Z0 d „  Z1 d „  Z2 d „  Z3 d „  Z4 d  „  Z5 d d! „ Z6 d S(#   sü   Tools for use in AppleEvent clients and servers:
conversion between AE types and python types

pack(x) converts a Python object to an AEDesc object
unpack(desc) does the reverse
coerce(x, wanted_sample) coerces a python object to another python object
iÿÿÿÿ(   t   warnpy3ks%   In 3.x, the aepack module is removed.t
   stackleveli   N(   t   *(   t   AE(   t   mkenumt   ObjectSpecifiert   FSSTypec           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyR   @   s   c         C   sV   t  | d ƒ r | j } n! t  | d ƒ r6 | j } n | } |  j | t | ƒ ƒ d  S(   Nt   whicht   want(   t   hasattrR	   R
   t   AEPutParamDesct   pack(   t   aet   keyt   valuet   keystr(    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyt   packkeyE   s    c         C   sÛ  | r> t  |  ƒ t k r( t j | |  ƒ St |  ƒ j | ƒ Sn  |  d k rZ t j d d ƒ St |  t ƒ rm |  St |  t	 ƒ r t j d |  j
 ƒ St |  t ƒ r± t j d |  j
 ƒ St |  t ƒ rÓ t j d |  j
 ƒ St |  t ƒ rþ t j d t j d |  ƒ ƒ St |  t ƒ r)t j d t j d	 |  ƒ ƒ St |  t ƒ rHt j d
 |  ƒ St |  t ƒ r“|  j d ƒ } | d  d k rƒ| d } n  t j d | ƒ St |  t ƒ rßt j d d ƒ } x$ |  D] } | j d t | ƒ ƒ q»W| St |  t ƒ r1t j d d ƒ } x* |  j ƒ  D] \ } } t | | | ƒ qW| St  |  ƒ t j k rht |  t ƒ rht j d |  j ƒ St |  d ƒ r|  j ƒ  St |  d ƒ r£t j d
 |  j ƒ St |  d ƒ rÅt j d
 |  j ƒ St j d
 t  |  ƒ ƒ S(   s*   Pack a python object into an AE descriptort   nullt    s   fss t   fsrft   alist   longt   lt   doubt   dt   TEXTt   utf16i   s   þÿt   utxti    i   t   typet
   __aepack__R	   R
   N(!   R   t
   StringTypeR   t   AECreateDescR   t   AECoerceDesct   Nonet
   isinstancet
   AEDescTypeR   t   datat	   FSRefTypet	   AliasTypet   IntTypet   structt	   FloatTypet   UnicodeTypet   encodet   ListTypet   AECreateListt	   AEPutDesct   DictionaryTypet   itemsR   t   typest	   ClassTypet
   issubclassR   R
   R   R   R	   t   repr(   t   xt	   forcetypeR&   t   listt   itemt   recordR   R   (    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyR   N   sX    $
R   c         C   sÉ  |  j  } | t k r4 |  j t | ƒ }  |  j  } n  | t k r™ g  } xL t |  j ƒ  ƒ D]8 } |  j | d d ƒ \ } } | j t | | ƒ ƒ qY W| S| t	 k rû i  } xI t |  j ƒ  ƒ D]5 } |  j | d d ƒ \ } } t | | ƒ | | <q¾ W| S| t
 k r)|  j d ƒ } t t | | ƒ ƒ S| t k rKt j j d |  j ƒ S| t k rnt j d |  j ƒ d S| t k r|  j S| t k rt |  j d ƒ S| t k r¶t |  j ƒ S| t k rÆd S| t k rï|  j }	 t j d |	 ƒ d S| t k rt j j d |  j ƒ S| t k r3t j j d |  j ƒ S| t k ra|  j d ƒ } t t | | ƒ ƒ S| t  k r¦t j d	 |  j d
  ƒ \ }
 } t! j" |
 | |  j d
 ƒ S| t# k rÝt j d	 |  j ƒ \ }
 } t! j$ |
 | ƒ S| t% k röt& |  j ƒ S| t' k rt j d |  j ƒ d S| t( k rRt j d |  j ƒ \ } } t) | ƒ d >| S| t* k rbd S| t, k r t j d |  j ƒ } | d k  rœd | } n  | S| t- k rê|  j d ƒ } | r×t. t | | ƒ | ƒ St/ t | | ƒ ƒ S| t0 k r!t j d	 |  j ƒ \ } } t! j1 | | ƒ S| t2 k rdt j d |  j ƒ \ } } } } t! j3 | | | | ƒ S| t4 k r¡t j d |  j ƒ \ } } } t! j5 | | | ƒ S| t6 k rÄt j d |  j ƒ d S| t7 k rçt j d |  j ƒ d S| t8 k r t9 |  j ƒ S| t: k rd S| t; k r,t< |  j | ƒ S| d k rZ|  j d ƒ } t= t | | ƒ ƒ S| d k rˆ|  j d ƒ } t> t | | ƒ ƒ S| d k r¶|  j d ƒ } t? t | | ƒ ƒ St@ |  j  |  j ƒ S(   s*   Unpack an AE descriptor to a python objecti   s   ****t   recot   rawdatat   bi    R   R   t   hhi   R   t   lLi    l        t   hhhht   hhht   ft   ht   rangt   cmpdt   logiN(A   R   t   unpacker_coercionsR"   t
   typeAEListt   ranget   AECountItemst   AEGetNthDesct   appendt   unpackt   typeAERecordt
   typeAETextt   mkaetextt	   typeAliast   Carbont   Filet   AliasR&   t   typeBooleanR*   t   typeChart   typeUnicodeTextt   unicodet   typeEnumerationR   t	   typeFalset	   typeFloatt   typeFSSt   FSSpect	   typeFSReft   FSReft   typeInsertionLoct   mkinsertionloct   typeIntlTextt   aetypest   IntlTextt   typeIntlWritingCodet   IntlWritingCodet   typeKeywordt	   mkkeywordt   typeLongIntegert   typeLongDateTimeR   t   typeNullR#   t   typeMagnitudet   typeObjectSpecifiert   mkobjectfrommodulet   mkobjectt   typeQDPointt   QDPointt   typeQDRectanglet   QDRectanglet   typeRGBColort   RGBColort   typeShortFloatt   typeShortIntegert   typeTargetIDt
   mktargetidt   typeTruet   typeTypet   mktypet   mkranget   mkcomparisont	   mklogicalt	   mkunknown(   t   desct   formodulenamet   tR   t   it   keywordR:   R   R;   R&   t   scriptt   languaget   aR>   t   vRD   t   v0t   h0t   v1t   h1t   rt   g(    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyRN   ƒ   s¾    		!c         C   s4   t  |  ƒ } t  | ƒ } | j | j ƒ } t | ƒ S(   s<   Coerce a python object to another type using the AE coercers(   R   R"   R   RN   (   R&   t   egdatat   pdatat   pegdata(    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyt   coerceÿ   s    c         C   sY   t  |  d  ƒ } t |  d d !ƒ } t |  d d !ƒ } t |  d d !ƒ } | | | | f S(	   Ni   iH   iL   i$   ip   iL   ip   i¸   (   t   getlongt   mkppcportrect   mklocationnamerec(   R&   t	   sessionIDt   namet   locationt   rcvrName(    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyRz   	  s
    c         C   sŽ   t  |  d  ƒ } t |  d d !ƒ } t  |  d d !ƒ } | d k rk |  d d !} |  d d !} | | f } n t |  d d	 !ƒ } | | | | f S(
   Ni   i!   i$   i&   i   i*   i.   i#   iG   (   t   getwordt   getpstr(   t   rect
   namescriptR™   t   portkindt   ctorR   t   identity(    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyR–     s    c         C   sT   t  |  d  ƒ } |  d } | d k r/ d  } n  | d k rJ t | ƒ } n  | | f S(   Ni   i    (   Rœ   R#   R   (   Rž   t   kindt   stuff(    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyR—     s    
 	 c         C   s   t  j |  | ƒ S(   N(   Rd   t   Unknown(   R   R&   (    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyR   #  s    c         C   s   |  d d t  |  d ƒ !S(   Ni   i    (   t   ord(   t   s(    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyR   &  s    c         C   sD   t  |  d ƒ d >t  |  d ƒ d >Bt  |  d ƒ d >Bt  |  d ƒ BS(   Ni    i   i   i   i   i   i   (   R¦   (   R§   (    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyR•   )  s    c         C   s$   t  |  d ƒ d >t  |  d ƒ d >BS(   Ni    i   i   (   R¦   (   R§   (    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyRœ   ,  s    c         C   s   t  j |  ƒ S(   N(   Rd   t   Keyword(   R†   (    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyRi   /  s    c         C   s   t  j |  d |  d ƒ S(   Nt   start   stop(   Rd   t   Range(   t   dict(    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyR~   2  s    c         C   s"   t  j |  d |  d j |  d ƒ S(   Nt   obj1t   relot   obj2(   Rd   t
   Comparisont   enum(   R¬   (    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyR   5  s    c         C   s   t  j |  d |  d ƒ S(   Nt   logct   term(   Rd   t   Logical(   R¬   (    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyR€   8  s    c         C   s   t  j |  d |  d ƒ S(   Nt   kstyt   ktxt(   Rd   t
   StyledText(   R¬   (    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyt   mkstyledtext;  s    c         C   s   t  j |  t |  t |  t ƒ S(   N(   Rd   t   AETextt   keyAEScriptTagt   keyAEStylest	   keyAEText(   R¬   (    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyRQ   >  s    c         C   s   t  j |  t |  t ƒ S(   N(   Rd   t   InsertionLoct   keyAEObjectt   keyAEPosition(   R¬   (    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyRb   A  s    c         C   s‰  |  d j  } |  d j } |  d } |  d } | d k r9| d	 k rV t j | | ƒ S| d
 k rr t j | | ƒ S| d k rŽ t j | | ƒ S| d k rª t j | | ƒ S| d k rÆ t j | | ƒ S| d k râ t j | | ƒ S| d k rþ t j	 | | ƒ S| d k rt j
 | | ƒ S| d k r9t j | | ƒ Sn  | d k rs| d k rst j | ƒ rst j | j  | ƒ St j | | | | ƒ S(   NR
   t   formt   seldt   fromR™   t   indxRE   t   testt   texts   cha t   cwort   clint   cpart   cwint   docut   filet   cinst   prop(   s   nameRÃ   s   rangRÄ   (   R   R±   Rd   t   Textt	   Charactert   Wordt   Linet	   Paragrapht   Windowt   DocumentRT   t   InsertionPointt   IsTypet   PropertyR   (   R¬   R
   RÀ   RÁ   t   fr(    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyRp   D  s4    

         'c         C   s¥   t  |  d ƒ t j k rO t |  d t ƒ rO |  d } t j | j ƒ |  d <n  |  d j  } t | ƒ } | j	 } | j
 | d  ƒ } t |  ƒ } | r¡ | | _ n  | S(   NR
   (   R   R3   R4   R5   R   Rd   R}   R
   t
   __import__t   _classdeclarationst   getR#   Rp   t	   __class__(   R¬   t
   modulenamet	   classtypeR
   t   modulet   codenamemappert   newobj(    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyRo   [  s    ,
	c         C   sG   | r: t  | ƒ } | j } | j |  d  ƒ } | r: | Sn  t j |  ƒ S(   N(   RÙ   RÚ   RÛ   R#   Rd   R}   (   t   typecodeRÝ   Rß   Rà   RÞ   (    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyR}   j  s    	(    (7   t   __doc__t   warningsR    R*   R3   RS   R   t   Carbon.AppleEventst   MacOSt   Carbon.FileRd   R   R   R\   t   typeCompRI   t   typeColorTableRO   t   typeDrawingAreat	   typeFixedt   typeExtendedt   typePixelMapt   typeRotationt   typeStyledTextt   typeTextStylesRH   R%   RT   t
   FSSpecTypeR   t   AttributeErrorR'   R(   R   R#   R   RN   R”   Rz   R–   R—   R   R   R•   Rœ   Ri   R~   R   R€   R¸   RQ   Rb   Rp   Ro   R}   (    (    (    s<   /Users/tom/newbuild/install/lib/python2.7/plat-mac/aepack.pyt   <module>   sb   


			5|	
																