U
    cqeÄ  ã                   @   s¤   d Z ddlmZmZ ddlmZ dddddd	d
ddddddddddœZdd„ e ¡ D ƒZG dd„ de	ƒZ
e	e	dœdd„Ze	ee	e	f dœdd„Ze	e	dœd d!„Zd"S )#zNamespace-related objects.é    )ÚAnyÚDict)ÚSelfz5http://schemas.openxmlformats.org/drawingml/2006/mainz6http://schemas.openxmlformats.org/drawingml/2006/chartzGhttp://schemas.openxmlformats.org/package/2006/metadata/core-propertiesz http://purl.org/dc/elements/1.1/zhttp://purl.org/dc/dcmitype/zhttp://purl.org/dc/terms/z8http://schemas.openxmlformats.org/drawingml/2006/diagramz:http://schemas.openxmlformats.org/officeDocument/2006/mathz8http://schemas.openxmlformats.org/drawingml/2006/picturezChttp://schemas.openxmlformats.org/officeDocument/2006/relationshipsz9http://schemas.openxmlformats.org/schemaLibrary/2006/mainz<http://schemas.openxmlformats.org/wordprocessingml/2006/mainz4http://schemas.microsoft.com/office/word/2010/wordmlzFhttp://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawingz$http://www.w3.org/XML/1998/namespacez)http://www.w3.org/2001/XMLSchema-instance)ÚaÚcÚcpÚdcZdcmitypeZdctermsZdgmÚmZpicÚrÚslÚwZw14ZwpÚxmlÚxsic                 C   s   i | ]\}}||“qS © r   )Ú.0ÚkeyÚvaluer   r   ú0/tmp/pip-unpacked-wheel-gx5hpqp3/docx/oxml/ns.pyÚ
<dictcomp>   s      r   c                       s¬   e Zd ZdZeedœ‡ fdd„Zedœdd„Zeedœd	d
„ƒZ	e
eedœdd„ƒZeedœdd„ƒZeeeef dœdd„ƒZeedœdd„ƒZeedœdd„ƒZ‡  ZS )ÚNamespacePrefixedTagzNValue object that knows the semantics of an XML tag having a namespace prefix.)ÚnstagÚargsc                    s   t t| ƒ | |¡S )N)Úsuperr   Ú__new__)Úclsr   r   ©Ú	__class__r   r   r       s    zNamespacePrefixedTag.__new__)r   c                 C   s"   |  d¡\| _| _t| j | _d S )Nú:)ÚsplitÚ_pfxÚ_local_partÚnsmapÚ_ns_uri)Úselfr   r   r   r   Ú__init__#   s    zNamespacePrefixedTag.__init__)Úreturnc                 C   s   d| j | jf S )Nú{%s}%s)r"   r    ©r#   r   r   r   Ú
clark_name'   s    zNamespacePrefixedTag.clark_name)r(   r%   c                 C   s.   |dd …   d¡\}}dt| |f }| |ƒS )Né   Ú}z%s:%s)r   Úpfxmap)r   r(   ÚnsuriZ
local_namer   r   r   r   Úfrom_clark_name+   s    z$NamespacePrefixedTag.from_clark_namec                 C   s   | j S )z[The local part of this tag.

        E.g. "foobar" is returned for tag "f:foobar".
        )r    r'   r   r   r   Ú
local_part1   s    zNamespacePrefixedTag.local_partc                 C   s   | j | jiS )z¼Single-member dict mapping prefix of this tag to it's namespace name.

        Example: `{"f": "http://foo/bar"}`. This is handy for passing to xpath calls
        and other uses.
        )r   r"   r'   r   r   r   r!   9   s    zNamespacePrefixedTag.nsmapc                 C   s   | j S )zeThe namespace-prefix for this tag.

        For example, "f" is returned for tag "f:foobar".
        )r   r'   r   r   r   ÚnspfxB   s    zNamespacePrefixedTag.nspfxc                 C   s   | j S )z±The namespace URI for this tag.

        For example, "http://foo/bar" would be returned for tag "f:foobar" if the "f"
        prefix maps to "http://foo/bar" in nsmap.
        )r"   r'   r   r   r   r,   J   s    zNamespacePrefixedTag.nsuri)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   r   r$   Úpropertyr(   Úclassmethodr   r-   r.   r   r!   r/   r,   Ú__classcell__r   r   r   r   r      s   r   )Úprefixesr%   c                  G   s   d  dd„ | D ƒ¡S )z—Namespace declaration including each namespace-prefix in `prefixes`.

    Handy for adding required namespace declarations to a tree root element.
    ú c                 S   s   g | ]}d |t | f ‘qS )zxmlns:%s="%s"©r!   ©r   Úpfxr   r   r   Ú
<listcomp>Y   s     znsdecls.<locals>.<listcomp>)Újoin)r8   r   r   r   ÚnsdeclsT   s    r?   )Únspfxsr%   c                  G   s   dd„ | D ƒS )z“Subset namespace-prefix mappings specified by *nspfxs*.

    Any number of namespace prefixes can be supplied, e.g. namespaces("a", "r", "p").
    c                 S   s   i | ]}|t | “qS r   r:   r;   r   r   r   r   a   s      znspfxmap.<locals>.<dictcomp>r   )r@   r   r   r   Únspfxmap\   s    rA   )Útagr%   c                 C   s"   |   d¡\}}t| }d||f S )a  Stands for "qualified name".

    This utility function converts a familiar namespace-prefixed tag name like "w:p"
    into a Clark-notation qualified tag name for lxml. For example, `qn("w:p")` returns
    "{http://schemas.openxmlformats.org/wordprocessingml/2006/main}p".
    r   r&   )r   r!   )rB   ÚprefixZtagrootÚurir   r   r   Úqnd   s    rE   N)r3   Útypingr   r   Ztyping_extensionsr   r!   Úitemsr+   r4   r   r?   rA   rE   r   r   r   r   Ú<module>   s0   ð7