ó
ê}Lc           @   sÍ   d  Z  d d l m Z d d l Td d l Td d l m Z d d l m Z d d l	 Z	 e	 j
 d d d	 f k  r„ d d
 l m Z [	 n  e e ƒ Z d f  d „  ƒ  YZ d f  d „  ƒ  YZ d f  d „  ƒ  YZ d S(   s"   
Provides XML I{element} classes.
iÿÿÿÿ(   t	   getLogger(   t   *(   t   Text(   t	   AttributeNi   i   i    (   t   Sett   Elementc           B   s£  e  Z d  Z i d „  d 6d „  d 6d „  d 6d „  d 6Z i e j d	 e j d
 6Z e d „  ƒ Z dD dD d „ Z
 d „  Z dD d „ Z d „  Z d „  Z dD d „ Z d „  Z d „  Z d „  Z dD dD d „ Z d „  Z dD d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d
 d „ Z d „  Z d „  Z dD dD d  „ Z dD dD d! „ Z d" „  Z  d# „  Z! dD dD d$ „ Z" d% „  Z# e j$ d& „ Z% d' „  Z& d( „  Z' d) „  Z( dD d* „ Z) d d+ „ Z* d, „  Z+ d- „  Z, d. „  Z- e. d/ „ Z/ d0 „  Z0 e. d1 „ Z1 d2 „  Z2 d
 d3 „ Z3 d4 „  Z4 d5 „  Z5 dD dD d6 „ Z6 d7 „  Z7 d8 „  Z8 d9 „  Z9 d: „  Z: d; „  Z; d< „  Z< d= „  Z= d> „  Z> d? „  Z? d@ „  Z@ dA „  ZA dB „  ZB dC „  ZC RS(E   s@  
    An XML element object.
    @ivar parent: The node containing this attribute
    @type parent: L{Element}
    @ivar prefix: The I{optional} namespace prefix.
    @type prefix: basestring
    @ivar name: The I{unqualified} name of the attribute
    @type name: basestring
    @ivar expns: An explicit namespace (xmlns="...").
    @type expns: (I{prefix}, I{name})
    @ivar nsprefixes: A mapping of prefixes to namespaces.
    @type nsprefixes: dict
    @ivar attributes: A list of XML attributes.
    @type attributes: [I{Attribute},]
    @ivar text: The element's I{text} content.
    @type text: basestring
    @ivar children: A list of child elements.
    @type children: [I{Element},]
    @cvar matcher: A collection of I{lambda} for string matching.
    @cvar specialprefixes: A dictionary of builtin-special prefixes.
    c         C   s
   |  | k S(   N(    (   t   at   b(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   <lambda>:   s    t   eqc         C   s   |  j  | ƒ S(   N(   t
   startswith(   R   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR   ;   s    R
   c         C   s   |  j  | ƒ S(   N(   t   endswith(   R   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR   <   s    R   c         C   s
   | |  k S(   N(    (   R   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR   =   s    t   containsi   i    c         C   sQ   xJ | j  d ƒ D]9 } | j | ƒ } | d k rC t | | ƒ } n  | } q W| S(   sr  
        Build the specifed pat as a/b/c where missing intermediate nodes are built
        automatically.
        @param parent: A parent element on which the path is built.
        @type parent: I{Element}
        @param path: A simple path separated by (/).
        @type path: basestring
        @return: The leaf node of I{path}.
        @rtype: L{Element}
        t   /N(   t   splitt   getChildt   NoneR   (   t   selft   parentt   patht   tagt   child(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt	   buildPathB   s    
c         C   s“   |  j  | ƒ d |  _ i  |  _ g  |  _ d |  _ | d k	 rp t | t ƒ rX | |  _ qy t	 d | j
 j ƒ ‚ n	 d |  _ g  |  _ |  j | ƒ d S(   s  
        @param name: The element's (tag) name.  May cotain a prefix.
        @type name: basestring
        @param parent: An optional parent element.
        @type parent: I{Element}
        @param ns: An optional namespace
        @type ns: (I{prefix}, I{name})
        s   parent (%s) not-validN(   t   renameR   t   expnst
   nsprefixest
   attributest   textt
   isinstanceR   R   t	   Exceptiont	   __class__t   __name__t   childrent   applyns(   R   t   nameR   t   ns(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   __init__U   s    
						c         C   s;   | d k r t d | ƒ ‚ n t | ƒ \ |  _ |  _ d S(   sv   
        Rename the element.
        @param name: A new name for the element.
        @type name: basestring 
        s   name (%s) not-validN(   R   R   t   splitPrefixt   prefixR"   (   R   R"   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR   n   s    c         C   s8   | |  _  | d k	 r4 | d k	 r4 |  j | | ƒ n  |  S(   s  
        Set the element namespace prefix.
        @param p: A new prefix for the element.
        @type p: basestring 
        @param u: A namespace URI to be mapped to the prefix.
        @type u: basestring
        @return: self
        @rtype: L{Element}
        N(   R&   R   t	   addPrefix(   R   t   pt   u(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt	   setPrefixy   s    
	c         C   s.   |  j  d k r |  j Sd |  j  |  j f Sd S(   s‡   
        Get the B{fully} qualified name of this element
        @return: The fully qualified name.
        @rtype: basestring
        s   %s:%sN(   R&   R   R"   (   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   qnameˆ   s    c         C   s$   |  j  d k r |  S|  j  j ƒ  Sd S(   s€   
        Get the root (top) node of the tree.
        @return: The I{top} node of this tree.
        @rtype: I{Element}
        N(   R   R   t   getRoot(   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR,   “   s    c         C   s¨   t  |  j ƒ  | |  j ƒ  ƒ } x' |  j D] } | j | j |  ƒ ƒ q( Wx' |  j D] } | j | j |  ƒ ƒ qR Wx/ |  j j ƒ  D] } | j	 | d | d ƒ q‚ W| S(   sì   
        Deep clone of this element and children.
        @param parent: An optional parent for the copied fragment.
        @type parent: I{Element}
        @return: A deep copy parented by I{parent}
        @rtype: I{Element}
        i    i   (
   R   R+   t	   namespaceR   t   appendt   cloneR    R   t   itemsR'   (   R   R   t   rootR   t   ct   item(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR/   ž   s    c         C   sG   |  j  d k	 rC |  |  j  j k r7 |  j  j j |  ƒ n  d |  _  n  |  S(   s¥   
        Detach from parent.
        @return: This element removed from its parent's
            child list and I{parent}=I{None}
        @rtype: L{Element}
        N(   R   R   R    t   remove(   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   detach¯   s
    c         C   sK   |  j  | ƒ } | d k r: t | | ƒ } |  j | ƒ n | j | ƒ d S(   sá   
        Set an attribute's value.
        @param name: The name of the attribute.
        @type name: basestring
        @param value: The attribute value.
        @type value: basestring
        @see: __setitem__()
        N(   t   getAttributeR   R   R.   t   setValue(   R   R"   t   valuet   attr(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   set¼   s
    	c         C   s1   y# |  j  | ƒ } |  j j | ƒ Wn n X|  S(   s    
        Unset (remove) an attribute.
        @param name: The attribute name.
        @type name: str
        @return: self
        @rtype: L{Element}
        (   R6   R   R4   (   R   R"   R9   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   unsetÌ   s    c         C   s?   |  j  | | ƒ } | d k s- | j d k r1 | S| j ƒ  Sd S(   só  
        Get the value of an attribute by name.
        @param name: The name of the attribute.
        @type name: basestring
        @param ns: The optional attribute's namespace.
        @type ns: (I{prefix}, I{name})
        @param default: An optional value to be returned when either
            the attribute does not exist of has not value.
        @type default: basestring
        @return: The attribute's value or I{default}
        @rtype: basestring
        @see: __getitem__()
        N(   R6   R   R8   t   getValue(   R   R"   R#   t   defaultR9   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   getÜ   s    c         C   s.   t  | t ƒ r | |  _ n t | ƒ |  _ |  S(   sµ   
        Set the element's L{Text} content.
        @param value: The element's text value.
        @type value: basestring
        @return: self
        @rtype: I{Element}
        (   R   R   R   (   R   R8   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   setTextð   s    c         C   s   |  j  ƒ  r |  j S| Sd S(   s   
        Get the element's L{Text} content with optional default
        @param default: A value to be returned when no text content exists.
        @type default: basestring
        @return: The text content, or I{default}
        @rtype: L{Text}
        N(   t   hasTextR   (   R   R=   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   getTextþ   s    c         C   s%   |  j  ƒ  r! |  j j ƒ  |  _ n  |  S(   sh   
        Trim leading and trailing whitespace.
        @return: self
        @rtype: L{Element}
        (   R@   R   t   trim(   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyRB     s    c         C   s   |  j  d k	 o t |  j  ƒ S(   s¯   
        Get whether the element has I{text} and that it is not an empty
        (zero length) string.
        @return: True when has I{text}.
        @rtype: boolean
        N(   R   R   t   len(   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR@     s    c         C   s-   |  j  d k r |  j ƒ  S|  j |  j  ƒ Sd S(   sÕ   
        Get the element's namespace.
        @return: The element's namespace by resolving the prefix, the explicit 
            namespace or the inherited namespace.
        @rtype: (I{prefix}, I{name})
        N(   R&   R   t   defaultNamespacet   resolvePrefix(   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR-     s    
c         C   sE   |  } x5 | d k	 r= | j d k	 r1 d | j f S| j } q	 Wt j S(   sù   
        Get the default (unqualified namespace).  
        This is the expns of the first node (looking up the tree)
        that has it set.
        @return: The namespace of a node when not qualified.
        @rtype: (I{prefix}, I{name})
        N(   R   R   R   t	   NamespaceR=   (   R   R(   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyRD   *  s    c         C   s¨   t  | t t f ƒ s! | f } n  x€ | D]x } t  | t ƒ r\ |  j j | ƒ |  | _ q( n  t  | t ƒ rŠ |  j j | ƒ |  | _ q( n  t	 d | j
 j ƒ ‚ q( W|  S(   s:  
        Append the specified child based on whether it is an
        element or an attrbuite.
        @param objects: A (single|collection) of attribute(s) or element(s)
            to be added as children.
        @type objects: (L{Element}|L{Attribute})
        @return: self
        @rtype: L{Element}
        s   append %s not-valid(   R   t   listt   tupleR   R    R.   R   R   R   R   R   R   (   R   t   objectsR   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR.   :  s    
		c         C   sb   | f } xR | D]J } t  | t ƒ rD |  j j | | ƒ |  | _ q t d | j j ƒ ‚ q W|  S(   sx  
        Insert an L{Element} content at the specified index.
        @param objects: A (single|collection) of attribute(s) or element(s)
            to be added as children.
        @type objects: (L{Element}|L{Attribute})
        @param index: The position in the list of children to insert.
        @type index: int
        @return: self
        @rtype: L{Element}
        s   append %s not-valid(   R   R   R    t   insertR   R   R   R   (   R   RI   t   indexR   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyRJ   R  s    	c         C   s?   t  | t ƒ r | j ƒ  St  | t ƒ r; |  j j | ƒ n  d S(   s  
        Remove the specified child element or attribute.
        @param child: A child to remove.
        @type child: L{Element}|L{Attribute}
        @return: The detached I{child} when I{child} is an element, else None.
        @rtype: L{Element}|None
        N(   R   R   R5   R   R   R4   R   (   R   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR4   f  s
    
c         C   sŸ   | |  j  k r t d ƒ ‚ n  |  j  j | ƒ } |  j | ƒ t | t t f ƒ s^ | f } n  x: | D]2 } |  j  j | | j ƒ  ƒ |  | _	 | d 7} qe Wd S(   sù   
        Replace I{child} with the specified I{content}.
        @param child: A child element.
        @type child: L{Element}
        @param content: An element or collection of elements.
        @type content: L{Element} or [L{Element},]
        s   child not-foundi   N(
   R    R   RK   R4   R   RG   RH   RJ   R5   R   (   R   R   t   contentRK   t   node(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   replaceChildt  s    	c         C   ss   | d k rE t | ƒ \ } } | d k r3 d } qE |  j | ƒ } n  x' |  j D] } | j | | ƒ rO | SqO W| S(   s¬  
        Get an attribute by name and (optional) namespace
        @param name: The name of a contained attribute (may contain prefix).
        @type name: basestring
        @param ns: An optional namespace
        @type ns: (I{prefix}, I{name})
        @param default: Returned when attribute not-found.
        @type default: L{Attribute}
        @return: The requested attribute object.
        @rtype: L{Attribute}
        N(   R   R%   RE   R   t   match(   R   R"   R#   R=   R&   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR6   ‡  s    	c         C   ss   | d k rE t | ƒ \ } } | d k r3 d } qE |  j | ƒ } n  x' |  j D] } | j | | ƒ rO | SqO W| S(   sÔ  
        Get a child by (optional) name and/or (optional) namespace.
        @param name: The name of a child element (may contain prefix).
        @type name: basestring
        @param ns: An optional namespace used to match the child.
        @type ns: (I{prefix}, I{name})
        @param default: Returned when child not-found.
        @type default: L{Element}
        @return: The requested child, or I{default} when not-found.
        @rtype: L{Element}
        N(   R   R%   RE   R    RO   (   R   R"   R#   R=   R&   R2   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR   ž  s    	c         C   s­   d } |  } xš g  | j d ƒ D] } t | ƒ d k r | ^ q D]d } d } t | ƒ \ } } | d k	 r} | j | ƒ } n  | j | | ƒ } | d k rŸ PqA | } qA W| S(   s4  
        Get a child at I{path} where I{path} is a (/) separated
        list of element names that are expected to be children.
        @param path: A (/) separated list of element names.
        @type path: basestring
        @return: The leaf node at the end of I{path}
        @rtype: L{Element}
        R   i    N(   R   R   RC   R%   RE   R   (   R   R   t   resultRM   R(   R"   R#   R&   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   childAtPathµ  s    	;
c         C   sk   g  | j  d ƒ D] } t | ƒ d k r | ^ q } t | ƒ d k rX |  j | ƒ } n |  j | ƒ } | S(   sQ  
        Get a list of children at I{path} where I{path} is a (/) separated
        list of element names that are expected to be children.
        @param path: A (/) separated list of element names.
        @type path: basestring
        @return: The collection leaf nodes at the end of I{path}
        @rtype: [L{Element},...]
        R   i    i   (   R   RC   t   getChildrent   _Element__childrenAtPath(   R   R   R(   t   partsRP   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   childrenAtPathÌ  s
    	4c         C   s„   | d k rX | d k r |  j St | ƒ \ } } | d k rF d } qX |  j | ƒ } n  g  |  j D] } | j | | ƒ rb | ^ qb S(   sx  
        Get a list of children by (optional) name and/or (optional) namespace.
        @param name: The name of a child element (may contain prefix).
        @type name: basestring
        @param ns: An optional namespace used to match the child.
        @type ns: (I{prefix}, I{name})
        @return: The list of matching children.
        @rtype: [L{Element},...]
        N(   R   R    R%   RE   RO   (   R   R"   R#   R&   R2   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyRR   Ü  s    
	c         C   s0   |  j  } g  |  _  x | D] } d | _ q W| S(   s‘   
        Detach and return this element's children.
        @return: The element's children (detached).
        @rtype: [L{Element},...]
        N(   R    R   R   (   R   t   detachedR   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   detachChildrenð  s
    		c         C   sf   |  } xY | d k	 ra | | j k r5 | | j | f S| |  j k rU | |  j | f S| j } q	 W| S(   sd  
        Resolve the specified prefix to a namespace.  The I{nsprefixes} is
        searched.  If not found, it walks up the tree until either resolved or
        the top of the tree is reached.  Searching up the tree provides for
        inherited mappings.
        @param prefix: A namespace prefix to resolve.
        @type prefix: basestring
        @param default: An optional value to be returned when the prefix
            cannot be resolved.
        @type default: (I{prefix},I{URI})
        @return: The namespace that is mapped to I{prefix} in this context.
        @rtype: (I{prefix},I{URI})
        N(   R   R   t   specialprefixesR   (   R   R&   R=   t   n(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyRE   ü  s    c         C   s   | |  j  | <|  S(   sÙ   
        Add or update a prefix mapping.
        @param p: A prefix.
        @type p: basestring
        @param u: A namespace URI.
        @type u: basestring
        @return: self
        @rtype: L{Element}
        (   R   (   R   R(   R)   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR'     s    
c         C   sG   | |  j  k r | |  j  | <n  x! |  j D] } | j | | ƒ q) W|  S(   s*  
        Update (redefine) a prefix mapping for the branch. 
        @param p: A prefix.
        @type p: basestring
        @param u: A namespace URI.
        @type u: basestring
        @return: self
        @rtype: L{Element}
        @note: This method traverses down the entire branch!
        (   R   R    t   updatePrefix(   R   R(   R)   R2   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyRZ      s
    c         C   s    | |  j  k r |  j  | =n  |  S(   sÂ   
        Clear the specified prefix from the prefix mappings.
        @param prefix: A prefix to clear.
        @type prefix: basestring
        @return: self
        @rtype: L{Element}
        (   R   (   R   R&   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   clearPrefix1  s    c         C   sš   x5 |  j  j ƒ  D]$ } | d | k r | d } | Sq Wx5 |  j j ƒ  D]$ } | d | k rH | d } | SqH W|  j d k	 r’ |  j j | | ƒ S| Sd S(   sŸ  
        Find the first prefix that has been mapped to a namespace URI.
        The local mapping is searched, then it walks up the tree until
        it reaches the top or finds a match.
        @param uri: A namespace URI.
        @type uri: basestring
        @param default: A default prefix when not found.
        @type default: basestring
        @return: A mapped prefix.
        @rtype: basestring
        i   i    N(   R   R0   RX   R   R   t
   findPrefix(   R   t   uriR=   R3   R&   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR\   =  s    

c         C   sÑ   g  } xK |  j  j ƒ  D]: } |  j | | d | ƒ r | d } | j | ƒ q q WxK |  j j ƒ  D]: } |  j | | d | ƒ rd | d } | j | ƒ qd qd W|  j d k	 rÍ | |  j j | | ƒ 7} n  | S(   s´  
        Find all prefixes that has been mapped to a namespace URI.
        The local mapping is searched, then it walks up the tree until
        it reaches the top collecting all matches.
        @param uri: A namespace URI.
        @type uri: basestring
        @param match: A matching function L{Element.matcher}.
        @type match: basestring
        @return: A list of mapped prefixes.
        @rtype: [basestring,...]
        i   i    N(   R   R0   t   matcherR.   RX   R   R   t   findPrefixes(   R   R]   RO   RP   R3   R&   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR_   V  s    

c         C   sÅ   x |  j  D] } | j ƒ  q
 W|  j d k r1 d Sx� |  j j ƒ  D]| \ } } | |  j j k rŽ |  j j | } | | k rA |  j | =qA qA n  | |  j j k rA | |  j j | <|  j | =qA qA W|  S(   sJ  
        Push prefix declarations up the tree as far as possible.  Prefix
        mapping are pushed to its parent unless the parent has the
        prefix mapped to another URI or the parent has the prefix.
        This is propagated up the tree until the top is reached.
        @return: self
        @rtype: L{Element}
        N(   R    t   promotePrefixesR   R   R   R0   R&   (   R   R2   R(   R)   t   pu(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR`   o  s    	c         C   sx   x |  j  D] } | j ƒ  q
 W|  j d k	 rb |  j |  j ƒ } | d d k	 rb | d |  _ qb n  d |  _ i  |  _ |  S(   sº   
        Refit namespace qualification by replacing prefixes
        with explicit namespaces. Also purges prefix mapping table.
        @return: self
        @rtype: L{Element}
        i   N(   R    t   refitPrefixesR&   R   RE   R   R   (   R   R2   R#   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyRb   ‡  s    		c         C   s   t  j |  ƒ |  S(   s.  
        Normalize the namespace prefixes.
        This generates unique prefixes for all namespaces.  Then retrofits all
        prefixes and prefix mappings.  Further, it will retrofix attribute values
        that have values containing (:).
        @return: self
        @rtype: L{Element}
        (   t   PrefixNormalizert   apply(   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   normalizePrefixes˜  s    	c         C   sS   t  |  j ƒ } t  |  j ƒ } |  j d k } | o8 | } | rE | S| oN | Sd S(   sã   
        Get whether the element has no children.
        @param content: Test content (children & text) only.
        @type content: boolean
        @return: True when element has not children.
        @rtype: boolean
        N(   RC   R   R    R   R   (   R   RL   t   noattrst
   nochildrent   notextt	   nocontent(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   isempty¤  s    c         C   sB   |  j  d d t j ƒ} | d k r( t S| j ƒ  j ƒ  d k Sd S(   sº   
        Get whether the element is I{nil} as defined by having
        an attribute in the I{xsi:nil="true"}
        @return: True if I{nil}, else False
        @rtype: boolean
        t   nilR#   t   trueN(   R6   RF   t   xsinsR   t   FalseR<   t   lower(   R   t   nilattr(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   isnil¶  s    c         C   sf   t  j \ } } d j | d f ƒ } |  j | t | ƒ j ƒ  ƒ |  j | | ƒ | rb d |  _ n  |  S(   s÷   
        Set this node to I{nil} as defined by having an
        attribute I{xsi:nil}=I{flag}.
        @param flag: A flag inidcating how I{xsi:nil} will be set.
        @type flag: boolean
        @return: self
        @rtype: L{Element}
        t   :Rk   N(	   RF   Rm   t   joinR:   t   strRo   R'   R   R   (   R   t   flagR(   R)   R"   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   setnilÃ  s    	c         C   sz   | d k r d St | t t f ƒ s4 t d ƒ ‚ n  | d d k rT | d |  _ n" | d |  _ | d |  j | d <d S(   s  
        Apply the namespace to this node.  If the prefix is I{None} then
        this element's explicit namespace I{expns} is set to the
        URI defined by I{ns}.  Otherwise, the I{ns} is simply mapped.
        @param ns: A namespace.
        @type ns: (I{prefix},I{URI})
        Ns   namespace must be tuplei    i   (   R   R   RH   RG   R   R   R&   R   (   R   R#   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR!   Ô  s    c         C   sh  d | d d f } g  } | j  d | |  j ƒ  f ƒ | j  |  j ƒ  ƒ x; g  |  j D] } t | ƒ ^ qW D] } | j  d | ƒ qm W|  j ƒ  r® | j  d ƒ d j | ƒ S| j  d ƒ |  j ƒ  rà | j  |  j j	 ƒ  ƒ n  x8 |  j
 D]- } | j  d ƒ | j  | j | d	 ƒ ƒ qê Wt |  j
 ƒ r>| j  d
 | ƒ n  | j  d |  j ƒ  ƒ d j | ƒ } | S(   sä   
        Get a string representation of this XML fragment.
        @param indent: The indent to be used in formatting the output.
        @type indent: int
        @return: A I{pretty} string.
        @rtype: basestring
        s   %*si   t    s   %s<%ss    %ss   />t   >s   
i   s   
%ss   </%s>(   R.   R+   t   nsdeclarationsR   t   unicodeRj   Rs   R@   R   t   escapeR    Rt   RC   (   R   t   indentt   tabRP   R   R2   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyRt   æ  s(    )c         C   s  g  } | j  d |  j ƒ  ƒ | j  |  j ƒ  ƒ x; g  |  j D] } t | ƒ ^ q= D] } | j  d | ƒ qS W|  j ƒ  r” | j  d ƒ d j | ƒ S| j  d ƒ |  j ƒ  rÆ | j  |  j j	 ƒ  ƒ n  x$ |  j
 D] } | j  | j ƒ  ƒ qÐ W| j  d |  j ƒ  ƒ d j | ƒ } | S(   s‚   
        Get a string representation of this XML fragment.
        @return: A I{plain} string.
        @rtype: basestring
        s   <%ss    %ss   />Rw   Rx   s   </%s>(   R.   R+   Ry   R   Rz   Rj   Rs   R@   R   R{   R    t   plain(   R   RP   R   R2   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR~     s     )c   	      C   s  g  } d |  j f } |  j d k r0 t j } n d |  j j f } | d | d k r… |  j d k	 r… d |  j } | j | ƒ q… n  xz |  j j ƒ  D]i } | \ } } |  j d k	 rá |  j j | ƒ } | d | k rá q• qá n  d | | f } | j | ƒ q• Wd j	 | ƒ S(   s¾   
        Get a string representation for all namespace declarations
        as xmlns="" and xmlns:p="".
        @return: A separated list of declarations.
        @rtype: basestring
        i   s    xmlns="%s"s    xmlns:%s="%s"Rw   N(
   R   R   R   RF   R=   R.   R   R0   RE   Rs   (	   R   t   st   mynst   pnst   dR3   R(   R)   R#   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyRy     s$     	c         C   s]   | d k r t } n |  j | k } | d k r9 t } n |  j ƒ  d | d k } | o\ | S(   s  
        Match by (optional) name and/or (optional) namespace.
        @param name: The optional element tag name.
        @type name: str
        @param ns: An optional namespace.
        @type ns: (I{prefix}, I{name})
        @return: True if matched.
        @rtype: boolean
        i   N(   R   t   TrueR"   R-   (   R   R"   R#   t   bynamet   byns(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyRO   4  s    
		c         C   s1   |  g } x! |  j  D] } | | j ƒ  7} q W| S(   s†   
        Get a flattened representation of the branch.
        @return: A flat list of nodes.
        @rtype: [L{Element},..]
        (   R    t   branch(   R   R†   R2   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR†   H  s    	c         C   s<   g  } |  j  } x& | d k	 r7 | j | ƒ | j  } q W| S(   sp   
        Get a list of ancestors.
        @return: A list of ancestors.
        @rtype: [L{Element},..]
        N(   R   R   R.   (   R   t	   ancestorsR(   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR‡   S  s    	c         C   s/   | |  ƒ x |  j  D] } | j | ƒ q W|  S(   sª   
        Walk the branch and call the visitor function
        on each node.
        @param visitor: A function.
        @return: self
        @rtype: L{Element}
        (   R    t   walk(   R   t   visitorR2   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyRˆ   `  s    
c         C   sh   g  } x: |  j  D]/ } | j ƒ  | j t ƒ r | j | ƒ q q Wx | D] } |  j  j | ƒ qJ Wd S(   s2   
        Prune the branch of empty nodes.
        N(   R    t   pruneRj   Rn   R.   R4   (   R   t   prunedR2   R(   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyRŠ   m  s    
c         C   s÷   g  } |  } t  | ƒ d } | |  } | | } xl | D]d } d  } t | ƒ \ }	 } |	 d  k	 rs | j |	 ƒ } n  | j | | ƒ }
 |
 d  k r• Pq7 |
 } q7 W|
 d  k	 ró d  } t | ƒ \ }	 } |	 d  k	 rá | j |	 ƒ } n  |
 j | ƒ } n  | S(   Ni   (   RC   R   R%   RE   R   RR   (   R   RT   RP   RM   t   lastR‡   t   leafR"   R#   R&   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   __childrenAtPathz  s*    


c         C   s   t  |  j ƒ S(   N(   RC   R    (   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   __len__’  s    c         C   sD   t  | t ƒ r |  j | ƒ S| t |  j ƒ k  r< |  j | Sd  Sd  S(   N(   R   t
   basestringR>   RC   R    R   (   R   RK   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   __getitem__•  s
    c         C   s`   t  | t ƒ r" |  j | | ƒ n: | t |  j ƒ k  r\ t  | t ƒ r\ |  j j | | ƒ n  d  S(   N(   R   R�   R:   RC   R    R   RJ   (   R   RK   R8   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   __setitem__ž  s
    c         C   sK   | d  k	 oJ t | t ƒ oJ |  j | j k oJ |  j ƒ  d | j ƒ  d k S(   Ni   (   R   R   R   R"   R-   (   R   t   rhs(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   __eq__¦  s    c         C   s   d |  j  |  j f S(   Ns   Element (prefix=%s, name=%s)(   R&   R"   (   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   __repr__¬  s    c         C   s   t  |  ƒ j d ƒ S(   Ns   utf-8(   Rz   t   encode(   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   __str__°  s    c         C   s
   |  j  ƒ  S(   N(   Rt   (   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   __unicode__³  s    c         C   s
   t  |  ƒ S(   N(   t   NodeIterator(   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   __iter__¶  s    N(D   R   t
   __module__t   __doc__R^   RF   t   xmlnsRX   t   classmethodR   R   R$   R   R*   R+   R,   R/   R5   R:   R;   R>   R?   RA   RB   R@   R-   RD   R.   RJ   R4   RN   R6   R   RQ   RU   RR   RW   R=   RE   R'   RZ   R[   R\   R_   R`   Rb   Re   Rƒ   Rj   Rq   Rv   R!   Rt   R~   Ry   RO   R†   R‡   Rˆ   RŠ   RS   R�   R‘   R’   R”   R•   R—   R˜   Rš   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR   !   s€   


								
																																	R™   c           B   s    e  Z d  Z d „  Z d „  Z RS(   s¶   
    The L{Element} child node iterator.
    @ivar pos: The current position
    @type pos: int
    @ivar children: A list of a child nodes.
    @type children: [L{Element},..] 
    c         C   s   d |  _  | j |  _ d S(   sX   
        @param parent: An element to iterate.
        @type parent: L{Element}
        i    N(   t   posR    (   R   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR$   Ã  s    	c         C   s>   y' |  j  |  j } |  j d 7_ | SWn t ƒ  ‚ n Xd S(   sŠ   
        Get the next child.
        @return: The next child.
        @rtype: L{Element}
        @raise StopIterator: At the end.
        i   N(   R    RŸ   t   StopIteration(   R   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   nextË  s    (   R   R›   Rœ   R$   R¡   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR™   º  s   	Rc   c           B   s‰   e  Z d  Z e 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 „  Z RS(   sy  
    The prefix normalizer provides namespace prefix normalization.
    @ivar node: A node to normalize.
    @type node: L{Element}
    @ivar branch: The nodes flattened branch.
    @type branch: [L{Element},..]
    @ivar namespaces: A unique list of namespaces (URI).
    @type namespaces: [str,]
    @ivar prefixes: A reverse dict of prefixes.
    @type prefixes: {u, p}
    c         C   s   t  | ƒ } | j ƒ  S(   s¹   
        Normalize the specified node.
        @param node: A node to normalize.
        @type node: L{Element}
        @return: The normalized node.
        @rtype: L{Element}
        (   Rc   t   refit(   t   clsRM   t   pn(    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyRd   ç  s    	c         C   s:   | |  _  | j ƒ  |  _ |  j ƒ  |  _ |  j ƒ  |  _ d S(   sR   
        @param node: A node to normalize.
        @type node: L{Element}
        N(   RM   R†   t   getNamespacest
   namespacest   genPrefixest   prefixes(   R   RM   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR$   ó  s    	c         C   sk   t  ƒ  } x[ |  j |  j j ƒ  D]C } |  j | j ƒ rK | j | j ƒ n  | j |  j | ƒ ƒ } q  W| S(   s‰   
        Get the I{unique} set of namespaces referenced in the branch.
        @return: A set of namespaces.
        @rtype: set
        (	   R:   R†   RM   R‡   t   permitR   t   addt   uniont   pset(   R   R   RY   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR¥   ý  s    	c         C   sJ   t  ƒ  } x: | j j ƒ  D]) } |  j | ƒ r | j | d ƒ q q W| S(   sª   
        Convert the nodes nsprefixes into a set.
        @param n: A node.
        @type n: L{Element}
        @return: A set of namespaces.
        @rtype: set
        i   (   R:   R   R0   R©   Rª   (   R   RY   R   R#   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR¬   
  s
    	c         C   sB   i  } d } x/ |  j  D]$ } d | } | | | <| d 7} q W| S(   sš   
        Generate a I{reverse} mapping of unique prefixes for all namespaces.
        @return: A referse dict of prefixes.
        @rtype: {u, p}
        i    s   ns%di   (   R¦   (   R   R¨   RY   R)   R(   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR§     s    

c         C   s   |  j  ƒ  |  j ƒ  d S(   s=   
        Refit (normalize) the prefixes in the node.
        N(   t
   refitNodest   refitMappings(   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR¢   &  s    
c         C   si   xb |  j  D]W } | j d k	 rT | j ƒ  } |  j | ƒ rT |  j | d | _ qT n  |  j | ƒ q
 Wd S(   sC   
        Refit (normalize) all of the nodes in the branch.
        i   N(   R†   R&   R   R-   R©   R¨   t
   refitAttrs(   R   RY   R#   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR­   -  s    c         C   s%   x | j  D] } |  j | ƒ q
 Wd S(   s|   
        Refit (normalize) all of the attributes in the node.
        @param n: A node.
        @type n: L{Element}
        N(   R   t	   refitAddr(   R   RY   R   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR¯   8  s    c         C   sU   | j  d k	 rD | j ƒ  } |  j | ƒ rD |  j | d | _  qD n  |  j | ƒ d S(   sp   
        Refit (normalize) the attribute.
        @param a: An attribute.
        @type a: L{Attribute}
        i   N(   R&   R   R-   R©   R¨   t
   refitValue(   R   R   R#   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR°   A  s
    c         C   s€   t  | j ƒ  ƒ \ } } | d k r( d S| j | ƒ } |  j | ƒ r| | d } |  j | } | j d j | | f ƒ ƒ n  d S(   sx   
        Refit (normalize) the attribute's value.
        @param a: An attribute.
        @type a: L{Attribute}
        Ni   Rr   (   R%   R<   R   RE   R©   R¨   R7   Rs   (   R   R   R(   R"   R#   R)   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR±   M  s     
c         C   sZ   x |  j  D] } i  | _ q
 W|  j } x- |  j j ƒ  D] \ } } | j | | ƒ q6 Wd S(   sA   
        Refit (normalize) all of the nsprefix mappings.
        N(   R†   R   RM   R¨   R0   R'   (   R   RY   R)   R(   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR®   [  s
    	c         C   s   |  j  | ƒ S(   sµ   
        Get whether the I{ns} is to be normalized.
        @param ns: A namespace.
        @type ns: (p,u)
        @return: True if to be included.
        @rtype: boolean
        (   t   skip(   R   R#   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR©   e  s    c         C   sF   | d k pE | t j k pE | t j k pE | t j k pE | t j k S(   s»   
        Get whether the I{ns} is to B{not} be normalized.
        @param ns: A namespace.
        @type ns: (p,u)
        @return: True if to be skipped.
        @rtype: boolean
        N(   R   RF   R=   t   xsdnsRm   R�   (   R   R#   (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyR²   o  s
    (   R   R›   Rœ   Rž   Rd   R$   R¥   R¬   R§   R¢   R­   R¯   R°   R±   R®   R©   R²   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyRc   Ú  s   	
										
	
(   Rœ   t   loggingR    t   sudst   suds.saxt   suds.sax.textR   t   suds.sax.attributeR   t   syst   version_infot   setsR   R:   R   t   logR   R™   Rc   (    (    (    sJ   /opt/xtal/ccp4-6.5-linux32/lib/python2.7/site-packages/suds/sax/element.pyt   <module>   s    

ÿ ÿ ÿ œ 