ó
{c‹Ac           @   sý   d  Z  d d l m Z d d l m Z d d l m Z d d l m Z d d l	 m
 Z
 d d l m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d d d „  ƒ  YZ d S(   s    XTM file parser. iÿÿÿÿ(   t   minidom(   t   TopicMap(   t   Topic(   t   BaseNameString(   t   BaseName(   t   Association(   t
   InstanceOf(   t   TopicRef(   t   Scope(   t
   Occurrence(   t   ResourceRef(   t   Member(   t   RoleSpec(   t   ns_xlinkt   Parserc           B   sª   e  Z 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 „  Z d „  Z d „  Z d „  Z d „  Z RS(   s    XTM file parser. s   utf-8c         C   s   | |  _  d S(   sH   Initialize Parser object. (encoding="utf-8") - set TopicMap xml encodingN(   t	   _encoding(   t   selft   encoding(    (    s   lib/xtm/Parser.pyt   __init__   s    c         C   s   t  |  d | j ƒ | ƒ S(   s)   get XTM object representation of dom nodet   _parse_(   t   getattrt   nodeName(   R   t   node(    (    s   lib/xtm/Parser.pyt	   parseNode   s    c         C   sG   x@ | j  D]5 } t |  d | j ƒ r
 | j |  j | ƒ ƒ q
 q
 Wd S(   s@   (xtmObject, xtmNode), parse xtmNode and add objects to xtmObjectR   N(   t
   childNodest   hasattrR   t   addChildR   (   R   t	   xtmObjectt   xtmNodet   child(    (    s   lib/xtm/Parser.pyt	   _addChild    s    c         C   s%   t  j | ƒ } | j } |  j | ƒ S(   s!   parse xtm file -> TopicMap object(   R    t   parset
   firstChildR   (   R   t   filenamet   xmlR   (    (    s   lib/xtm/Parser.pyR   &   s    	c         C   s%   t  j | ƒ } | j } |  j | ƒ S(   s#   parse xtm string -> TopicMap object(   R    t   parseStringR    R   (   R   t   stringR"   R   (    (    s   lib/xtm/Parser.pyR#   ,   s    	c         C   s5   | j  d ƒ } t | |  j ƒ } |  j | | ƒ | S(   s   parse topicMap node -> TopicMapt   id(   t   getAttributeR   R   R   (   R   t   tmNodeR%   t   topicMap(    (    s   lib/xtm/Parser.pyt   _parse_topicMap2   s    c         C   s/   | j  d ƒ } t | ƒ } |  j | | ƒ | S(   s   parse topic node -> TopicR%   (   R&   R   R   (   R   t	   topicNodeR%   t   topic(    (    s   lib/xtm/Parser.pyt   _parse_topic9   s    c         C   s   t  ƒ  } |  j | | ƒ | S(   s#   parse occurrence node -> Occurrence(   R	   R   (   R   t   occurrenceNodet
   occurrence(    (    s   lib/xtm/Parser.pyt   _parse_occurrence@   s    	c         C   s   | j  t d ƒ } t | ƒ S(   s%   parse resourceRef node -> ResourceReft   href(   t   getAttributeNSR   R
   (   R   t   resourceRefNodeR0   (    (    s   lib/xtm/Parser.pyt   _parse_resourceRefF   s    c         C   s   t  ƒ  } |  j | | ƒ | S(   s#   parse instanceOf node -> InstanceOf(   R   R   (   R   t   instanceOfNodet
   instanceOf(    (    s   lib/xtm/Parser.pyt   _parse_instanceOfK   s    	c         C   s9   | j  t d ƒ } | d d k r/ | d } n  t | ƒ S(   s   parse topicRef node -> TopicRefR0   i    t   #i   (   R1   R   R   (   R   t   topicRefNodeR0   (    (    s   lib/xtm/Parser.pyt   _parse_topicRefQ   s    c         C   s   t  ƒ  } |  j | | ƒ | S(   s   parse baseName node -> BaseName(   R   R   (   R   t   baseNameNodet   baseName(    (    s   lib/xtm/Parser.pyt   _parse_baseNameX   s    	c         C   s   t  ƒ  } |  j | | ƒ | S(   s   parse scope node -> Scope(   R   R   (   R   t	   scopeNodet   scope(    (    s   lib/xtm/Parser.pyt   _parse_scope^   s    	c         C   s   | j  j } t | ƒ S(   s+   parse baseNameString node -> BaseNameString(   R    t	   nodeValueR   (   R   t   baseNameStringNodet   name(    (    s   lib/xtm/Parser.pyt   _parse_baseNameStringd   s    c         C   s/   | j  d ƒ } t | ƒ } |  j | | ƒ | S(   s%   parse association node -> AssociationR%   (   R&   R   R   (   R   t   associationNodeR%   t   association(    (    s   lib/xtm/Parser.pyt   _parse_associationi   s    c         C   s   t  ƒ  } |  j | | ƒ | S(   s   parse member node -> Member(   R   R   (   R   t
   memberNodet   member(    (    s   lib/xtm/Parser.pyt   _parse_memberp   s    	c         C   s   t  ƒ  } |  j | | ƒ | S(   s   parse roleSpec node -> RoleSpec(   R   R   (   R   t   roleSpecNodet   roleSpec(    (    s   lib/xtm/Parser.pyt   _parse_roleSpecv   s    	(   t   __name__t
   __module__t   __doc__R   R   R   R   R#   R)   R,   R/   R3   R6   R9   R<   R?   RC   RF   RI   RL   (    (    (    s   lib/xtm/Parser.pyR      s$   															N(    (   RO   t   xml.domR    t   xtm.TopicMapR   t	   xtm.TopicR   t   xtm.BaseNameStringR   t   xtm.BaseNameR   t   xtm.AssociationR   t   xtm.InstanceOfR   t   xtm.TopicRefR   t	   xtm.ScopeR   t   xtm.OccurrenceR	   t   xtm.ResourceRefR
   t
   xtm.MemberR   t   xtm.RoleSpecR   R   R   (    (    (    s   lib/xtm/Parser.pyt   <module>   s   