
MV]c           @   sA  d  d l  Z  d  d l Z d  d l m Z m Z d  d l m Z d  d l m Z m	 Z	 m
 Z
 d  d l m Z d  d l m Z m Z d  d l m Z d  d l m Z m Z 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  m! Z! i  a" d e# f d     YZ$ d e$ f d     YZ% d   Z& d S(   iN(   t   FileNotFoundErrort   is_pypy(   t   generate_grammar(   t   split_linest   python_bytes_to_unicodet   parse_version_string(   t
   DiffParser(   t   tokenize_linest   tokenize(   t   PythonTokenTypes(   t   parser_cachet   load_modulet   save_module(   t
   BaseParser(   t   Parser(   t   ErrorFinderConfig(   t   pep8(   t   FileIOt   KnownContentFileIOt   Grammarc        
   B   s   e  Z d  Z d Z d Z e j   Z e	 d d  Z
 d d  Z d e d d e e d d d d 	 Z d   Z d   Z d   Z d d	  Z d d
  Z d   Z RS(   s   
    :py:func:`parso.load_grammar` returns instances of this class.

    Creating custom none-python grammars by calling this is not supported, yet.
    c         C   s[   t  | d |  j   |  _ | |  _ | |  _ | |  _ t j | j d   j	   |  _
 d  S(   Nt   token_namespaces   utf-8(   R   t   _get_token_namespacet   _pgen_grammart   _parsert
   _tokenizert   _diff_parsert   hashlibt   sha256t   encodet	   hexdigestt   _hashed(   t   selft   textt	   tokenizert   parsert   diff_parser(    (    s,   lib/python2.7/site-packages/parso/grammar.pyt   __init__   s    			c         K   s.   d | k r t  d   n  |  j d | |  S(   s  
        If you want to parse a Python file you want to start here, most likely.

        If you need finer grained control over the parsed instance, there will be
        other ways to access it.

        :param str code: A unicode or bytes string. When it's not possible to
            decode bytes to a string, returns a
            :py:class:`UnicodeDecodeError`.
        :param bool error_recovery: If enabled, any code will be returned. If
            it is invalid, it will be returned as an error node. If disabled,
            you will get a ParseError when encountering syntax errors in your
            code.
        :param str start_symbol: The grammar rule (nonterminal) that you want
            to parse. Only allowed to be used when error_recovery is False.
        :param str path: The path to the file you want to open. Only needed for caching.
        :param bool cache: Keeps a copy of the parser tree in RAM and on disk
            if a path is given. Returns the cached trees if the corresponding
            files on disk have not changed. Note that this stores pickle files
            on your file system (e.g. for Linux in ``~/.cache/parso/``).
        :param bool diff_cache: Diffs the cached python module against the new
            code and tries to parse only the parts that have changed. Returns
            the same (changed) module that is found in cache. Using this option
            requires you to not do anything anymore with the cached modules
            under that path, because the contents of it might change. This
            option is still somewhat experimental. If you want stability,
            please don't use it.
        :param bool cache_path: If given saves the parso cache in this
            directory. If not given, defaults to the default cache places on
            each platform.

        :return: A subclass of :py:class:`parso.tree.NodeOrLeaf`. Typically a
            :py:class:`parso.python.tree.Module`.
        t	   start_poss+   parse() got an unexpected keyword argument.t   code(   t	   TypeErrort   _parse(   R   R&   t   kwargs(    (    s,   lib/python2.7/site-packages/parso/grammar.pyt   parse)   s    #i   i    c
      	   C   sk  | d k r3 | d k r3 | d k r3 t d   n  | d k rK |  j } n  | rl | d k rl t d   n  | d k r | d k r t |  } q t | |  } n  | r | j d k	 r t |  j | d | }
 |
 d k	 r |
 Sn  | d k r | j	   } n  t
 |  } t | d t } | r|  j d k rBt d   n  y t |  j | j } Wn t k
 rmqX| j }
 | j } | | k r|
 S|  j |  j |  j |
  j d | d |  } t |  j | | | d	 | ot d | | Sn  |  j | |	  } |  j |  j d
 | d | } | j d |  } | s;| rgt |  j | | | d	 | oZt d | n  | S(   s   
        Wanted python3.5 * operator and keyword only arguments. Therefore just
        wrap it all.
        start_pos here is just a parameter internally used. Might be public
        sometime in the future.
        s%   Please provide either code or a path.t
   file_inputs"   This is currently not implemented.t
   cache_patht   keependss?   You have to define a diff parser to be able to use this option.t	   old_linest	   new_linest   picklingt   error_recoveryt   start_nonterminalt   tokensN(   t   NoneR'   t   _start_nonterminalt   NotImplementedErrorR   R   t   pathR   R   t   readR   R   t   TrueR   R
   t   KeyErrort   nodet   linesR   R   t   updateR   R   R   R*   (   R   R&   R1   R7   t   start_symbolt   cachet
   diff_cacheR,   t   file_ioR%   t   module_nodeR<   t   module_cache_itemR.   t   new_nodeR3   t   pt	   root_node(    (    s,   lib/python2.7/site-packages/parso/grammar.pyR(   P   s`    	$					
c         C   s(   |  j  } | d  k r$ t d   n  | S(   Ns"   The token namespace should be set.(   t   _token_namespaceR4   t
   ValueError(   R   t   ns(    (    s,   lib/python2.7/site-packages/parso/grammar.pyR      s    	c         C   s1   |  j  d k r t d   n  |  j | |  j   S(   s   
        Given a :py:class:`parso.tree.NodeOrLeaf` returns a generator of
        :py:class:`parso.normalizer.Issue` objects. For Python this is
        a list of syntax/indentation errors.
        s/   No error normalizer specified for this grammar.N(   t   _error_normalizer_configR4   RH   t   _get_normalizer_issues(   R   R;   (    (    s,   lib/python2.7/site-packages/parso/grammar.pyt   iter_errors   s    c         C   s@   | d  k r3 |  j } | d  k r3 t d   q3 n  | j |   S(   NsV   You need to specify a normalizer, because there's no default normalizer for this tree.(   R4   t   _default_normalizer_configRH   t   create_normalizer(   R   t   normalizer_config(    (    s,   lib/python2.7/site-packages/parso/grammar.pyt   _get_normalizer   s
    	c         C   s   |  j  |  } | j |  S(   ss   
        TODO this is not public, yet.
        The returned code will be normalized, e.g. PEP8 for Python.
        (   RP   t   walk(   R   R;   RO   t
   normalizer(    (    s,   lib/python2.7/site-packages/parso/grammar.pyt
   _normalize   s    c         C   s#   |  j  |  } | j |  | j S(   N(   RP   RQ   t   issues(   R   R;   RO   RR   (    (    s,   lib/python2.7/site-packages/parso/grammar.pyRK      s    c         C   sC   |  j  j j   } d j t |  d   d } d |  j j | f S(   Nt    i   s    ...s   <%s:%s>(   R   t   nonterminal_to_dfast   keyst   joint   listt	   __class__t   __name__(   R   t   nonterminalst   txt(    (    s,   lib/python2.7/site-packages/parso/grammar.pyt   __repr__   s    N(   i   i    (   R[   t
   __module__t   __doc__R4   RJ   RG   R   t   PEP8NormalizerConfigRM   R   R$   R*   R9   t   FalseR(   R   RL   RP   RS   RK   R^   (    (    (    s,   lib/python2.7/site-packages/parso/grammar.pyR      s   
'		J			t   PythonGrammarc           B   s8   e  Z e   Z e Z d  Z d   Z d   Z d   Z	 RS(   R+   c         C   s8   t  t |   j | d |  j d t d t | |  _ d  S(   NR!   R"   R#   (   t   superRc   R$   t   _tokenize_linest   PythonParserR   t   version_info(   R   Rg   t   bnf_text(    (    s,   lib/python2.7/site-packages/parso/grammar.pyR$      s    	c         C   s   t  | |  j d | S(   NR%   (   R   Rg   (   R   R<   R%   (    (    s,   lib/python2.7/site-packages/parso/grammar.pyRe      s    c         C   s   t  | |  j  S(   N(   R   Rg   (   R   R&   (    (    s,   lib/python2.7/site-packages/parso/grammar.pyt	   _tokenize   s    (
   R[   R_   R   RJ   R	   RG   R5   R$   Re   Ri   (    (    (    s,   lib/python2.7/site-packages/parso/grammar.pyRc      s   				c          K   s   d d d d  } | |    S(   s   
    Loads a :py:class:`parso.Grammar`. The default version is the current Python
    version.

    :param str version: A python version string, e.g. ``version='3.3'``.
    :param str path: A path to a grammar file
    t   pythonc   	      S   s	  |  d k r t  |  } | p@ t j j d d | j | j f  } t j j t j j t  |  } y t | SWqt	 k
 r yD t
 |   } | j   } Wd  QXt | |  } t j | |  SWq t k
 r d | } t |   q XqXn t d |    d  S(   NRj   s   grammar%s%s.txts-   Python version %s is currently not supported.s   No support for language %s.(   R   t   osR7   RX   t   majort   minort   dirnamet   __file__t   _loaded_grammarsR:   t   openR8   Rc   t
   setdefaultR    R6   (	   t   languaget   versionR7   Rg   t   filet   fRh   t   grammart   message(    (    s,   lib/python2.7/site-packages/parso/grammar.pyt   load_grammar   s$    !
N(   R4   (   R)   Ry   (    (    s,   lib/python2.7/site-packages/parso/grammar.pyRy      s    ('   R   Rk   t   parso._compatibilityR    R   t   parso.pgen2R   t   parso.utilsR   R   R   t   parso.python.diffR   t   parso.python.tokenizeR   R   t   parso.python.tokenR	   t   parso.cacheR
   R   R   t   parso.parserR   t   parso.python.parserR   Rf   t   parso.python.errorsR   t   parso.pythonR   t   parso.file_ioR   R   Rp   t   objectR   Rc   Ry   (    (    (    s,   lib/python2.7/site-packages/parso/grammar.pyt   <module>   s"   