î
5dÝVÊ  ã               @   sð  d  Z  d d l m Z m Z m Z m Z m Z d d l m Z m Z m	 Z	 m
 Z
 d d l m Z m Z m Z d d l m Z m Z m Z m Z m Z d d l m Z m Z m Z d d l m Z m Z d d l m Z m Z m Z m Z d d	 l m Z d d
 l m Z d d l j  Z! e! j" e# e! j$ ƒ e! j" e% d ƒ e! j& ƒ y d d l' m( Z( Wn e) k
 rkYn' Xd d l m( Z* e! j" e( e* ƒ [( [* d d l+ Z+ e+ j, d ƒ e+ j, d ƒ d d „ Z- [+ d d d d d d d d d d d „	 Z. d S)aŽ  A Python driver for PostgreSQL

psycopg is a PostgreSQL_ database adapter for the Python_ programming
language. This is version 2, a complete rewrite of the original code to
provide new-style classes for connection and cursor objects and other sweet
candies. Like the original, psycopg 2 was written with the aim of being very
small and fast, and stable as a rock.

Homepage: http://initd.org/projects/psycopg2

.. _PostgreSQL: http://www.postgresql.org/
.. _Python: http://www.python.org/

:Groups:
  * `Connections creation`: connect
  * `Value objects constructors`: Binary, Date, DateFromTicks, Time,
    TimeFromTicks, Timestamp, TimestampFromTicks
é    )ÚBINARYÚNUMBERÚSTRINGÚDATETIMEÚROWID)ÚBinaryÚDateÚTimeÚ	Timestamp)ÚDateFromTicksÚTimeFromTicksÚTimestampFromTicks)ÚErrorÚWarningÚ	DataErrorÚDatabaseErrorÚProgrammingError)ÚIntegrityErrorÚInterfaceErrorÚInternalError)ÚNotSupportedErrorÚOperationalError)Ú_connectÚapilevelÚthreadsafetyÚ
paramstyle)Ú__version__)ÚtzN)ÚDecimalz([\\'])z\sc             C   s@   |  s
 d S| j  d |  ƒ }  | j |  ƒ r< d |  d }  n  |  S)z9
    Apply the escaping rule required by PQconnectdb
    z''z\\\1ú')ÚsubÚsearch)ÚsZ	re_escapeZre_space© r#   ú5/tmp/pip-build-0jahl3lb/psycopg2/psycopg2/__init__.pyÚ_param_escapeU   s     r%   Fc	             K   sq  g  }
 | d k	 r( |
 j  d | f ƒ n  | d k	 rJ |
 j  d | f ƒ n  | d k	 rl |
 j  d | f ƒ n  | d k	 rŽ |
 j  d | f ƒ n  | d k	 r° |
 j  d | f ƒ n  |
 j d d „  |	 j ƒ  Dƒ ƒ |  d k	 rý |
 rý t d	 |
 d
 d
 ƒ ‚ n  |  d k r=|
 st d ƒ ‚ q=d j d d „  |
 Dƒ ƒ }  n  t |  d | d | ƒ} | d k	 rm| | _ n  | S)aº  
    Create a new database connection.

    The connection parameters can be specified either as a string:

        conn = psycopg2.connect("dbname=test user=postgres password=secret")

    or using a set of keyword arguments:

        conn = psycopg2.connect(database="test", user="postgres", password="secret")

    The basic connection parameters are:

    - *dbname*: the database name (only in dsn string)
    - *database*: the database name (only as keyword argument)
    - *user*: user name used to authenticate
    - *password*: password used to authenticate
    - *host*: database host address (defaults to UNIX socket if not provided)
    - *port*: connection port number (defaults to 5432 if not provided)

    Using the *connection_factory* parameter a different class or connections
    factory can be specified. It should be a callable object taking a dsn
    argument.

    Using the *cursor_factory* parameter, a new default cursor factory will be
    used by cursor().

    Using *async*=True an asynchronous connection will be created.

    Any other keyword parameter will be passed to the underlying client
    library: the list of supported parameters depends on the library version.

    NZdbnameÚuserÚpasswordÚhostÚportc             S   s.   g  |  ]$ \ } } | d  k	 r | | f ‘ q S)Nr#   )Ú.0ÚkÚvr#   r#   r$   ú
<listcomp>–   s   	 zconnect.<locals>.<listcomp>z='%s' is an invalid keyword argument when the dsn is specifiedr   zmissing dsn and no parametersú c             S   s2   g  |  ]( \ } } d  | t  t | ƒ ƒ f ‘ q S)z%s=%s)r%   Ústr)r*   r+   r,   r#   r#   r$   r-   ¡   s   	Úconnection_factoryÚasync)ÚappendÚextendÚitemsÚ	TypeErrorÚjoinr   Úcursor_factory)ZdsnZdatabaser&   r'   r(   r)   r0   r7   r1   Úkwargsr4   Úconnr#   r#   r$   Úconnectf   s2    $ r:   )/Ú__doc__Zpsycopg2._psycopgr   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zpsycopg2r   Zpsycopg2.extensionsÚ
extensionsZ_extZregister_adapterÚtupleZSQL_INÚtypeZNoneAdapterÚdecimalr   ÚImportErrorZAdapterÚreÚcompiler%   r:   r#   r#   r#   r$   Ú<module>   s4    ("("