
^Q\                 @   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 Gd d   d e
  Z Gd	 d
   d
 e
  Z d d   Z d d   Z d d d d  Z d S)    )absolute_importN)StringSetNoneSetAliasSequence)Serialisable)REL_NS
PKG_REL_NS)Element
fromstringtostringc               @   s   e  Z d  Z d Z d  Z e   Z e   Z e d  Z	 e d d  Z
 e d d  Z e d  Z d d d d d d d  Z d S)	Relationshipz'Represents many kinds of relationships.TargetZ
allow_noneTIdNc             C   sI   | d k	 r! d j  t |  } n  | |  _ | |  _ | |  _ | |  _ d S)z
        `type` can be used as a shorthand with the default relationships namespace
        otherwise the `Type` must be a fully qualified URL
        Nz{0}/{1})formatr	   Typer   
TargetModer   )selfr   r   typer   r    r   T/var/www/dbchiro/venv/lib/python3.4/site-packages/openpyxl/packaging/relationship.py__init__$   s    			zRelationship.__init__)__name__
__module____qualname____doc__tagnamer   r   r   r   targetr   r   idr   r   r   r   r   r      s   		r   c               @   s|   e  Z d  Z d Z e d e  Z f  d d  Z d d   Z d d   Z d	 d
   Z	 d d   Z
 d d   Z d d   Z d S)RelationshipListRelationshipsZexpected_typec             C   s   | |  _  d  S)N)r   )r   r   r   r   r   r   >   s    zRelationshipList.__init__c             C   sQ   |  j  d  d   } | j |  | j sD d j t |   | _ n  | |  _  d  S)NzrId{0})r   appendr   r   len)r   valuevaluesr   r   r   r"   B   s
    	zRelationshipList.appendc             C   s   t  |  j  S)N)r#   r   )r   r   r   r   __len__J   s    zRelationshipList.__len__c             C   s   t  |  j  S)N)boolr   )r   r   r   r   __bool__N   s    zRelationshipList.__bool__c             c   s/   x( |  j  D] } | j | k r
 | Vq
 q
 Wd S)z
        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   content_typerr   r   r   findR   s    zRelationshipList.findc             C   s@   x$ |  j  D] } | j | k r
 | Sq
 Wt d j |    d  S)NzUnknown relationship: {0})r   r   KeyErrorr   )r   keyr*   r   r   r   __getitem__]   s    zRelationshipList.__getitem__c             C   sj   t  d d t } xQ t |  j d  D]= \ } } | j sO d j |  | _ n  | j | j    q% W| S)Nr!   Zxmlns   zrId{0})r   r
   	enumerater   r   r   r"   to_tree)r   treeidxrelr   r   r   r1   d   s    	zRelationshipList.to_treeN)r   r   r   r   r   r   r   r"   r&   r(   r+   r.   r1   r   r   r   r   r    7   s   r    c             C   s7   t  j |   \ } } t  j | d d j |   } | S)z
    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.)
    Z_relsz{0}.rels)	posixpathsplitjoinr   )pathfolderobjfilenamer   r   r   get_rels_pathn   s    r<   c       	      C   s   |  j  |  } t |  } t j |  } t j |  } t j |  d } xx | j D]m } | j d k rq qV qV | j	 j
 d  r | j	 d d  | _	 qV t j | | j	  } t j |  | _	 qV W| S)zl
    Normalise dependency file paths to absolute ones

    Relative paths are relative to parent object
    r   ZExternal/r/   N)readr   r    	from_treer5   dirnamer6   r   r   r   
startswithr7   normpath)	archiver;   srcnodeZrelsr9   parentr*   pthr   r   r   get_dependentsz   s    rH   c       
      C   s   t  | | g  s! t d   n  | d k	 r: | | } n t | j | j   } | j } |  j |  } t |  } | j |  } t	 |  }	 y t
 |  |	  | _ Wn t k
 r g  | _ Yn X| S)z4
    Get related object based on id or rel_type
    z.Either the id or the content type are requiredN)any
ValueErrornextr+   Zrel_typer   r>   r   r?   r<   rH   depsr,   )
rC   rL   r   clsr4   r8   rD   r2   r:   Z	rels_pathr   r   r   get_rel   s    	rN   )
__future__r   r5   Zopenpyxl.descriptorsr   r   r   r   r   Z!openpyxl.descriptors.serialisabler   Zopenpyxl.xml.constantsr	   r
   Zopenpyxl.xml.functionsr   r   r   r   r    r<   rH   rN   r   r   r   r   <module>   s   ( 7