ó
•‰]c           @@  sç   d  d l  m Z d  d l Z d  d l m Z m Z m Z m Z m Z d  d l	 m
 Z
 d  d l m Z m Z d  d l m Z m Z m Z d e
 f d „  ƒ  YZ d	 e
 f d
 „  ƒ  YZ d „  Z d  d l m Z d „  Z d d d „ Z d S(   i    (   t   absolute_importN(   t   Stringt   Sett   NoneSett   Aliast   Sequence(   t   Serialisable(   t   REL_NSt
   PKG_REL_NS(   t   Elementt
   fromstringt   tostringt   Relationshipc           B@  st   e  Z d  Z d Z e ƒ  Z e ƒ  Z e d ƒ Z e d e	 ƒ Z
 e d e	 ƒ Z e d ƒ Z d d d d d d „ Z RS(   s'   Represents many kinds of relationships.R   t   Targett
   allow_nonet   Idc         C@  sI   | d k	 r! d j t | ƒ } n  | |  _ | |  _ | |  _ | |  _ d S(   s—   
        `type` can be used as a shorthand with the default relationships namespace
        otherwise the `Type` must be a fully qualified URL
        s   {0}/{1}N(   t   Nonet   formatR   t   TypeR   t
   TargetModeR   (   t   selfR   R   t   typeR   R   (    (    s>   lib/python2.7/site-packages/openpyxl/packaging/relationship.pyt   __init__$   s    			N(   t   __name__t
   __module__t   __doc__t   tagnameR   R   R   R   t   targett   TrueR   R   t   idR   R   (    (    (    s>   lib/python2.7/site-packages/openpyxl/packaging/relationship.pyR      s   		t   RelationshipListc           B@  s_   e  Z d  Z e d e ƒ Z d	 d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(
   t   Relationshipst   expected_typec         C@  s   | |  _  d  S(   N(   R   (   R   R   (    (    s>   lib/python2.7/site-packages/openpyxl/packaging/relationship.pyR   >   s    c         C@  sH   |  j  } | j | ƒ | j s; d j t | ƒ ƒ | _ n  | |  _  d  S(   Ns   rId{0}(   R   t   appendR   R   t   len(   R   t   valuet   values(    (    s>   lib/python2.7/site-packages/openpyxl/packaging/relationship.pyR!   B   s
    
	c         C@  s   t  |  j ƒ S(   N(   R"   R   (   R   (    (    s>   lib/python2.7/site-packages/openpyxl/packaging/relationship.pyt   __len__J   s    c         C@  s   t  |  j ƒ S(   N(   t   boolR   (   R   (    (    s>   lib/python2.7/site-packages/openpyxl/packaging/relationship.pyt   __bool__N   s    c         c@  s/   x( |  j  D] } | j | k r
 | Vq
 q
 Wd S(   s«   
        Find relationships by content-type
        NB. these content-types namespaced objects and different to the MIME-types
        in the package manifest :-(
        N(   R   R   (   R   t   content_typet   r(    (    s>   lib/python2.7/site-packages/openpyxl/packaging/relationship.pyt   findR   s    c         C@  s@   x$ |  j  D] } | j | k r
 | Sq
 Wt d j | ƒ ƒ ‚ d  S(   Ns   Unknown relationship: {0}(   R   R   t   KeyErrorR   (   R   t   keyR)   (    (    s>   lib/python2.7/site-packages/openpyxl/packaging/relationship.pyt   __getitem__]   s    c         C@  sj   t  d d t ƒ} xQ t |  j d ƒ D]= \ } } | j sO d j | ƒ | _ n  | j | j ƒ  ƒ q% W| S(   NR   t   xmlnsi   s   rId{0}(   R	   R   t	   enumerateR   R   R   R!   t   to_tree(   R   t   treet   idxt   rel(    (    s>   lib/python2.7/site-packages/openpyxl/packaging/relationship.pyR0   d   s    	(    (   R   R   R   R   R   R   R!   R%   R'   R*   R-   R0   (    (    (    s>   lib/python2.7/site-packages/openpyxl/packaging/relationship.pyR   7   s   					c         C@  s7   t  j |  ƒ \ } } t  j | d d j | ƒ ƒ } | S(   s±   
    Convert relative path to absolutes that can be loaded from a zip
    archive.
    The path to be passed in is that of containing object (workbook,
    worksheet, etc.)
    t   _relss   {0}.rels(   t	   posixpatht   splitt   joinR   (   t   patht   foldert   objt   filename(    (    s>   lib/python2.7/site-packages/openpyxl/packaging/relationship.pyt   get_rels_pathn   s    (   t   warnc   
      C@  sÿ   |  j  | ƒ } t | ƒ } y t j | ƒ } Wn3 t k
 rc d j | ƒ } t | ƒ t ƒ  } n Xt j | ƒ } t j	 | ƒ d } xr | j
 D]g } | j d k r« q q | j j d ƒ rÐ | j d | _ q t j | | j ƒ }	 t j |	 ƒ | _ q W| S(   sl   
    Normalise dependency file paths to absolute ones

    Relative paths are relative to parent object
    s+   {0} contains invalid dependency definitionsi    t   Externalt   /i   (   t   readR
   R   t	   from_treet	   TypeErrorR   R=   R5   t   dirnameR6   R   R   R   t
   startswithR7   t   normpath(
   t   archiveR;   t   srct   nodet   relst   msgR9   t   parentR)   t   pth(    (    s>   lib/python2.7/site-packages/openpyxl/packaging/relationship.pyt   get_dependents|   s$    
c   
      C@  sá   t  | | g ƒ s! t d ƒ ‚ n  | d k	 r: | | } n1 y t | j | j ƒ ƒ } Wn t k
 rj d SX| j } |  j | ƒ } t	 | ƒ } | j
 | ƒ } t | ƒ }	 y t |  |	 ƒ | _ Wn t k
 rÜ g  | _ n X| S(   s4   
    Get related object based on id or rel_type
    s.   Either the id or the content type are requiredN(   t   anyt
   ValueErrorR   t   nextR*   t   rel_typet   StopIterationR   R@   R
   RA   R<   RM   t   depsR+   (
   RF   RS   R   t   clsR3   R8   RG   R1   R:   t	   rels_path(    (    s>   lib/python2.7/site-packages/openpyxl/packaging/relationship.pyt   get_rel—   s$    	(   t
   __future__R    R5   t   openpyxl.descriptorsR   R   R   R   R   t!   openpyxl.descriptors.serialisableR   t   openpyxl.xml.constantsR   R   t   openpyxl.xml.functionsR	   R
   R   R   R   R<   t   warningsR=   RM   R   RV   (    (    (    s>   lib/python2.7/site-packages/openpyxl/packaging/relationship.pyt   <module>   s   ( 7		