ó
¿b›]c           @   s©   d  Z  d d l 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
 e
 f d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d „  Z d S(   s  Provides the :class:`~sqlalchemy.engine.url.URL` class which encapsulates
information about a database connection specification.

The URL object is created automatically when
:func:`~sqlalchemy.engine.create_engine` is called with a string
argument; alternatively, the URL is a public-facing construct which can
be used directly and is also accepted directly by ``create_engine()``.
iÿÿÿÿNi   (   t   Dialecti   (   t   exc(   t   util(   t   plugins(   t   registryt   URLc           B   s¼   e  Z d  Z d d d d d d d „ Z e d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z e d „  ƒ Z e j d	 „  ƒ Z d
 „  Z d „  Z d „  Z d „  Z d „  Z g  d „ Z RS(   sX  
    Represent the components of a URL used to connect to a database.

    This object is suitable to be passed directly to a
    :func:`~sqlalchemy.create_engine` call.  The fields of the URL are parsed
    from a string by the :func:`.make_url` function.  the string
    format of the URL is an RFC-1738-style string.

    All initialization parameters are available as public attributes.

    :param drivername: the name of the database backend.
      This name will correspond to a module in sqlalchemy/databases
      or a third party plug-in.

    :param username: The user name.

    :param password: database password.

    :param host: The name of the host.

    :param port: The port number.

    :param database: The database name.

    :param query: A dictionary of options to be passed to the
      dialect and/or the DBAPI upon connect.

    c         C   sg   | |  _  | |  _ | |  _ | |  _ | d  k	 rB t | ƒ |  _ n	 d  |  _ | |  _ | p] i  |  _ d  S(   N(	   t
   drivernamet   usernamet   password_originalt   hostt   Nonet   intt   portt   databaset   query(   t   selfR   R   t   passwordR	   R   R   R   (    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   __init__8   s    
						c            sO  ˆ  j  d } ˆ  j d  k	 rq | t ˆ  j ƒ 7} ˆ  j d  k	 rd | d | rP d n t ˆ  j ƒ 7} n  | d 7} n  ˆ  j d  k	 r³ d ˆ  j k r£ | d ˆ  j 7} q³ | ˆ  j 7} n  ˆ  j d  k	 rÜ | d t ˆ  j ƒ 7} n  ˆ  j d  k	 rÿ | d ˆ  j 7} n  ˆ  j	 rKt
 ˆ  j	 ƒ } | j ƒ  | d d j ‡  f d	 †  | Dƒ ƒ 7} n  | S(
   Ns   ://t   :s   ***t   @s   [%s]t   /t   ?t   &c         3   s<   |  ]2 } t  j ˆ  j | ƒ D] } d  | | f Vq q d S(   s   %s=%sN(   R   t   to_listR   (   t   .0t   kt   element(   R   (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pys	   <genexpr>c   s   (   R   R   R
   t   _rfc_1738_quoteR   R	   R   t   strR   R   t   listt   sortt   join(   R   t   hide_passwordt   st   keys(    (   R   s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   __to_string__M   s,     	
c         C   s   |  j  d t ƒ S(   NR    (   R#   t   False(   R   (    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   __str__i   s    c         C   s
   |  j  ƒ  S(   N(   R#   (   R   (    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   __repr__l   s    c         C   s   t  t |  ƒ ƒ S(   N(   t   hashR   (   R   (    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   __hash__o   s    c         C   s‹   t  | t ƒ oŠ |  j | j k oŠ |  j | j k oŠ |  j | j k oŠ |  j | j k oŠ |  j | j k oŠ |  j | j k oŠ |  j | j k S(   N(	   t
   isinstanceR   R   R   R   R	   R   R   R   (   R   t   other(    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   __eq__r   s    c         C   s   |  | k S(   N(    (   R   R*   (    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   __ne__~   s    c         C   s'   |  j  d  k r d  St j |  j  ƒ Sd  S(   N(   R   R
   R   t	   text_type(   R   (    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyR      s    c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyR   ˆ   s    c         C   s.   d |  j  k r |  j  S|  j  j d ƒ d Sd  S(   Nt   +i    (   R   t   split(   R   (    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   get_backend_nameŒ   s    c         C   s4   d |  j  k r |  j ƒ  j S|  j  j d ƒ d Sd  S(   NR.   i   (   R   t   get_dialectt   driverR/   (   R   (    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   get_driver_name’   s    c         C   s]   t  j |  j j d d ƒ ƒ } | | j d g  ƒ 7} g  | D] } t j | ƒ |  | ƒ ^ q; S(   Nt   pluginR   (    (   R   R   R   t   getR   t   load(   R   t   kwargst   plugin_namest   plugin_name(    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   _instantiate_plugins˜   s    c         C   s   d |  j  k r |  j  } n |  j  j d d ƒ } t j | ƒ } t | d ƒ ry t | j t ƒ ry t | j t	 ƒ ry | j S| Sd S(   sº   Return the "entry point" dialect class.

        This is normally the dialect itself except in the case when the
        returned class implements the get_dialect_cls() method.

        R.   t   .t   dialectN(
   R   t   replaceR   R6   t   hasattrR)   R<   t   typet
   issubclassR    (   R   t   namet   cls(    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   _get_entrypoint¡   s    c         C   s   |  j  ƒ  } | j |  ƒ } | S(   sf   Return the SQLAlchemy database dialect class corresponding
        to this URL's driver name.
        (   RC   t   get_dialect_cls(   R   t
   entrypointt   dialect_cls(    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyR1   ¹   s    c         K   s›   i  } d d d d d g } xy | D]q } | r@ | j  d ƒ } n | | k rY | | } n | } | d k	 r" t |  | t ƒ r" t |  | ƒ | | <q" q" W| S(   s2  Translate url attributes into a dictionary of connection arguments.

        Returns attributes of this url (`host`, `database`, `username`,
        `password`, `port`) as a plain dictionary.  The attribute names are
        used as the keys by default.  Unset or false attributes are omitted
        from the final dictionary.

        :param \**kw: Optional, alternate key names for url attributes.

        :param names: Deprecated.  Same purpose as the keyword-based alternate
            names, but correlates the name to the original positionally.
        R	   R   R   R   R   i    N(   t   popR
   t   getattrR$   (   R   t   namest   kwt
   translatedt   attribute_namest   snameRA   (    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   translate_connect_argsÁ   s    N(   t   __name__t
   __module__t   __doc__R
   R   t   TrueR#   R%   R&   R(   R+   R,   t   propertyR   t   setterR0   R3   R:   RC   R1   RN   (    (    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyR      s*   											c         C   s$   t  |  t j ƒ r t |  ƒ S|  Sd S(   sÇ   Given a string or unicode instance, produce a new URL instance.

    The given string is parsed according to the RFC 1738 spec.  If an
    existing URL object is passed, just returns the object.
    N(   R)   R   t   string_typest   _parse_rfc1738_args(   t   name_or_url(    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   make_urlÝ   s    
c   
      C   sÓ  t  j d t  j ƒ } | j |  ƒ } | d  k	 r¼| j ƒ  } | d d  k	 r| d j d d ƒ } | d | d <t | ƒ d k ri  } x† t j	 | d ƒ D]h \ } } t j
 rÃ | j d ƒ } n  | | k rú t j | | ƒ | | <| | j | ƒ qœ | | | <qœ Wqd  } n d  } | | d <| d	 d  k	 rKt | d	 ƒ | d	 <n  | d
 d  k	 rrt | d
 ƒ | d
 <n  | j d ƒ } | j d ƒ }	 | p™|	 | d <| j d ƒ }  t |  |  St j d |  ƒ ‚ d  S(   Ns€  
            (?P<name>[\w\+]+)://
            (?:
                (?P<username>[^:/]*)
                (?::(?P<password>.*))?
            @)?
            (?:
                (?:
                    \[(?P<ipv6host>[^/]+)\] |
                    (?P<ipv4host>[^/:]+)
                )?
                (?::(?P<port>[^/]*))?
            )?
            (?:/(?P<database>.*))?
            R   R   i   i    i   t   asciiR   R   R   t   ipv4hostt   ipv6hostR	   RA   s,   Could not parse rfc1738 URL from string '%s'(   t   ret   compilet   Xt   matchR
   t	   groupdictR/   t   lenR   t	   parse_qslt   py2kt   encodeR   t   appendt   _rfc_1738_unquoteRG   R   R   t   ArgumentError(
   RA   t   patternt   mt
   componentst   tokensR   t   keyt   valueRZ   R[   (    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyRV   ê   s@     		
c         C   s   t  j d d „  |  ƒ S(   Ns   [:@/]c         S   s   d t  |  j d ƒ ƒ S(   Ns   %%%Xi    (   t   ordt   group(   Ri   (    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   <lambda>(  t    (   R\   t   sub(   t   text(    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyR   '  s    c         C   s   t  j |  ƒ S(   N(   R   t   unquote(   Rs   (    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyRf   +  s    c         C   s`   t  j d |  ƒ } | d  k	 rX | j d d ƒ \ }  } t t j | ƒ ƒ } t |  | Œ Sd  Sd  S(   Ns   (\w+)://(.*)i   i   (   R\   R_   R
   Ro   t   dictR   Rb   R   (   RA   Ri   t   argst   opts(    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   _parse_keyvalue_args/  s    (   RQ   R\   t
   interfacesR    Rq   R   R   t   dialectsR   R   t   objectR   RX   RV   R   Rf   Rx   (    (    (    s4   lib/python2.7/site-packages/sqlalchemy/engine/url.pyt   <module>   s   Ã		=		