├── .gitignore ├── README.md ├── psycopg2-3.11 ├── psycopg2 │ ├── __init__.py │ ├── _ipaddress.py │ ├── _json.py │ ├── _psycopg.so │ ├── _range.py │ ├── errorcodes.py │ ├── errors.py │ ├── extensions.py │ ├── extras.py │ ├── pool.py │ ├── sql.py │ └── tz.py ├── psycopg2_binary-2.9.9.dist-info │ ├── INSTALLER │ ├── LICENSE │ ├── METADATA │ ├── RECORD │ ├── REQUESTED │ ├── WHEEL │ └── top_level.txt └── psycopg2_binary.libs │ ├── libcom_err-2abe824b.so.2.1 │ ├── libcrypto-75e66d43.so.1.1 │ ├── libgssapi_krb5-497db0c6.so.2.2 │ ├── libk5crypto-b1f99d5c.so.3.1 │ ├── libkeyutils-dfe70bd6.so.1.5 │ ├── libkrb5-fcafa220.so.3.3 │ ├── libkrb5support-d0bcff84.so.0.1 │ ├── liblber-a070ad53.so.2.0.200 │ ├── libldap-7a982b46.so.2.0.200 │ ├── libpcre-9513aab5.so.1.2.0 │ ├── libpq-e8a033dd.so.5.16 │ ├── libsasl2-883649fd.so.3.0.0 │ ├── libselinux-0922c95c.so.1 │ └── libssl-3e69114b.so.1.1 ├── psycopg2-3.6 ├── __init__.py ├── _ipaddress.py ├── _json.py ├── _psycopg.cpython-36m-x86_64-linux-gnu.so ├── _range.py ├── errorcodes.py ├── extensions.py ├── extras.py ├── pool.py ├── psycopg1.py ├── sql.py └── tz.py ├── psycopg2-3.7 ├── __init__.py ├── _ipaddress.py ├── _json.py ├── _lru_cache.py ├── _psycopg.cpython-37m-x86_64-linux-gnu.so ├── _range.py ├── compat.py ├── errorcodes.py ├── errors.py ├── extensions.py ├── extras.py ├── pool.py ├── psycopg1.py ├── sql.py └── tz.py ├── psycopg2-3.8 ├── __init__.py ├── _ipaddress.py ├── _json.py ├── _lru_cache.py ├── _psycopg.cpython-38-x86_64-linux-gnu.so ├── _range.py ├── compat.py ├── errorcodes.py ├── errors.py ├── extensions.py ├── extras.py ├── pool.py ├── sql.py └── tz.py ├── psycopg2-3.9 ├── __init__.py ├── _ipaddress.py ├── _json.py ├── _psycopg.cpython-39-x86_64-linux-gnu.so ├── _range.py ├── errorcodes.py ├── errors.py ├── extensions.py ├── extras.py ├── pool.py ├── sql.py └── tz.py ├── psycopg2 ├── __init__.py ├── _ipaddress.py ├── _json.py ├── _psycopg.so ├── _range.py ├── errorcodes.py ├── extensions.py ├── extras.py ├── pool.py ├── psycopg1.py ├── sql.py └── tz.py └── with_ssl_support ├── psycopg2-3.6 ├── __init__.py ├── _ipaddress.py ├── _json.py ├── _psycopg.cpython-36m-x86_64-linux-gnu.so ├── _range.py ├── errorcodes.py ├── extensions.py ├── extras.py ├── pool.py ├── psycopg1.py ├── sql.py └── tz.py ├── psycopg2-3.7 ├── __init__.py ├── _ipaddress.py ├── _json.py ├── _lru_cache.py ├── _psycopg.cpython-37m-x86_64-linux-gnu.so ├── _range.py ├── compat.py ├── errorcodes.py ├── errors.py ├── extensions.py ├── extras.py ├── pool.py ├── sql.py └── tz.py ├── psycopg2-3.8 ├── __init__.py ├── _ipaddress.py ├── _json.py ├── _lru_cache.py ├── _psycopg.cpython-38-x86_64-linux-gnu.so ├── _range.py ├── compat.py ├── errorcodes.py ├── errors.py ├── extensions.py ├── extras.py ├── pool.py ├── sql.py └── tz.py └── psycopg2 ├── __init__.py ├── _ipaddress.py ├── _json.py ├── _psycopg.so ├── _range.py ├── errorcodes.py ├── extensions.py ├── extras.py ├── pool.py ├── psycopg1.py ├── sql.py └── tz.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | psycopg2 Python Library for AWS Lambda 2 | ====================================== 3 | 4 | This is a custom compiled psycopg2 C library for Python. Due to AWS Lambda 5 | missing the required PostgreSQL libraries in the AMI image, we needed to 6 | compile psycopg2 with the PostgreSQL `libpq.so` library statically linked 7 | libpq library instead of the default dynamic link. 8 | 9 | ### How to use 10 | 11 | #### Python2.* 12 | Just copy the psycopg2 directory into your AWS Lambda zip package. 13 | 14 | #### Python 3.6 15 | Just copy the psycopg2-3.6 directory into your AWS Lambda project and rename it to psycopg2 before creating your AWS Lambda zip package. 16 | 17 | #### Python 3.11 18 | Just copy the content of psycopg2-3.11 directory into your AWS Lambda project before creating your AWS Lambda zip package. 19 | 20 | ### Instructions on compiling this package from scratch 21 | 22 | Here was the process that was used to build this package. You will need to 23 | perform these steps if you want to build a newer version of the psycopg2 24 | library. 25 | 26 | 1. Download the 27 | [PostgreSQL source code](https://ftp.postgresql.org/pub/source/v9.4.3/postgresql-9.4.3.tar.gz) and extract into a directory. 28 | 2. Download the 29 | [psycopg2 source code](http://initd.org/psycopg/tarballs/PSYCOPG-2-6/psycopg2-2.6.1.tar.gz) and extract into a directory. 30 | 3. Go into the PostgreSQL source directory and execute the following commands: 31 | - `./configure --prefix {path_to_postgresql_source} --without-readline --without-zlib` 32 | - `make` 33 | - `make install` 34 | 4. Go into the psycopg2 source directory and edit the `setup.cfg` file with the following: 35 | - `pg_config={path_to_postgresql_source/bin/pg_config}` 36 | - `static_libpq=1` 37 | 5. Execute `python setup.py build` in the psycopg2 source directory. 38 | 39 | After the above steps have been completed you will then have a build directory 40 | and the custom compiled psycopg2 library will be contained within it. Copy this 41 | directory into your AWS Lambda package and you will now be able to access 42 | PostgreSQL from within AWS Lambda using the psycopg2 library! 43 | 44 | #### Compiling with ssl support 45 | 46 | To compile with ssl support steps 3 and 4 above become. 47 | 48 | 3. Go into the PostgreSQL source directory and execute the following commands: 49 | - `./configure --prefix {path_to_postgresql_source} --without-readline --without-zlib --with-openssl` 50 | - `make` 51 | - `make install` 52 | 4. Go into the psycopg2 source directory and edit the `setup.cfg` file with the following: 53 | - `pg_config={path_to_postgresql_source/bin/pg_config}` 54 | - `static_libpq=1` 55 | - `libraries=ssl crypto` 56 | 57 | All other steps are identical. 58 | -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2/__init__.py: -------------------------------------------------------------------------------- 1 | """A Python driver for PostgreSQL 2 | 3 | psycopg is a PostgreSQL_ database adapter for the Python_ programming 4 | language. This is version 2, a complete rewrite of the original code to 5 | provide new-style classes for connection and cursor objects and other sweet 6 | candies. Like the original, psycopg 2 was written with the aim of being very 7 | small and fast, and stable as a rock. 8 | 9 | Homepage: https://psycopg.org/ 10 | 11 | .. _PostgreSQL: https://www.postgresql.org/ 12 | .. _Python: https://www.python.org/ 13 | 14 | :Groups: 15 | * `Connections creation`: connect 16 | * `Value objects constructors`: Binary, Date, DateFromTicks, Time, 17 | TimeFromTicks, Timestamp, TimestampFromTicks 18 | """ 19 | # psycopg/__init__.py - initialization of the psycopg module 20 | # 21 | # Copyright (C) 2003-2019 Federico Di Gregorio 22 | # Copyright (C) 2020-2021 The Psycopg Team 23 | # 24 | # psycopg2 is free software: you can redistribute it and/or modify it 25 | # under the terms of the GNU Lesser General Public License as published 26 | # by the Free Software Foundation, either version 3 of the License, or 27 | # (at your option) any later version. 28 | # 29 | # In addition, as a special exception, the copyright holders give 30 | # permission to link this program with the OpenSSL library (or with 31 | # modified versions of OpenSSL that use the same license as OpenSSL), 32 | # and distribute linked combinations including the two. 33 | # 34 | # You must obey the GNU Lesser General Public License in all respects for 35 | # all of the code used other than OpenSSL. 36 | # 37 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 38 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 39 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 40 | # License for more details. 41 | 42 | # Import modules needed by _psycopg to allow tools like py2exe to do 43 | # their work without bothering about the module dependencies. 44 | 45 | # Note: the first internal import should be _psycopg, otherwise the real cause 46 | # of a failed loading of the C module may get hidden, see 47 | # https://archives.postgresql.org/psycopg/2011-02/msg00044.php 48 | 49 | # Import the DBAPI-2.0 stuff into top-level module. 50 | 51 | from psycopg2._psycopg import ( # noqa 52 | BINARY, NUMBER, STRING, DATETIME, ROWID, 53 | 54 | Binary, Date, Time, Timestamp, 55 | DateFromTicks, TimeFromTicks, TimestampFromTicks, 56 | 57 | Error, Warning, DataError, DatabaseError, ProgrammingError, IntegrityError, 58 | InterfaceError, InternalError, NotSupportedError, OperationalError, 59 | 60 | _connect, apilevel, threadsafety, paramstyle, 61 | __version__, __libpq_version__, 62 | ) 63 | 64 | 65 | # Register default adapters. 66 | 67 | from psycopg2 import extensions as _ext 68 | _ext.register_adapter(tuple, _ext.SQL_IN) 69 | _ext.register_adapter(type(None), _ext.NoneAdapter) 70 | 71 | # Register the Decimal adapter here instead of in the C layer. 72 | # This way a new class is registered for each sub-interpreter. 73 | # See ticket #52 74 | from decimal import Decimal # noqa 75 | from psycopg2._psycopg import Decimal as Adapter # noqa 76 | _ext.register_adapter(Decimal, Adapter) 77 | del Decimal, Adapter 78 | 79 | 80 | def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs): 81 | """ 82 | Create a new database connection. 83 | 84 | The connection parameters can be specified as a string: 85 | 86 | conn = psycopg2.connect("dbname=test user=postgres password=secret") 87 | 88 | or using a set of keyword arguments: 89 | 90 | conn = psycopg2.connect(database="test", user="postgres", password="secret") 91 | 92 | Or as a mix of both. The basic connection parameters are: 93 | 94 | - *dbname*: the database name 95 | - *database*: the database name (only as keyword argument) 96 | - *user*: user name used to authenticate 97 | - *password*: password used to authenticate 98 | - *host*: database host address (defaults to UNIX socket if not provided) 99 | - *port*: connection port number (defaults to 5432 if not provided) 100 | 101 | Using the *connection_factory* parameter a different class or connections 102 | factory can be specified. It should be a callable object taking a dsn 103 | argument. 104 | 105 | Using the *cursor_factory* parameter, a new default cursor factory will be 106 | used by cursor(). 107 | 108 | Using *async*=True an asynchronous connection will be created. *async_* is 109 | a valid alias (for Python versions where ``async`` is a keyword). 110 | 111 | Any other keyword parameter will be passed to the underlying client 112 | library: the list of supported parameters depends on the library version. 113 | 114 | """ 115 | kwasync = {} 116 | if 'async' in kwargs: 117 | kwasync['async'] = kwargs.pop('async') 118 | if 'async_' in kwargs: 119 | kwasync['async_'] = kwargs.pop('async_') 120 | 121 | dsn = _ext.make_dsn(dsn, **kwargs) 122 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 123 | if cursor_factory is not None: 124 | conn.cursor_factory = cursor_factory 125 | 126 | return conn 127 | -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2/_ipaddress.py: -------------------------------------------------------------------------------- 1 | """Implementation of the ipaddres-based network types adaptation 2 | """ 3 | 4 | # psycopg/_ipaddress.py - Ipaddres-based network types adaptation 5 | # 6 | # Copyright (C) 2016-2019 Daniele Varrazzo 7 | # Copyright (C) 2020-2021 The Psycopg Team 8 | # 9 | # psycopg2 is free software: you can redistribute it and/or modify it 10 | # under the terms of the GNU Lesser General Public License as published 11 | # by the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # In addition, as a special exception, the copyright holders give 15 | # permission to link this program with the OpenSSL library (or with 16 | # modified versions of OpenSSL that use the same license as OpenSSL), 17 | # and distribute linked combinations including the two. 18 | # 19 | # You must obey the GNU Lesser General Public License in all respects for 20 | # all of the code used other than OpenSSL. 21 | # 22 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 23 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 25 | # License for more details. 26 | 27 | from psycopg2.extensions import ( 28 | new_type, new_array_type, register_type, register_adapter, QuotedString) 29 | 30 | # The module is imported on register_ipaddress 31 | ipaddress = None 32 | 33 | # The typecasters are created only once 34 | _casters = None 35 | 36 | 37 | def register_ipaddress(conn_or_curs=None): 38 | """ 39 | Register conversion support between `ipaddress` objects and `network types`__. 40 | 41 | :param conn_or_curs: the scope where to register the type casters. 42 | If `!None` register them globally. 43 | 44 | After the function is called, PostgreSQL :sql:`inet` values will be 45 | converted into `~ipaddress.IPv4Interface` or `~ipaddress.IPv6Interface` 46 | objects, :sql:`cidr` values into into `~ipaddress.IPv4Network` or 47 | `~ipaddress.IPv6Network`. 48 | 49 | .. __: https://www.postgresql.org/docs/current/static/datatype-net-types.html 50 | """ 51 | global ipaddress 52 | import ipaddress 53 | 54 | global _casters 55 | if _casters is None: 56 | _casters = _make_casters() 57 | 58 | for c in _casters: 59 | register_type(c, conn_or_curs) 60 | 61 | for t in [ipaddress.IPv4Interface, ipaddress.IPv6Interface, 62 | ipaddress.IPv4Network, ipaddress.IPv6Network]: 63 | register_adapter(t, adapt_ipaddress) 64 | 65 | 66 | def _make_casters(): 67 | inet = new_type((869,), 'INET', cast_interface) 68 | ainet = new_array_type((1041,), 'INET[]', inet) 69 | 70 | cidr = new_type((650,), 'CIDR', cast_network) 71 | acidr = new_array_type((651,), 'CIDR[]', cidr) 72 | 73 | return [inet, ainet, cidr, acidr] 74 | 75 | 76 | def cast_interface(s, cur=None): 77 | if s is None: 78 | return None 79 | # Py2 version force the use of unicode. meh. 80 | return ipaddress.ip_interface(str(s)) 81 | 82 | 83 | def cast_network(s, cur=None): 84 | if s is None: 85 | return None 86 | return ipaddress.ip_network(str(s)) 87 | 88 | 89 | def adapt_ipaddress(obj): 90 | return QuotedString(str(obj)) 91 | -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2/_psycopg.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2/_psycopg.so -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2/errors.py: -------------------------------------------------------------------------------- 1 | """Error classes for PostgreSQL error codes 2 | """ 3 | 4 | # psycopg/errors.py - SQLSTATE and DB-API exceptions 5 | # 6 | # Copyright (C) 2018-2019 Daniele Varrazzo 7 | # Copyright (C) 2020-2021 The Psycopg Team 8 | # 9 | # psycopg2 is free software: you can redistribute it and/or modify it 10 | # under the terms of the GNU Lesser General Public License as published 11 | # by the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # In addition, as a special exception, the copyright holders give 15 | # permission to link this program with the OpenSSL library (or with 16 | # modified versions of OpenSSL that use the same license as OpenSSL), 17 | # and distribute linked combinations including the two. 18 | # 19 | # You must obey the GNU Lesser General Public License in all respects for 20 | # all of the code used other than OpenSSL. 21 | # 22 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 23 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 25 | # License for more details. 26 | 27 | # 28 | # NOTE: the exceptions are injected into this module by the C extention. 29 | # 30 | 31 | 32 | def lookup(code): 33 | """Lookup an error code and return its exception class. 34 | 35 | Raise `!KeyError` if the code is not found. 36 | """ 37 | from psycopg2._psycopg import sqlstate_errors # avoid circular import 38 | return sqlstate_errors[code] 39 | -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2/tz.py: -------------------------------------------------------------------------------- 1 | """tzinfo implementations for psycopg2 2 | 3 | This module holds two different tzinfo implementations that can be used as 4 | the 'tzinfo' argument to datetime constructors, directly passed to psycopg 5 | functions or used to set the .tzinfo_factory attribute in cursors. 6 | """ 7 | # psycopg/tz.py - tzinfo implementation 8 | # 9 | # Copyright (C) 2003-2019 Federico Di Gregorio 10 | # Copyright (C) 2020-2021 The Psycopg Team 11 | # 12 | # psycopg2 is free software: you can redistribute it and/or modify it 13 | # under the terms of the GNU Lesser General Public License as published 14 | # by the Free Software Foundation, either version 3 of the License, or 15 | # (at your option) any later version. 16 | # 17 | # In addition, as a special exception, the copyright holders give 18 | # permission to link this program with the OpenSSL library (or with 19 | # modified versions of OpenSSL that use the same license as OpenSSL), 20 | # and distribute linked combinations including the two. 21 | # 22 | # You must obey the GNU Lesser General Public License in all respects for 23 | # all of the code used other than OpenSSL. 24 | # 25 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 26 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 27 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 28 | # License for more details. 29 | 30 | import datetime 31 | import time 32 | 33 | ZERO = datetime.timedelta(0) 34 | 35 | 36 | class FixedOffsetTimezone(datetime.tzinfo): 37 | """Fixed offset in minutes east from UTC. 38 | 39 | This is exactly the implementation__ found in Python 2.3.x documentation, 40 | with a small change to the `!__init__()` method to allow for pickling 41 | and a default name in the form ``sHH:MM`` (``s`` is the sign.). 42 | 43 | The implementation also caches instances. During creation, if a 44 | FixedOffsetTimezone instance has previously been created with the same 45 | offset and name that instance will be returned. This saves memory and 46 | improves comparability. 47 | 48 | .. versionchanged:: 2.9 49 | 50 | The constructor can take either a timedelta or a number of minutes of 51 | offset. Previously only minutes were supported. 52 | 53 | .. __: https://docs.python.org/library/datetime.html 54 | """ 55 | _name = None 56 | _offset = ZERO 57 | 58 | _cache = {} 59 | 60 | def __init__(self, offset=None, name=None): 61 | if offset is not None: 62 | if not isinstance(offset, datetime.timedelta): 63 | offset = datetime.timedelta(minutes=offset) 64 | self._offset = offset 65 | if name is not None: 66 | self._name = name 67 | 68 | def __new__(cls, offset=None, name=None): 69 | """Return a suitable instance created earlier if it exists 70 | """ 71 | key = (offset, name) 72 | try: 73 | return cls._cache[key] 74 | except KeyError: 75 | tz = super().__new__(cls, offset, name) 76 | cls._cache[key] = tz 77 | return tz 78 | 79 | def __repr__(self): 80 | return "psycopg2.tz.FixedOffsetTimezone(offset=%r, name=%r)" \ 81 | % (self._offset, self._name) 82 | 83 | def __eq__(self, other): 84 | if isinstance(other, FixedOffsetTimezone): 85 | return self._offset == other._offset 86 | else: 87 | return NotImplemented 88 | 89 | def __ne__(self, other): 90 | if isinstance(other, FixedOffsetTimezone): 91 | return self._offset != other._offset 92 | else: 93 | return NotImplemented 94 | 95 | def __getinitargs__(self): 96 | return self._offset, self._name 97 | 98 | def utcoffset(self, dt): 99 | return self._offset 100 | 101 | def tzname(self, dt): 102 | if self._name is not None: 103 | return self._name 104 | 105 | minutes, seconds = divmod(self._offset.total_seconds(), 60) 106 | hours, minutes = divmod(minutes, 60) 107 | rv = "%+03d" % hours 108 | if minutes or seconds: 109 | rv += ":%02d" % minutes 110 | if seconds: 111 | rv += ":%02d" % seconds 112 | 113 | return rv 114 | 115 | def dst(self, dt): 116 | return ZERO 117 | 118 | 119 | STDOFFSET = datetime.timedelta(seconds=-time.timezone) 120 | if time.daylight: 121 | DSTOFFSET = datetime.timedelta(seconds=-time.altzone) 122 | else: 123 | DSTOFFSET = STDOFFSET 124 | DSTDIFF = DSTOFFSET - STDOFFSET 125 | 126 | 127 | class LocalTimezone(datetime.tzinfo): 128 | """Platform idea of local timezone. 129 | 130 | This is the exact implementation from the Python 2.3 documentation. 131 | """ 132 | def utcoffset(self, dt): 133 | if self._isdst(dt): 134 | return DSTOFFSET 135 | else: 136 | return STDOFFSET 137 | 138 | def dst(self, dt): 139 | if self._isdst(dt): 140 | return DSTDIFF 141 | else: 142 | return ZERO 143 | 144 | def tzname(self, dt): 145 | return time.tzname[self._isdst(dt)] 146 | 147 | def _isdst(self, dt): 148 | tt = (dt.year, dt.month, dt.day, 149 | dt.hour, dt.minute, dt.second, 150 | dt.weekday(), 0, -1) 151 | stamp = time.mktime(tt) 152 | tt = time.localtime(stamp) 153 | return tt.tm_isdst > 0 154 | 155 | 156 | LOCAL = LocalTimezone() 157 | 158 | # TODO: pre-generate some interesting time zones? 159 | -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary-2.9.9.dist-info/INSTALLER: -------------------------------------------------------------------------------- 1 | pip 2 | -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary-2.9.9.dist-info/LICENSE: -------------------------------------------------------------------------------- 1 | psycopg2 and the LGPL 2 | --------------------- 3 | 4 | psycopg2 is free software: you can redistribute it and/or modify it 5 | under the terms of the GNU Lesser General Public License as published 6 | by the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | psycopg2 is distributed in the hope that it will be useful, but WITHOUT 10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 12 | License for more details. 13 | 14 | In addition, as a special exception, the copyright holders give 15 | permission to link this program with the OpenSSL library (or with 16 | modified versions of OpenSSL that use the same license as OpenSSL), 17 | and distribute linked combinations including the two. 18 | 19 | You must obey the GNU Lesser General Public License in all respects for 20 | all of the code used other than OpenSSL. If you modify file(s) with this 21 | exception, you may extend this exception to your version of the file(s), 22 | but you are not obligated to do so. If you do not wish to do so, delete 23 | this exception statement from your version. If you delete this exception 24 | statement from all source files in the program, then also delete it here. 25 | 26 | You should have received a copy of the GNU Lesser General Public License 27 | along with psycopg2 (see the doc/ directory.) 28 | If not, see . 29 | 30 | 31 | Alternative licenses 32 | -------------------- 33 | 34 | The following BSD-like license applies (at your option) to the files following 35 | the pattern ``psycopg/adapter*.{h,c}`` and ``psycopg/microprotocol*.{h,c}``: 36 | 37 | Permission is granted to anyone to use this software for any purpose, 38 | including commercial applications, and to alter it and redistribute it 39 | freely, subject to the following restrictions: 40 | 41 | 1. The origin of this software must not be misrepresented; you must not 42 | claim that you wrote the original software. If you use this 43 | software in a product, an acknowledgment in the product documentation 44 | would be appreciated but is not required. 45 | 46 | 2. Altered source versions must be plainly marked as such, and must not 47 | be misrepresented as being the original software. 48 | 49 | 3. This notice may not be removed or altered from any source distribution. 50 | -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary-2.9.9.dist-info/METADATA: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: psycopg2-binary 3 | Version: 2.9.9 4 | Summary: psycopg2 - Python-PostgreSQL Database Adapter 5 | Home-page: https://psycopg.org/ 6 | Author: Federico Di Gregorio 7 | Author-email: fog@initd.org 8 | Maintainer: Daniele Varrazzo 9 | Maintainer-email: daniele.varrazzo@gmail.com 10 | License: LGPL with exceptions 11 | Project-URL: Homepage, https://psycopg.org/ 12 | Project-URL: Documentation, https://www.psycopg.org/docs/ 13 | Project-URL: Code, https://github.com/psycopg/psycopg2 14 | Project-URL: Issue Tracker, https://github.com/psycopg/psycopg2/issues 15 | Project-URL: Download, https://pypi.org/project/psycopg2/ 16 | Platform: any 17 | Classifier: Development Status :: 5 - Production/Stable 18 | Classifier: Intended Audience :: Developers 19 | Classifier: License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL) 20 | Classifier: Programming Language :: Python 21 | Classifier: Programming Language :: Python :: 3 22 | Classifier: Programming Language :: Python :: 3.7 23 | Classifier: Programming Language :: Python :: 3.8 24 | Classifier: Programming Language :: Python :: 3.9 25 | Classifier: Programming Language :: Python :: 3.10 26 | Classifier: Programming Language :: Python :: 3.11 27 | Classifier: Programming Language :: Python :: 3.12 28 | Classifier: Programming Language :: Python :: 3 :: Only 29 | Classifier: Programming Language :: Python :: Implementation :: CPython 30 | Classifier: Programming Language :: C 31 | Classifier: Programming Language :: SQL 32 | Classifier: Topic :: Database 33 | Classifier: Topic :: Database :: Front-Ends 34 | Classifier: Topic :: Software Development 35 | Classifier: Topic :: Software Development :: Libraries :: Python Modules 36 | Classifier: Operating System :: Microsoft :: Windows 37 | Classifier: Operating System :: Unix 38 | Requires-Python: >=3.7 39 | License-File: LICENSE 40 | 41 | Psycopg is the most popular PostgreSQL database adapter for the Python 42 | programming language. Its main features are the complete implementation of 43 | the Python DB API 2.0 specification and the thread safety (several threads can 44 | share the same connection). It was designed for heavily multi-threaded 45 | applications that create and destroy lots of cursors and make a large number 46 | of concurrent "INSERT"s or "UPDATE"s. 47 | 48 | Psycopg 2 is mostly implemented in C as a libpq wrapper, resulting in being 49 | both efficient and secure. It features client-side and server-side cursors, 50 | asynchronous communication and notifications, "COPY TO/COPY FROM" support. 51 | Many Python types are supported out-of-the-box and adapted to matching 52 | PostgreSQL data types; adaptation can be extended and customized thanks to a 53 | flexible objects adaptation system. 54 | 55 | Psycopg 2 is both Unicode and Python 3 friendly. 56 | 57 | 58 | Documentation 59 | ------------- 60 | 61 | Documentation is included in the ``doc`` directory and is `available online`__. 62 | 63 | .. __: https://www.psycopg.org/docs/ 64 | 65 | For any other resource (source code repository, bug tracker, mailing list) 66 | please check the `project homepage`__. 67 | 68 | .. __: https://psycopg.org/ 69 | 70 | 71 | Installation 72 | ------------ 73 | 74 | Building Psycopg requires a few prerequisites (a C compiler, some development 75 | packages): please check the install_ and the faq_ documents in the ``doc`` dir 76 | or online for the details. 77 | 78 | If prerequisites are met, you can install psycopg like any other Python 79 | package, using ``pip`` to download it from PyPI_:: 80 | 81 | $ pip install psycopg2 82 | 83 | or using ``setup.py`` if you have downloaded the source package locally:: 84 | 85 | $ python setup.py build 86 | $ sudo python setup.py install 87 | 88 | You can also obtain a stand-alone package, not requiring a compiler or 89 | external libraries, by installing the `psycopg2-binary`_ package from PyPI:: 90 | 91 | $ pip install psycopg2-binary 92 | 93 | The binary package is a practical choice for development and testing but in 94 | production it is advised to use the package built from sources. 95 | 96 | .. _PyPI: https://pypi.org/project/psycopg2/ 97 | .. _psycopg2-binary: https://pypi.org/project/psycopg2-binary/ 98 | .. _install: https://www.psycopg.org/docs/install.html#install-from-source 99 | .. _faq: https://www.psycopg.org/docs/faq.html#faq-compile 100 | 101 | :Linux/OSX: |gh-actions| 102 | :Windows: |appveyor| 103 | 104 | .. |gh-actions| image:: https://github.com/psycopg/psycopg2/actions/workflows/tests.yml/badge.svg 105 | :target: https://github.com/psycopg/psycopg2/actions/workflows/tests.yml 106 | :alt: Linux and OSX build status 107 | 108 | .. |appveyor| image:: https://ci.appveyor.com/api/projects/status/github/psycopg/psycopg2?branch=master&svg=true 109 | :target: https://ci.appveyor.com/project/psycopg/psycopg2/branch/master 110 | :alt: Windows build status 111 | -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary-2.9.9.dist-info/RECORD: -------------------------------------------------------------------------------- 1 | psycopg2/__init__.py,sha256=9mo5Qd0uWHiEBx2CdogGos2kNqtlNNGzbtYlGC0hWS8,4768 2 | psycopg2/__pycache__/__init__.cpython-39.pyc,, 3 | psycopg2/__pycache__/_ipaddress.cpython-39.pyc,, 4 | psycopg2/__pycache__/_json.cpython-39.pyc,, 5 | psycopg2/__pycache__/_range.cpython-39.pyc,, 6 | psycopg2/__pycache__/errorcodes.cpython-39.pyc,, 7 | psycopg2/__pycache__/errors.cpython-39.pyc,, 8 | psycopg2/__pycache__/extensions.cpython-39.pyc,, 9 | psycopg2/__pycache__/extras.cpython-39.pyc,, 10 | psycopg2/__pycache__/pool.cpython-39.pyc,, 11 | psycopg2/__pycache__/sql.cpython-39.pyc,, 12 | psycopg2/__pycache__/tz.cpython-39.pyc,, 13 | psycopg2/_ipaddress.py,sha256=jkuyhLgqUGRBcLNWDM8QJysV6q1Npc_RYH4_kE7JZPU,2922 14 | psycopg2/_json.py,sha256=XPn4PnzbTg1Dcqz7n1JMv5dKhB5VFV6834GEtxSawt0,7153 15 | psycopg2/_psycopg.cpython-39-x86_64-linux-gnu.so,sha256=yvBbtMCaRhORSnJ64BUsz_7ylzWH-J4x7H-eY27r0gk,335065 16 | psycopg2/_range.py,sha256=sXeenGraJEEw2I3mc8RlmNivy2jMg7zWoanDes2Ywp8,18494 17 | psycopg2/errorcodes.py,sha256=jb1SkuGq5zJT7F99GFAUi3VQH8GbsB7zRHiLsAWAU0Q,14362 18 | psycopg2/errors.py,sha256=aAS4dJyTg1bsDzJDCRQAMB_s7zv-Q4yB6Yvih26I-0M,1425 19 | psycopg2/extensions.py,sha256=CG0kG5vL8Ot503UGlDXXJJFdFWLg4HE2_c1-lLOLc8M,6797 20 | psycopg2/extras.py,sha256=oBfrdvtWn8ITxc3x-h2h6IwHUsWdVqCdf4Gphb0JqY8,44215 21 | psycopg2/pool.py,sha256=UGEt8IdP3xNc2PGYNlG4sQvg8nhf4aeCnz39hTR0H8I,6316 22 | psycopg2/sql.py,sha256=OcFEAmpe2aMfrx0MEk4Lx00XvXXJCmvllaOVbJY-yoE,14779 23 | psycopg2/tz.py,sha256=r95kK7eGSpOYr_luCyYsznHMzjl52sLjsnSPXkXLzRI,4870 24 | psycopg2_binary-2.9.9.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4 25 | psycopg2_binary-2.9.9.dist-info/LICENSE,sha256=lhS4XfyacsWyyjMUTB1-HtOxwpdFnZ-yimpXYsLo1xs,2238 26 | psycopg2_binary-2.9.9.dist-info/METADATA,sha256=vkxMt-2J7iReUtyq2SN4AY4BrHDgiz8csUjacUUYWVk,4445 27 | psycopg2_binary-2.9.9.dist-info/RECORD,, 28 | psycopg2_binary-2.9.9.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0 29 | psycopg2_binary-2.9.9.dist-info/WHEEL,sha256=_BMdtp3IQ4NF7VFMKD4lD9Cik0H3WhEP1vtG22VwXhU,148 30 | psycopg2_binary-2.9.9.dist-info/top_level.txt,sha256=7dHGpLqQ3w-vGmGEVn-7uK90qU9fyrGdWWi7S-gTcnM,9 31 | psycopg2_binary.libs/libcom_err-2abe824b.so.2.1,sha256=VCbctU3QHJ7t2gXiF58ORxFOi0ilNP_p6UkW55Rxslc,17497 32 | psycopg2_binary.libs/libcrypto-75e66d43.so.1.1,sha256=YcAu8Al5-4Nybeplw217P639-WiAuUuRFXHMxEHRFrY,3133185 33 | psycopg2_binary.libs/libgssapi_krb5-497db0c6.so.2.2,sha256=KnSwMw7pcygbJvjr5KzvDr-e6ZxraEl8-RUf_2xMNOE,345209 34 | psycopg2_binary.libs/libk5crypto-b1f99d5c.so.3.1,sha256=mETlAJ5wpq0vsitYcwaBD-Knsbn2uZItqhx4ujRm3ic,219953 35 | psycopg2_binary.libs/libkeyutils-dfe70bd6.so.1.5,sha256=wp5BsDz0st_7-0lglG4rQvgsDKXVPSMdPw_Fl7onRIg,17913 36 | psycopg2_binary.libs/libkrb5-fcafa220.so.3.3,sha256=sqq1KP9MqyFE5c4BskasCfV0oHKlP_Y-qB1rspsmuPE,1018953 37 | psycopg2_binary.libs/libkrb5support-d0bcff84.so.0.1,sha256=anH1fXSP73m05zbVNIh1VF0KIk-okotdYqPPJkf8EJ8,76873 38 | psycopg2_binary.libs/liblber-a070ad53.so.2.0.200,sha256=r3cz9xghDA9SqeluB6fU8jRWaYcbr-VzABYFt2RsLzg,60977 39 | psycopg2_binary.libs/libldap-7a982b46.so.2.0.200,sha256=CBJ1VucxNVSbKylS8WgpeJWrZ36vnH5svj5bdQfaDZo,447329 40 | psycopg2_binary.libs/libpcre-9513aab5.so.1.2.0,sha256=Au2oUOBJMWVtivgfUXG_902L7BVT09hcPTLX_F7-iGQ,406817 41 | psycopg2_binary.libs/libpq-e8a033dd.so.5.16,sha256=Cev0iQNwOIdZPNACM7290RDd_YsHbDPEegS95fowR0w,370777 42 | psycopg2_binary.libs/libsasl2-883649fd.so.3.0.0,sha256=GC8C1eR02yJ82oOrrHQT1DHUh8bAGv0M10HhQM7cDzo,119217 43 | psycopg2_binary.libs/libselinux-0922c95c.so.1,sha256=1PqOf7Ot2WCmgyWlnJaUJErqMhP9c5pQgVywZ8SWVlQ,178337 44 | psycopg2_binary.libs/libssl-3e69114b.so.1.1,sha256=-nyde6hPV_6WXwrqdPTrTdViOI0jQ3EGD0BAg0RRRio,646065 45 | -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary-2.9.9.dist-info/REQUESTED: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2_binary-2.9.9.dist-info/REQUESTED -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary-2.9.9.dist-info/WHEEL: -------------------------------------------------------------------------------- 1 | Wheel-Version: 1.0 2 | Generator: bdist_wheel (0.41.2) 3 | Root-Is-Purelib: false 4 | Tag: cp39-cp39-manylinux_2_17_x86_64 5 | Tag: cp39-cp39-manylinux2014_x86_64 6 | 7 | -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary-2.9.9.dist-info/top_level.txt: -------------------------------------------------------------------------------- 1 | psycopg2 2 | -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary.libs/libcom_err-2abe824b.so.2.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2_binary.libs/libcom_err-2abe824b.so.2.1 -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary.libs/libcrypto-75e66d43.so.1.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2_binary.libs/libcrypto-75e66d43.so.1.1 -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary.libs/libgssapi_krb5-497db0c6.so.2.2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2_binary.libs/libgssapi_krb5-497db0c6.so.2.2 -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary.libs/libk5crypto-b1f99d5c.so.3.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2_binary.libs/libk5crypto-b1f99d5c.so.3.1 -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary.libs/libkeyutils-dfe70bd6.so.1.5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2_binary.libs/libkeyutils-dfe70bd6.so.1.5 -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary.libs/libkrb5-fcafa220.so.3.3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2_binary.libs/libkrb5-fcafa220.so.3.3 -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary.libs/libkrb5support-d0bcff84.so.0.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2_binary.libs/libkrb5support-d0bcff84.so.0.1 -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary.libs/liblber-a070ad53.so.2.0.200: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2_binary.libs/liblber-a070ad53.so.2.0.200 -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary.libs/libldap-7a982b46.so.2.0.200: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2_binary.libs/libldap-7a982b46.so.2.0.200 -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary.libs/libpcre-9513aab5.so.1.2.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2_binary.libs/libpcre-9513aab5.so.1.2.0 -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary.libs/libpq-e8a033dd.so.5.16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2_binary.libs/libpq-e8a033dd.so.5.16 -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary.libs/libsasl2-883649fd.so.3.0.0: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2_binary.libs/libsasl2-883649fd.so.3.0.0 -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary.libs/libselinux-0922c95c.so.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2_binary.libs/libselinux-0922c95c.so.1 -------------------------------------------------------------------------------- /psycopg2-3.11/psycopg2_binary.libs/libssl-3e69114b.so.1.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.11/psycopg2_binary.libs/libssl-3e69114b.so.1.1 -------------------------------------------------------------------------------- /psycopg2-3.6/__init__.py: -------------------------------------------------------------------------------- 1 | """A Python driver for PostgreSQL 2 | 3 | psycopg is a PostgreSQL_ database adapter for the Python_ programming 4 | language. This is version 2, a complete rewrite of the original code to 5 | provide new-style classes for connection and cursor objects and other sweet 6 | candies. Like the original, psycopg 2 was written with the aim of being very 7 | small and fast, and stable as a rock. 8 | 9 | Homepage: http://initd.org/projects/psycopg2 10 | 11 | .. _PostgreSQL: http://www.postgresql.org/ 12 | .. _Python: http://www.python.org/ 13 | 14 | :Groups: 15 | * `Connections creation`: connect 16 | * `Value objects constructors`: Binary, Date, DateFromTicks, Time, 17 | TimeFromTicks, Timestamp, TimestampFromTicks 18 | """ 19 | # psycopg/__init__.py - initialization of the psycopg module 20 | # 21 | # Copyright (C) 2003-2010 Federico Di Gregorio 22 | # 23 | # psycopg2 is free software: you can redistribute it and/or modify it 24 | # under the terms of the GNU Lesser General Public License as published 25 | # by the Free Software Foundation, either version 3 of the License, or 26 | # (at your option) any later version. 27 | # 28 | # In addition, as a special exception, the copyright holders give 29 | # permission to link this program with the OpenSSL library (or with 30 | # modified versions of OpenSSL that use the same license as OpenSSL), 31 | # and distribute linked combinations including the two. 32 | # 33 | # You must obey the GNU Lesser General Public License in all respects for 34 | # all of the code used other than OpenSSL. 35 | # 36 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 37 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 38 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 39 | # License for more details. 40 | 41 | # Import modules needed by _psycopg to allow tools like py2exe to do 42 | # their work without bothering about the module dependencies. 43 | 44 | # Note: the first internal import should be _psycopg, otherwise the real cause 45 | # of a failed loading of the C module may get hidden, see 46 | # http://archives.postgresql.org/psycopg/2011-02/msg00044.php 47 | 48 | # Import the DBAPI-2.0 stuff into top-level module. 49 | 50 | from psycopg2._psycopg import ( # noqa 51 | BINARY, NUMBER, STRING, DATETIME, ROWID, 52 | 53 | Binary, Date, Time, Timestamp, 54 | DateFromTicks, TimeFromTicks, TimestampFromTicks, 55 | 56 | Error, Warning, DataError, DatabaseError, ProgrammingError, IntegrityError, 57 | InterfaceError, InternalError, NotSupportedError, OperationalError, 58 | 59 | _connect, apilevel, threadsafety, paramstyle, 60 | __version__, __libpq_version__, 61 | ) 62 | 63 | from psycopg2 import tz # noqa 64 | 65 | 66 | # Register default adapters. 67 | 68 | import psycopg2.extensions as _ext 69 | _ext.register_adapter(tuple, _ext.SQL_IN) 70 | _ext.register_adapter(type(None), _ext.NoneAdapter) 71 | 72 | # Register the Decimal adapter here instead of in the C layer. 73 | # This way a new class is registered for each sub-interpreter. 74 | # See ticket #52 75 | try: 76 | from decimal import Decimal 77 | except ImportError: 78 | pass 79 | else: 80 | from psycopg2._psycopg import Decimal as Adapter 81 | _ext.register_adapter(Decimal, Adapter) 82 | del Decimal, Adapter 83 | 84 | 85 | def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs): 86 | """ 87 | Create a new database connection. 88 | 89 | The connection parameters can be specified as a string: 90 | 91 | conn = psycopg2.connect("dbname=test user=postgres password=secret") 92 | 93 | or using a set of keyword arguments: 94 | 95 | conn = psycopg2.connect(database="test", user="postgres", password="secret") 96 | 97 | Or as a mix of both. The basic connection parameters are: 98 | 99 | - *dbname*: the database name 100 | - *database*: the database name (only as keyword argument) 101 | - *user*: user name used to authenticate 102 | - *password*: password used to authenticate 103 | - *host*: database host address (defaults to UNIX socket if not provided) 104 | - *port*: connection port number (defaults to 5432 if not provided) 105 | 106 | Using the *connection_factory* parameter a different class or connections 107 | factory can be specified. It should be a callable object taking a dsn 108 | argument. 109 | 110 | Using the *cursor_factory* parameter, a new default cursor factory will be 111 | used by cursor(). 112 | 113 | Using *async*=True an asynchronous connection will be created. *async_* is 114 | a valid alias (for Python versions where ``async`` is a keyword). 115 | 116 | Any other keyword parameter will be passed to the underlying client 117 | library: the list of supported parameters depends on the library version. 118 | 119 | """ 120 | kwasync = {} 121 | if 'async' in kwargs: 122 | kwasync['async'] = kwargs.pop('async') 123 | if 'async_' in kwargs: 124 | kwasync['async_'] = kwargs.pop('async_') 125 | 126 | if dsn is None and not kwargs: 127 | raise TypeError('missing dsn and no parameters') 128 | 129 | dsn = _ext.make_dsn(dsn, **kwargs) 130 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 131 | if cursor_factory is not None: 132 | conn.cursor_factory = cursor_factory 133 | 134 | return conn 135 | -------------------------------------------------------------------------------- /psycopg2-3.6/_ipaddress.py: -------------------------------------------------------------------------------- 1 | """Implementation of the ipaddres-based network types adaptation 2 | """ 3 | 4 | # psycopg/_ipaddress.py - Ipaddres-based network types adaptation 5 | # 6 | # Copyright (C) 2016 Daniele Varrazzo 7 | # 8 | # psycopg2 is free software: you can redistribute it and/or modify it 9 | # under the terms of the GNU Lesser General Public License as published 10 | # by the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # In addition, as a special exception, the copyright holders give 14 | # permission to link this program with the OpenSSL library (or with 15 | # modified versions of OpenSSL that use the same license as OpenSSL), 16 | # and distribute linked combinations including the two. 17 | # 18 | # You must obey the GNU Lesser General Public License in all respects for 19 | # all of the code used other than OpenSSL. 20 | # 21 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 22 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 24 | # License for more details. 25 | 26 | from psycopg2.extensions import ( 27 | new_type, new_array_type, register_type, register_adapter, QuotedString) 28 | 29 | # The module is imported on register_ipaddress 30 | ipaddress = None 31 | 32 | # The typecasters are created only once 33 | _casters = None 34 | 35 | 36 | def register_ipaddress(conn_or_curs=None): 37 | """ 38 | Register conversion support between `ipaddress` objects and `network types`__. 39 | 40 | :param conn_or_curs: the scope where to register the type casters. 41 | If `!None` register them globally. 42 | 43 | After the function is called, PostgreSQL :sql:`inet` values will be 44 | converted into `~ipaddress.IPv4Interface` or `~ipaddress.IPv6Interface` 45 | objects, :sql:`cidr` values into into `~ipaddress.IPv4Network` or 46 | `~ipaddress.IPv6Network`. 47 | 48 | .. __: https://www.postgresql.org/docs/current/static/datatype-net-types.html 49 | """ 50 | global ipaddress 51 | import ipaddress 52 | 53 | global _casters 54 | if _casters is None: 55 | _casters = _make_casters() 56 | 57 | for c in _casters: 58 | register_type(c, conn_or_curs) 59 | 60 | for t in [ipaddress.IPv4Interface, ipaddress.IPv6Interface, 61 | ipaddress.IPv4Network, ipaddress.IPv6Network]: 62 | register_adapter(t, adapt_ipaddress) 63 | 64 | 65 | def _make_casters(): 66 | inet = new_type((869,), 'INET', cast_interface) 67 | ainet = new_array_type((1041,), 'INET[]', inet) 68 | 69 | cidr = new_type((650,), 'CIDR', cast_network) 70 | acidr = new_array_type((651,), 'CIDR[]', cidr) 71 | 72 | return [inet, ainet, cidr, acidr] 73 | 74 | 75 | def cast_interface(s, cur=None): 76 | if s is None: 77 | return None 78 | # Py2 version force the use of unicode. meh. 79 | return ipaddress.ip_interface(str(s)) 80 | 81 | 82 | def cast_network(s, cur=None): 83 | if s is None: 84 | return None 85 | return ipaddress.ip_network(str(s)) 86 | 87 | 88 | def adapt_ipaddress(obj): 89 | return QuotedString(str(obj)) 90 | -------------------------------------------------------------------------------- /psycopg2-3.6/_psycopg.cpython-36m-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.6/_psycopg.cpython-36m-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /psycopg2-3.6/psycopg1.py: -------------------------------------------------------------------------------- 1 | """psycopg 1.1.x compatibility module 2 | 3 | This module uses the new style connection and cursor types to build a psycopg 4 | 1.1.1.x compatibility layer. It should be considered a temporary hack to run 5 | old code while porting to psycopg 2. Import it as follows:: 6 | 7 | from psycopg2 import psycopg1 as psycopg 8 | """ 9 | # psycopg/psycopg1.py - psycopg 1.1.x compatibility module 10 | # 11 | # Copyright (C) 2003-2010 Federico Di Gregorio 12 | # 13 | # psycopg2 is free software: you can redistribute it and/or modify it 14 | # under the terms of the GNU Lesser General Public License as published 15 | # by the Free Software Foundation, either version 3 of the License, or 16 | # (at your option) any later version. 17 | # 18 | # In addition, as a special exception, the copyright holders give 19 | # permission to link this program with the OpenSSL library (or with 20 | # modified versions of OpenSSL that use the same license as OpenSSL), 21 | # and distribute linked combinations including the two. 22 | # 23 | # You must obey the GNU Lesser General Public License in all respects for 24 | # all of the code used other than OpenSSL. 25 | # 26 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 27 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 28 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 29 | # License for more details. 30 | 31 | import psycopg2._psycopg as _2psycopg # noqa 32 | from psycopg2.extensions import cursor as _2cursor 33 | from psycopg2.extensions import connection as _2connection 34 | 35 | from psycopg2 import * # noqa 36 | import psycopg2.extensions as _ext 37 | _2connect = connect 38 | 39 | 40 | def connect(*args, **kwargs): 41 | """connect(dsn, ...) -> new psycopg 1.1.x compatible connection object""" 42 | kwargs['connection_factory'] = connection 43 | conn = _2connect(*args, **kwargs) 44 | conn.set_isolation_level(_ext.ISOLATION_LEVEL_READ_COMMITTED) 45 | return conn 46 | 47 | 48 | class connection(_2connection): 49 | """psycopg 1.1.x connection.""" 50 | 51 | def cursor(self): 52 | """cursor() -> new psycopg 1.1.x compatible cursor object""" 53 | return _2connection.cursor(self, cursor_factory=cursor) 54 | 55 | def autocommit(self, on_off=1): 56 | """autocommit(on_off=1) -> switch autocommit on (1) or off (0)""" 57 | if on_off > 0: 58 | self.set_isolation_level(_ext.ISOLATION_LEVEL_AUTOCOMMIT) 59 | else: 60 | self.set_isolation_level(_ext.ISOLATION_LEVEL_READ_COMMITTED) 61 | 62 | 63 | class cursor(_2cursor): 64 | """psycopg 1.1.x cursor. 65 | 66 | Note that this cursor implements the exact procedure used by psycopg 1 to 67 | build dictionaries out of result rows. The DictCursor in the 68 | psycopg.extras modules implements a much better and faster algorithm. 69 | """ 70 | 71 | def __build_dict(self, row): 72 | res = {} 73 | for i in range(len(self.description)): 74 | res[self.description[i][0]] = row[i] 75 | return res 76 | 77 | def dictfetchone(self): 78 | row = _2cursor.fetchone(self) 79 | if row: 80 | return self.__build_dict(row) 81 | else: 82 | return row 83 | 84 | def dictfetchmany(self, size): 85 | res = [] 86 | rows = _2cursor.fetchmany(self, size) 87 | for row in rows: 88 | res.append(self.__build_dict(row)) 89 | return res 90 | 91 | def dictfetchall(self): 92 | res = [] 93 | rows = _2cursor.fetchall(self) 94 | for row in rows: 95 | res.append(self.__build_dict(row)) 96 | return res 97 | -------------------------------------------------------------------------------- /psycopg2-3.6/tz.py: -------------------------------------------------------------------------------- 1 | """tzinfo implementations for psycopg2 2 | 3 | This module holds two different tzinfo implementations that can be used as 4 | the 'tzinfo' argument to datetime constructors, directly passed to psycopg 5 | functions or used to set the .tzinfo_factory attribute in cursors. 6 | """ 7 | # psycopg/tz.py - tzinfo implementation 8 | # 9 | # Copyright (C) 2003-2010 Federico Di Gregorio 10 | # 11 | # psycopg2 is free software: you can redistribute it and/or modify it 12 | # under the terms of the GNU Lesser General Public License as published 13 | # by the Free Software Foundation, either version 3 of the License, or 14 | # (at your option) any later version. 15 | # 16 | # In addition, as a special exception, the copyright holders give 17 | # permission to link this program with the OpenSSL library (or with 18 | # modified versions of OpenSSL that use the same license as OpenSSL), 19 | # and distribute linked combinations including the two. 20 | # 21 | # You must obey the GNU Lesser General Public License in all respects for 22 | # all of the code used other than OpenSSL. 23 | # 24 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 25 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 26 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 27 | # License for more details. 28 | 29 | import datetime 30 | import time 31 | 32 | ZERO = datetime.timedelta(0) 33 | 34 | 35 | class FixedOffsetTimezone(datetime.tzinfo): 36 | """Fixed offset in minutes east from UTC. 37 | 38 | This is exactly the implementation__ found in Python 2.3.x documentation, 39 | with a small change to the `!__init__()` method to allow for pickling 40 | and a default name in the form ``sHH:MM`` (``s`` is the sign.). 41 | 42 | The implementation also caches instances. During creation, if a 43 | FixedOffsetTimezone instance has previously been created with the same 44 | offset and name that instance will be returned. This saves memory and 45 | improves comparability. 46 | 47 | .. __: http://docs.python.org/library/datetime.html#datetime-tzinfo 48 | """ 49 | _name = None 50 | _offset = ZERO 51 | 52 | _cache = {} 53 | 54 | def __init__(self, offset=None, name=None): 55 | if offset is not None: 56 | self._offset = datetime.timedelta(minutes=offset) 57 | if name is not None: 58 | self._name = name 59 | 60 | def __new__(cls, offset=None, name=None): 61 | """Return a suitable instance created earlier if it exists 62 | """ 63 | key = (offset, name) 64 | try: 65 | return cls._cache[key] 66 | except KeyError: 67 | tz = super(FixedOffsetTimezone, cls).__new__(cls, offset, name) 68 | cls._cache[key] = tz 69 | return tz 70 | 71 | def __repr__(self): 72 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 73 | return "psycopg2.tz.FixedOffsetTimezone(offset=%r, name=%r)" \ 74 | % (offset_mins, self._name) 75 | 76 | def __getinitargs__(self): 77 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 78 | return (offset_mins, self._name) 79 | 80 | def utcoffset(self, dt): 81 | return self._offset 82 | 83 | def tzname(self, dt): 84 | if self._name is not None: 85 | return self._name 86 | else: 87 | seconds = self._offset.seconds + self._offset.days * 86400 88 | hours, seconds = divmod(seconds, 3600) 89 | minutes = seconds / 60 90 | if minutes: 91 | return "%+03d:%d" % (hours, minutes) 92 | else: 93 | return "%+03d" % hours 94 | 95 | def dst(self, dt): 96 | return ZERO 97 | 98 | 99 | STDOFFSET = datetime.timedelta(seconds=-time.timezone) 100 | if time.daylight: 101 | DSTOFFSET = datetime.timedelta(seconds=-time.altzone) 102 | else: 103 | DSTOFFSET = STDOFFSET 104 | DSTDIFF = DSTOFFSET - STDOFFSET 105 | 106 | 107 | class LocalTimezone(datetime.tzinfo): 108 | """Platform idea of local timezone. 109 | 110 | This is the exact implementation from the Python 2.3 documentation. 111 | """ 112 | def utcoffset(self, dt): 113 | if self._isdst(dt): 114 | return DSTOFFSET 115 | else: 116 | return STDOFFSET 117 | 118 | def dst(self, dt): 119 | if self._isdst(dt): 120 | return DSTDIFF 121 | else: 122 | return ZERO 123 | 124 | def tzname(self, dt): 125 | return time.tzname[self._isdst(dt)] 126 | 127 | def _isdst(self, dt): 128 | tt = (dt.year, dt.month, dt.day, 129 | dt.hour, dt.minute, dt.second, 130 | dt.weekday(), 0, -1) 131 | stamp = time.mktime(tt) 132 | tt = time.localtime(stamp) 133 | return tt.tm_isdst > 0 134 | 135 | LOCAL = LocalTimezone() 136 | 137 | # TODO: pre-generate some interesting time zones? 138 | -------------------------------------------------------------------------------- /psycopg2-3.7/__init__.py: -------------------------------------------------------------------------------- 1 | """A Python driver for PostgreSQL 2 | 3 | psycopg is a PostgreSQL_ database adapter for the Python_ programming 4 | language. This is version 2, a complete rewrite of the original code to 5 | provide new-style classes for connection and cursor objects and other sweet 6 | candies. Like the original, psycopg 2 was written with the aim of being very 7 | small and fast, and stable as a rock. 8 | 9 | Homepage: http://initd.org/projects/psycopg2 10 | 11 | .. _PostgreSQL: https://www.postgresql.org/ 12 | .. _Python: https://www.python.org/ 13 | 14 | :Groups: 15 | * `Connections creation`: connect 16 | * `Value objects constructors`: Binary, Date, DateFromTicks, Time, 17 | TimeFromTicks, Timestamp, TimestampFromTicks 18 | """ 19 | # psycopg/__init__.py - initialization of the psycopg module 20 | # 21 | # Copyright (C) 2003-2019 Federico Di Gregorio 22 | # 23 | # psycopg2 is free software: you can redistribute it and/or modify it 24 | # under the terms of the GNU Lesser General Public License as published 25 | # by the Free Software Foundation, either version 3 of the License, or 26 | # (at your option) any later version. 27 | # 28 | # In addition, as a special exception, the copyright holders give 29 | # permission to link this program with the OpenSSL library (or with 30 | # modified versions of OpenSSL that use the same license as OpenSSL), 31 | # and distribute linked combinations including the two. 32 | # 33 | # You must obey the GNU Lesser General Public License in all respects for 34 | # all of the code used other than OpenSSL. 35 | # 36 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 37 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 38 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 39 | # License for more details. 40 | 41 | # Import modules needed by _psycopg to allow tools like py2exe to do 42 | # their work without bothering about the module dependencies. 43 | 44 | # Note: the first internal import should be _psycopg, otherwise the real cause 45 | # of a failed loading of the C module may get hidden, see 46 | # https://archives.postgresql.org/psycopg/2011-02/msg00044.php 47 | 48 | # Import the DBAPI-2.0 stuff into top-level module. 49 | 50 | from psycopg2._psycopg import ( # noqa 51 | BINARY, NUMBER, STRING, DATETIME, ROWID, 52 | 53 | Binary, Date, Time, Timestamp, 54 | DateFromTicks, TimeFromTicks, TimestampFromTicks, 55 | 56 | Error, Warning, DataError, DatabaseError, ProgrammingError, IntegrityError, 57 | InterfaceError, InternalError, NotSupportedError, OperationalError, 58 | 59 | _connect, apilevel, threadsafety, paramstyle, 60 | __version__, __libpq_version__, 61 | ) 62 | 63 | from psycopg2 import tz # noqa 64 | 65 | 66 | # Register default adapters. 67 | 68 | from psycopg2 import extensions as _ext 69 | _ext.register_adapter(tuple, _ext.SQL_IN) 70 | _ext.register_adapter(type(None), _ext.NoneAdapter) 71 | 72 | # Register the Decimal adapter here instead of in the C layer. 73 | # This way a new class is registered for each sub-interpreter. 74 | # See ticket #52 75 | from decimal import Decimal # noqa 76 | from psycopg2._psycopg import Decimal as Adapter # noqa 77 | _ext.register_adapter(Decimal, Adapter) 78 | del Decimal, Adapter 79 | 80 | 81 | def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs): 82 | """ 83 | Create a new database connection. 84 | 85 | The connection parameters can be specified as a string: 86 | 87 | conn = psycopg2.connect("dbname=test user=postgres password=secret") 88 | 89 | or using a set of keyword arguments: 90 | 91 | conn = psycopg2.connect(database="test", user="postgres", password="secret") 92 | 93 | Or as a mix of both. The basic connection parameters are: 94 | 95 | - *dbname*: the database name 96 | - *database*: the database name (only as keyword argument) 97 | - *user*: user name used to authenticate 98 | - *password*: password used to authenticate 99 | - *host*: database host address (defaults to UNIX socket if not provided) 100 | - *port*: connection port number (defaults to 5432 if not provided) 101 | 102 | Using the *connection_factory* parameter a different class or connections 103 | factory can be specified. It should be a callable object taking a dsn 104 | argument. 105 | 106 | Using the *cursor_factory* parameter, a new default cursor factory will be 107 | used by cursor(). 108 | 109 | Using *async*=True an asynchronous connection will be created. *async_* is 110 | a valid alias (for Python versions where ``async`` is a keyword). 111 | 112 | Any other keyword parameter will be passed to the underlying client 113 | library: the list of supported parameters depends on the library version. 114 | 115 | """ 116 | kwasync = {} 117 | if 'async' in kwargs: 118 | kwasync['async'] = kwargs.pop('async') 119 | if 'async_' in kwargs: 120 | kwasync['async_'] = kwargs.pop('async_') 121 | 122 | if dsn is None and not kwargs: 123 | raise TypeError('missing dsn and no parameters') 124 | 125 | dsn = _ext.make_dsn(dsn, **kwargs) 126 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 127 | if cursor_factory is not None: 128 | conn.cursor_factory = cursor_factory 129 | 130 | return conn 131 | -------------------------------------------------------------------------------- /psycopg2-3.7/_ipaddress.py: -------------------------------------------------------------------------------- 1 | """Implementation of the ipaddres-based network types adaptation 2 | """ 3 | 4 | # psycopg/_ipaddress.py - Ipaddres-based network types adaptation 5 | # 6 | # Copyright (C) 2016-2019 Daniele Varrazzo 7 | # 8 | # psycopg2 is free software: you can redistribute it and/or modify it 9 | # under the terms of the GNU Lesser General Public License as published 10 | # by the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # In addition, as a special exception, the copyright holders give 14 | # permission to link this program with the OpenSSL library (or with 15 | # modified versions of OpenSSL that use the same license as OpenSSL), 16 | # and distribute linked combinations including the two. 17 | # 18 | # You must obey the GNU Lesser General Public License in all respects for 19 | # all of the code used other than OpenSSL. 20 | # 21 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 22 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 24 | # License for more details. 25 | 26 | from psycopg2.extensions import ( 27 | new_type, new_array_type, register_type, register_adapter, QuotedString) 28 | from psycopg2.compat import text_type 29 | 30 | # The module is imported on register_ipaddress 31 | ipaddress = None 32 | 33 | # The typecasters are created only once 34 | _casters = None 35 | 36 | 37 | def register_ipaddress(conn_or_curs=None): 38 | """ 39 | Register conversion support between `ipaddress` objects and `network types`__. 40 | 41 | :param conn_or_curs: the scope where to register the type casters. 42 | If `!None` register them globally. 43 | 44 | After the function is called, PostgreSQL :sql:`inet` values will be 45 | converted into `~ipaddress.IPv4Interface` or `~ipaddress.IPv6Interface` 46 | objects, :sql:`cidr` values into into `~ipaddress.IPv4Network` or 47 | `~ipaddress.IPv6Network`. 48 | 49 | .. __: https://www.postgresql.org/docs/current/static/datatype-net-types.html 50 | """ 51 | global ipaddress 52 | import ipaddress 53 | 54 | global _casters 55 | if _casters is None: 56 | _casters = _make_casters() 57 | 58 | for c in _casters: 59 | register_type(c, conn_or_curs) 60 | 61 | for t in [ipaddress.IPv4Interface, ipaddress.IPv6Interface, 62 | ipaddress.IPv4Network, ipaddress.IPv6Network]: 63 | register_adapter(t, adapt_ipaddress) 64 | 65 | 66 | def _make_casters(): 67 | inet = new_type((869,), 'INET', cast_interface) 68 | ainet = new_array_type((1041,), 'INET[]', inet) 69 | 70 | cidr = new_type((650,), 'CIDR', cast_network) 71 | acidr = new_array_type((651,), 'CIDR[]', cidr) 72 | 73 | return [inet, ainet, cidr, acidr] 74 | 75 | 76 | def cast_interface(s, cur=None): 77 | if s is None: 78 | return None 79 | # Py2 version force the use of unicode. meh. 80 | return ipaddress.ip_interface(text_type(s)) 81 | 82 | 83 | def cast_network(s, cur=None): 84 | if s is None: 85 | return None 86 | return ipaddress.ip_network(text_type(s)) 87 | 88 | 89 | def adapt_ipaddress(obj): 90 | return QuotedString(str(obj)) 91 | -------------------------------------------------------------------------------- /psycopg2-3.7/_lru_cache.py: -------------------------------------------------------------------------------- 1 | """ 2 | LRU cache implementation for Python 2.7 3 | 4 | Ported from http://code.activestate.com/recipes/578078/ and simplified for our 5 | use (only support maxsize > 0 and positional arguments). 6 | """ 7 | 8 | from collections import namedtuple 9 | from functools import update_wrapper 10 | from threading import RLock 11 | 12 | _CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"]) 13 | 14 | 15 | def lru_cache(maxsize=100): 16 | """Least-recently-used cache decorator. 17 | 18 | Arguments to the cached function must be hashable. 19 | 20 | See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used 21 | 22 | """ 23 | def decorating_function(user_function): 24 | 25 | cache = dict() 26 | stats = [0, 0] # make statistics updateable non-locally 27 | HITS, MISSES = 0, 1 # names for the stats fields 28 | cache_get = cache.get # bound method to lookup key or return None 29 | _len = len # localize the global len() function 30 | lock = RLock() # linkedlist updates aren't threadsafe 31 | root = [] # root of the circular doubly linked list 32 | root[:] = [root, root, None, None] # initialize by pointing to self 33 | nonlocal_root = [root] # make updateable non-locally 34 | PREV, NEXT, KEY, RESULT = 0, 1, 2, 3 # names for the link fields 35 | 36 | assert maxsize and maxsize > 0, "maxsize %s not supported" % maxsize 37 | 38 | def wrapper(*args): 39 | # size limited caching that tracks accesses by recency 40 | key = args 41 | with lock: 42 | link = cache_get(key) 43 | if link is not None: 44 | # record recent use of the key by moving it to the 45 | # front of the list 46 | root, = nonlocal_root 47 | link_prev, link_next, key, result = link 48 | link_prev[NEXT] = link_next 49 | link_next[PREV] = link_prev 50 | last = root[PREV] 51 | last[NEXT] = root[PREV] = link 52 | link[PREV] = last 53 | link[NEXT] = root 54 | stats[HITS] += 1 55 | return result 56 | result = user_function(*args) 57 | with lock: 58 | root, = nonlocal_root 59 | if key in cache: 60 | # getting here means that this same key was added to the 61 | # cache while the lock was released. since the link 62 | # update is already done, we need only return the 63 | # computed result and update the count of misses. 64 | pass 65 | elif _len(cache) >= maxsize: 66 | # use the old root to store the new key and result 67 | oldroot = root 68 | oldroot[KEY] = key 69 | oldroot[RESULT] = result 70 | # empty the oldest link and make it the new root 71 | root = nonlocal_root[0] = oldroot[NEXT] 72 | oldkey = root[KEY] 73 | # oldvalue = root[RESULT] 74 | root[KEY] = root[RESULT] = None 75 | # now update the cache dictionary for the new links 76 | del cache[oldkey] 77 | cache[key] = oldroot 78 | else: 79 | # put result in a new link at the front of the list 80 | last = root[PREV] 81 | link = [last, root, key, result] 82 | last[NEXT] = root[PREV] = cache[key] = link 83 | stats[MISSES] += 1 84 | return result 85 | 86 | def cache_info(): 87 | """Report cache statistics""" 88 | with lock: 89 | return _CacheInfo(stats[HITS], stats[MISSES], maxsize, len(cache)) 90 | 91 | def cache_clear(): 92 | """Clear the cache and cache statistics""" 93 | with lock: 94 | cache.clear() 95 | root = nonlocal_root[0] 96 | root[:] = [root, root, None, None] 97 | stats[:] = [0, 0] 98 | 99 | wrapper.__wrapped__ = user_function 100 | wrapper.cache_info = cache_info 101 | wrapper.cache_clear = cache_clear 102 | return update_wrapper(wrapper, user_function) 103 | 104 | return decorating_function 105 | -------------------------------------------------------------------------------- /psycopg2-3.7/_psycopg.cpython-37m-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.7/_psycopg.cpython-37m-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /psycopg2-3.7/compat.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | __all__ = ['string_types', 'text_type', 'lru_cache'] 4 | 5 | if sys.version_info[0] == 2: 6 | # Python 2 7 | PY2 = True 8 | PY3 = False 9 | string_types = basestring, 10 | text_type = unicode 11 | from ._lru_cache import lru_cache 12 | 13 | else: 14 | # Python 3 15 | PY2 = False 16 | PY3 = True 17 | string_types = str, 18 | text_type = str 19 | from functools import lru_cache 20 | -------------------------------------------------------------------------------- /psycopg2-3.7/errors.py: -------------------------------------------------------------------------------- 1 | """Error classes for PostgreSQL error codes 2 | """ 3 | 4 | # psycopg/errors.py - SQLSTATE and DB-API exceptions 5 | # 6 | # Copyright (C) 2018-2019 Daniele Varrazzo 7 | # 8 | # psycopg2 is free software: you can redistribute it and/or modify it 9 | # under the terms of the GNU Lesser General Public License as published 10 | # by the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # In addition, as a special exception, the copyright holders give 14 | # permission to link this program with the OpenSSL library (or with 15 | # modified versions of OpenSSL that use the same license as OpenSSL), 16 | # and distribute linked combinations including the two. 17 | # 18 | # You must obey the GNU Lesser General Public License in all respects for 19 | # all of the code used other than OpenSSL. 20 | # 21 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 22 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 24 | # License for more details. 25 | 26 | # 27 | # NOTE: the exceptions are injected into this module by the C extention. 28 | # 29 | 30 | 31 | def lookup(code): 32 | """Lookup an error code and return its exception class. 33 | 34 | Raise `!KeyError` if the code is not found. 35 | """ 36 | from psycopg2._psycopg import sqlstate_errors # avoid circular import 37 | return sqlstate_errors[code] 38 | -------------------------------------------------------------------------------- /psycopg2-3.7/pool.py: -------------------------------------------------------------------------------- 1 | """Connection pooling for psycopg2 2 | 3 | This module implements thread-safe (and not) connection pools. 4 | """ 5 | # psycopg/pool.py - pooling code for psycopg 6 | # 7 | # Copyright (C) 2003-2019 Federico Di Gregorio 8 | # 9 | # psycopg2 is free software: you can redistribute it and/or modify it 10 | # under the terms of the GNU Lesser General Public License as published 11 | # by the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # In addition, as a special exception, the copyright holders give 15 | # permission to link this program with the OpenSSL library (or with 16 | # modified versions of OpenSSL that use the same license as OpenSSL), 17 | # and distribute linked combinations including the two. 18 | # 19 | # You must obey the GNU Lesser General Public License in all respects for 20 | # all of the code used other than OpenSSL. 21 | # 22 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 23 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 25 | # License for more details. 26 | 27 | import psycopg2 28 | from psycopg2 import extensions as _ext 29 | 30 | 31 | class PoolError(psycopg2.Error): 32 | pass 33 | 34 | 35 | class AbstractConnectionPool(object): 36 | """Generic key-based pooling code.""" 37 | 38 | def __init__(self, minconn, maxconn, *args, **kwargs): 39 | """Initialize the connection pool. 40 | 41 | New 'minconn' connections are created immediately calling 'connfunc' 42 | with given parameters. The connection pool will support a maximum of 43 | about 'maxconn' connections. 44 | """ 45 | self.minconn = int(minconn) 46 | self.maxconn = int(maxconn) 47 | self.closed = False 48 | 49 | self._args = args 50 | self._kwargs = kwargs 51 | 52 | self._pool = [] 53 | self._used = {} 54 | self._rused = {} # id(conn) -> key map 55 | self._keys = 0 56 | 57 | for i in range(self.minconn): 58 | self._connect() 59 | 60 | def _connect(self, key=None): 61 | """Create a new connection and assign it to 'key' if not None.""" 62 | conn = psycopg2.connect(*self._args, **self._kwargs) 63 | if key is not None: 64 | self._used[key] = conn 65 | self._rused[id(conn)] = key 66 | else: 67 | self._pool.append(conn) 68 | return conn 69 | 70 | def _getkey(self): 71 | """Return a new unique key.""" 72 | self._keys += 1 73 | return self._keys 74 | 75 | def _getconn(self, key=None): 76 | """Get a free connection and assign it to 'key' if not None.""" 77 | if self.closed: 78 | raise PoolError("connection pool is closed") 79 | if key is None: 80 | key = self._getkey() 81 | 82 | if key in self._used: 83 | return self._used[key] 84 | 85 | if self._pool: 86 | self._used[key] = conn = self._pool.pop() 87 | self._rused[id(conn)] = key 88 | return conn 89 | else: 90 | if len(self._used) == self.maxconn: 91 | raise PoolError("connection pool exhausted") 92 | return self._connect(key) 93 | 94 | def _putconn(self, conn, key=None, close=False): 95 | """Put away a connection.""" 96 | if self.closed: 97 | raise PoolError("connection pool is closed") 98 | 99 | if key is None: 100 | key = self._rused.get(id(conn)) 101 | if key is None: 102 | raise PoolError("trying to put unkeyed connection") 103 | 104 | if len(self._pool) < self.minconn and not close: 105 | # Return the connection into a consistent state before putting 106 | # it back into the pool 107 | if not conn.closed: 108 | status = conn.info.transaction_status 109 | if status == _ext.TRANSACTION_STATUS_UNKNOWN: 110 | # server connection lost 111 | conn.close() 112 | elif status != _ext.TRANSACTION_STATUS_IDLE: 113 | # connection in error or in transaction 114 | conn.rollback() 115 | self._pool.append(conn) 116 | else: 117 | # regular idle connection 118 | self._pool.append(conn) 119 | # If the connection is closed, we just discard it. 120 | else: 121 | conn.close() 122 | 123 | # here we check for the presence of key because it can happen that a 124 | # thread tries to put back a connection after a call to close 125 | if not self.closed or key in self._used: 126 | del self._used[key] 127 | del self._rused[id(conn)] 128 | 129 | def _closeall(self): 130 | """Close all connections. 131 | 132 | Note that this can lead to some code fail badly when trying to use 133 | an already closed connection. If you call .closeall() make sure 134 | your code can deal with it. 135 | """ 136 | if self.closed: 137 | raise PoolError("connection pool is closed") 138 | for conn in self._pool + list(self._used.values()): 139 | try: 140 | conn.close() 141 | except Exception: 142 | pass 143 | self.closed = True 144 | 145 | 146 | class SimpleConnectionPool(AbstractConnectionPool): 147 | """A connection pool that can't be shared across different threads.""" 148 | 149 | getconn = AbstractConnectionPool._getconn 150 | putconn = AbstractConnectionPool._putconn 151 | closeall = AbstractConnectionPool._closeall 152 | 153 | 154 | class ThreadedConnectionPool(AbstractConnectionPool): 155 | """A connection pool that works with the threading module.""" 156 | 157 | def __init__(self, minconn, maxconn, *args, **kwargs): 158 | """Initialize the threading lock.""" 159 | import threading 160 | AbstractConnectionPool.__init__( 161 | self, minconn, maxconn, *args, **kwargs) 162 | self._lock = threading.Lock() 163 | 164 | def getconn(self, key=None): 165 | """Get a free connection and assign it to 'key' if not None.""" 166 | self._lock.acquire() 167 | try: 168 | return self._getconn(key) 169 | finally: 170 | self._lock.release() 171 | 172 | def putconn(self, conn=None, key=None, close=False): 173 | """Put away an unused connection.""" 174 | self._lock.acquire() 175 | try: 176 | self._putconn(conn, key, close) 177 | finally: 178 | self._lock.release() 179 | 180 | def closeall(self): 181 | """Close all connections (even the one currently in use.)""" 182 | self._lock.acquire() 183 | try: 184 | self._closeall() 185 | finally: 186 | self._lock.release() 187 | -------------------------------------------------------------------------------- /psycopg2-3.7/psycopg1.py: -------------------------------------------------------------------------------- 1 | """psycopg 1.1.x compatibility module 2 | 3 | This module uses the new style connection and cursor types to build a psycopg 4 | 1.1.1.x compatibility layer. It should be considered a temporary hack to run 5 | old code while porting to psycopg 2. Import it as follows:: 6 | 7 | from psycopg2 import psycopg1 as psycopg 8 | """ 9 | # psycopg/psycopg1.py - psycopg 1.1.x compatibility module 10 | # 11 | # Copyright (C) 2003-2010 Federico Di Gregorio 12 | # 13 | # psycopg2 is free software: you can redistribute it and/or modify it 14 | # under the terms of the GNU Lesser General Public License as published 15 | # by the Free Software Foundation, either version 3 of the License, or 16 | # (at your option) any later version. 17 | # 18 | # In addition, as a special exception, the copyright holders give 19 | # permission to link this program with the OpenSSL library (or with 20 | # modified versions of OpenSSL that use the same license as OpenSSL), 21 | # and distribute linked combinations including the two. 22 | # 23 | # You must obey the GNU Lesser General Public License in all respects for 24 | # all of the code used other than OpenSSL. 25 | # 26 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 27 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 28 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 29 | # License for more details. 30 | 31 | import psycopg2._psycopg as _2psycopg # noqa 32 | from psycopg2.extensions import cursor as _2cursor 33 | from psycopg2.extensions import connection as _2connection 34 | 35 | from psycopg2 import * # noqa 36 | import psycopg2.extensions as _ext 37 | _2connect = connect 38 | 39 | 40 | def connect(*args, **kwargs): 41 | """connect(dsn, ...) -> new psycopg 1.1.x compatible connection object""" 42 | kwargs['connection_factory'] = connection 43 | conn = _2connect(*args, **kwargs) 44 | conn.set_isolation_level(_ext.ISOLATION_LEVEL_READ_COMMITTED) 45 | return conn 46 | 47 | 48 | class connection(_2connection): 49 | """psycopg 1.1.x connection.""" 50 | 51 | def cursor(self): 52 | """cursor() -> new psycopg 1.1.x compatible cursor object""" 53 | return _2connection.cursor(self, cursor_factory=cursor) 54 | 55 | def autocommit(self, on_off=1): 56 | """autocommit(on_off=1) -> switch autocommit on (1) or off (0)""" 57 | if on_off > 0: 58 | self.set_isolation_level(_ext.ISOLATION_LEVEL_AUTOCOMMIT) 59 | else: 60 | self.set_isolation_level(_ext.ISOLATION_LEVEL_READ_COMMITTED) 61 | 62 | 63 | class cursor(_2cursor): 64 | """psycopg 1.1.x cursor. 65 | 66 | Note that this cursor implements the exact procedure used by psycopg 1 to 67 | build dictionaries out of result rows. The DictCursor in the 68 | psycopg.extras modules implements a much better and faster algorithm. 69 | """ 70 | 71 | def __build_dict(self, row): 72 | res = {} 73 | for i in range(len(self.description)): 74 | res[self.description[i][0]] = row[i] 75 | return res 76 | 77 | def dictfetchone(self): 78 | row = _2cursor.fetchone(self) 79 | if row: 80 | return self.__build_dict(row) 81 | else: 82 | return row 83 | 84 | def dictfetchmany(self, size): 85 | res = [] 86 | rows = _2cursor.fetchmany(self, size) 87 | for row in rows: 88 | res.append(self.__build_dict(row)) 89 | return res 90 | 91 | def dictfetchall(self): 92 | res = [] 93 | rows = _2cursor.fetchall(self) 94 | for row in rows: 95 | res.append(self.__build_dict(row)) 96 | return res 97 | -------------------------------------------------------------------------------- /psycopg2-3.7/tz.py: -------------------------------------------------------------------------------- 1 | """tzinfo implementations for psycopg2 2 | 3 | This module holds two different tzinfo implementations that can be used as 4 | the 'tzinfo' argument to datetime constructors, directly passed to psycopg 5 | functions or used to set the .tzinfo_factory attribute in cursors. 6 | """ 7 | # psycopg/tz.py - tzinfo implementation 8 | # 9 | # Copyright (C) 2003-2019 Federico Di Gregorio 10 | # 11 | # psycopg2 is free software: you can redistribute it and/or modify it 12 | # under the terms of the GNU Lesser General Public License as published 13 | # by the Free Software Foundation, either version 3 of the License, or 14 | # (at your option) any later version. 15 | # 16 | # In addition, as a special exception, the copyright holders give 17 | # permission to link this program with the OpenSSL library (or with 18 | # modified versions of OpenSSL that use the same license as OpenSSL), 19 | # and distribute linked combinations including the two. 20 | # 21 | # You must obey the GNU Lesser General Public License in all respects for 22 | # all of the code used other than OpenSSL. 23 | # 24 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 25 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 26 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 27 | # License for more details. 28 | 29 | import datetime 30 | import time 31 | 32 | ZERO = datetime.timedelta(0) 33 | 34 | 35 | class FixedOffsetTimezone(datetime.tzinfo): 36 | """Fixed offset in minutes east from UTC. 37 | 38 | This is exactly the implementation__ found in Python 2.3.x documentation, 39 | with a small change to the `!__init__()` method to allow for pickling 40 | and a default name in the form ``sHH:MM`` (``s`` is the sign.). 41 | 42 | The implementation also caches instances. During creation, if a 43 | FixedOffsetTimezone instance has previously been created with the same 44 | offset and name that instance will be returned. This saves memory and 45 | improves comparability. 46 | 47 | .. __: https://docs.python.org/library/datetime.html 48 | """ 49 | _name = None 50 | _offset = ZERO 51 | 52 | _cache = {} 53 | 54 | def __init__(self, offset=None, name=None): 55 | if offset is not None: 56 | self._offset = datetime.timedelta(minutes=offset) 57 | if name is not None: 58 | self._name = name 59 | 60 | def __new__(cls, offset=None, name=None): 61 | """Return a suitable instance created earlier if it exists 62 | """ 63 | key = (offset, name) 64 | try: 65 | return cls._cache[key] 66 | except KeyError: 67 | tz = super(FixedOffsetTimezone, cls).__new__(cls, offset, name) 68 | cls._cache[key] = tz 69 | return tz 70 | 71 | def __repr__(self): 72 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 73 | return "psycopg2.tz.FixedOffsetTimezone(offset=%r, name=%r)" \ 74 | % (offset_mins, self._name) 75 | 76 | def __getinitargs__(self): 77 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 78 | return offset_mins, self._name 79 | 80 | def utcoffset(self, dt): 81 | return self._offset 82 | 83 | def tzname(self, dt): 84 | if self._name is not None: 85 | return self._name 86 | else: 87 | seconds = self._offset.seconds + self._offset.days * 86400 88 | hours, seconds = divmod(seconds, 3600) 89 | minutes = seconds / 60 90 | if minutes: 91 | return "%+03d:%d" % (hours, minutes) 92 | else: 93 | return "%+03d" % hours 94 | 95 | def dst(self, dt): 96 | return ZERO 97 | 98 | 99 | STDOFFSET = datetime.timedelta(seconds=-time.timezone) 100 | if time.daylight: 101 | DSTOFFSET = datetime.timedelta(seconds=-time.altzone) 102 | else: 103 | DSTOFFSET = STDOFFSET 104 | DSTDIFF = DSTOFFSET - STDOFFSET 105 | 106 | 107 | class LocalTimezone(datetime.tzinfo): 108 | """Platform idea of local timezone. 109 | 110 | This is the exact implementation from the Python 2.3 documentation. 111 | """ 112 | def utcoffset(self, dt): 113 | if self._isdst(dt): 114 | return DSTOFFSET 115 | else: 116 | return STDOFFSET 117 | 118 | def dst(self, dt): 119 | if self._isdst(dt): 120 | return DSTDIFF 121 | else: 122 | return ZERO 123 | 124 | def tzname(self, dt): 125 | return time.tzname[self._isdst(dt)] 126 | 127 | def _isdst(self, dt): 128 | tt = (dt.year, dt.month, dt.day, 129 | dt.hour, dt.minute, dt.second, 130 | dt.weekday(), 0, -1) 131 | stamp = time.mktime(tt) 132 | tt = time.localtime(stamp) 133 | return tt.tm_isdst > 0 134 | 135 | 136 | LOCAL = LocalTimezone() 137 | 138 | # TODO: pre-generate some interesting time zones? 139 | -------------------------------------------------------------------------------- /psycopg2-3.8/__init__.py: -------------------------------------------------------------------------------- 1 | """A Python driver for PostgreSQL 2 | 3 | psycopg is a PostgreSQL_ database adapter for the Python_ programming 4 | language. This is version 2, a complete rewrite of the original code to 5 | provide new-style classes for connection and cursor objects and other sweet 6 | candies. Like the original, psycopg 2 was written with the aim of being very 7 | small and fast, and stable as a rock. 8 | 9 | Homepage: https://psycopg.org/ 10 | 11 | .. _PostgreSQL: https://www.postgresql.org/ 12 | .. _Python: https://www.python.org/ 13 | 14 | :Groups: 15 | * `Connections creation`: connect 16 | * `Value objects constructors`: Binary, Date, DateFromTicks, Time, 17 | TimeFromTicks, Timestamp, TimestampFromTicks 18 | """ 19 | # psycopg/__init__.py - initialization of the psycopg module 20 | # 21 | # Copyright (C) 2003-2019 Federico Di Gregorio 22 | # Copyright (C) 2020 The Psycopg Team 23 | # 24 | # psycopg2 is free software: you can redistribute it and/or modify it 25 | # under the terms of the GNU Lesser General Public License as published 26 | # by the Free Software Foundation, either version 3 of the License, or 27 | # (at your option) any later version. 28 | # 29 | # In addition, as a special exception, the copyright holders give 30 | # permission to link this program with the OpenSSL library (or with 31 | # modified versions of OpenSSL that use the same license as OpenSSL), 32 | # and distribute linked combinations including the two. 33 | # 34 | # You must obey the GNU Lesser General Public License in all respects for 35 | # all of the code used other than OpenSSL. 36 | # 37 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 38 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 39 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 40 | # License for more details. 41 | 42 | # Import modules needed by _psycopg to allow tools like py2exe to do 43 | # their work without bothering about the module dependencies. 44 | 45 | # Note: the first internal import should be _psycopg, otherwise the real cause 46 | # of a failed loading of the C module may get hidden, see 47 | # https://archives.postgresql.org/psycopg/2011-02/msg00044.php 48 | 49 | # Import the DBAPI-2.0 stuff into top-level module. 50 | 51 | from psycopg2._psycopg import ( # noqa 52 | BINARY, NUMBER, STRING, DATETIME, ROWID, 53 | 54 | Binary, Date, Time, Timestamp, 55 | DateFromTicks, TimeFromTicks, TimestampFromTicks, 56 | 57 | Error, Warning, DataError, DatabaseError, ProgrammingError, IntegrityError, 58 | InterfaceError, InternalError, NotSupportedError, OperationalError, 59 | 60 | _connect, apilevel, threadsafety, paramstyle, 61 | __version__, __libpq_version__, 62 | ) 63 | 64 | from psycopg2 import tz # noqa 65 | 66 | 67 | # Register default adapters. 68 | 69 | from psycopg2 import extensions as _ext 70 | _ext.register_adapter(tuple, _ext.SQL_IN) 71 | _ext.register_adapter(type(None), _ext.NoneAdapter) 72 | 73 | # Register the Decimal adapter here instead of in the C layer. 74 | # This way a new class is registered for each sub-interpreter. 75 | # See ticket #52 76 | from decimal import Decimal # noqa 77 | from psycopg2._psycopg import Decimal as Adapter # noqa 78 | _ext.register_adapter(Decimal, Adapter) 79 | del Decimal, Adapter 80 | 81 | 82 | def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs): 83 | """ 84 | Create a new database connection. 85 | 86 | The connection parameters can be specified as a string: 87 | 88 | conn = psycopg2.connect("dbname=test user=postgres password=secret") 89 | 90 | or using a set of keyword arguments: 91 | 92 | conn = psycopg2.connect(database="test", user="postgres", password="secret") 93 | 94 | Or as a mix of both. The basic connection parameters are: 95 | 96 | - *dbname*: the database name 97 | - *database*: the database name (only as keyword argument) 98 | - *user*: user name used to authenticate 99 | - *password*: password used to authenticate 100 | - *host*: database host address (defaults to UNIX socket if not provided) 101 | - *port*: connection port number (defaults to 5432 if not provided) 102 | 103 | Using the *connection_factory* parameter a different class or connections 104 | factory can be specified. It should be a callable object taking a dsn 105 | argument. 106 | 107 | Using the *cursor_factory* parameter, a new default cursor factory will be 108 | used by cursor(). 109 | 110 | Using *async*=True an asynchronous connection will be created. *async_* is 111 | a valid alias (for Python versions where ``async`` is a keyword). 112 | 113 | Any other keyword parameter will be passed to the underlying client 114 | library: the list of supported parameters depends on the library version. 115 | 116 | """ 117 | kwasync = {} 118 | if 'async' in kwargs: 119 | kwasync['async'] = kwargs.pop('async') 120 | if 'async_' in kwargs: 121 | kwasync['async_'] = kwargs.pop('async_') 122 | 123 | if dsn is None and not kwargs: 124 | raise TypeError('missing dsn and no parameters') 125 | 126 | dsn = _ext.make_dsn(dsn, **kwargs) 127 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 128 | if cursor_factory is not None: 129 | conn.cursor_factory = cursor_factory 130 | 131 | return conn 132 | -------------------------------------------------------------------------------- /psycopg2-3.8/_ipaddress.py: -------------------------------------------------------------------------------- 1 | """Implementation of the ipaddres-based network types adaptation 2 | """ 3 | 4 | # psycopg/_ipaddress.py - Ipaddres-based network types adaptation 5 | # 6 | # Copyright (C) 2016-2019 Daniele Varrazzo 7 | # Copyright (C) 2020 The Psycopg Team 8 | # 9 | # psycopg2 is free software: you can redistribute it and/or modify it 10 | # under the terms of the GNU Lesser General Public License as published 11 | # by the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # In addition, as a special exception, the copyright holders give 15 | # permission to link this program with the OpenSSL library (or with 16 | # modified versions of OpenSSL that use the same license as OpenSSL), 17 | # and distribute linked combinations including the two. 18 | # 19 | # You must obey the GNU Lesser General Public License in all respects for 20 | # all of the code used other than OpenSSL. 21 | # 22 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 23 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 25 | # License for more details. 26 | 27 | from psycopg2.extensions import ( 28 | new_type, new_array_type, register_type, register_adapter, QuotedString) 29 | from psycopg2.compat import text_type 30 | 31 | # The module is imported on register_ipaddress 32 | ipaddress = None 33 | 34 | # The typecasters are created only once 35 | _casters = None 36 | 37 | 38 | def register_ipaddress(conn_or_curs=None): 39 | """ 40 | Register conversion support between `ipaddress` objects and `network types`__. 41 | 42 | :param conn_or_curs: the scope where to register the type casters. 43 | If `!None` register them globally. 44 | 45 | After the function is called, PostgreSQL :sql:`inet` values will be 46 | converted into `~ipaddress.IPv4Interface` or `~ipaddress.IPv6Interface` 47 | objects, :sql:`cidr` values into into `~ipaddress.IPv4Network` or 48 | `~ipaddress.IPv6Network`. 49 | 50 | .. __: https://www.postgresql.org/docs/current/static/datatype-net-types.html 51 | """ 52 | global ipaddress 53 | import ipaddress 54 | 55 | global _casters 56 | if _casters is None: 57 | _casters = _make_casters() 58 | 59 | for c in _casters: 60 | register_type(c, conn_or_curs) 61 | 62 | for t in [ipaddress.IPv4Interface, ipaddress.IPv6Interface, 63 | ipaddress.IPv4Network, ipaddress.IPv6Network]: 64 | register_adapter(t, adapt_ipaddress) 65 | 66 | 67 | def _make_casters(): 68 | inet = new_type((869,), 'INET', cast_interface) 69 | ainet = new_array_type((1041,), 'INET[]', inet) 70 | 71 | cidr = new_type((650,), 'CIDR', cast_network) 72 | acidr = new_array_type((651,), 'CIDR[]', cidr) 73 | 74 | return [inet, ainet, cidr, acidr] 75 | 76 | 77 | def cast_interface(s, cur=None): 78 | if s is None: 79 | return None 80 | # Py2 version force the use of unicode. meh. 81 | return ipaddress.ip_interface(text_type(s)) 82 | 83 | 84 | def cast_network(s, cur=None): 85 | if s is None: 86 | return None 87 | return ipaddress.ip_network(text_type(s)) 88 | 89 | 90 | def adapt_ipaddress(obj): 91 | return QuotedString(str(obj)) 92 | -------------------------------------------------------------------------------- /psycopg2-3.8/_lru_cache.py: -------------------------------------------------------------------------------- 1 | """ 2 | LRU cache implementation for Python 2.7 3 | 4 | Ported from http://code.activestate.com/recipes/578078/ and simplified for our 5 | use (only support maxsize > 0 and positional arguments). 6 | """ 7 | 8 | from collections import namedtuple 9 | from functools import update_wrapper 10 | from threading import RLock 11 | 12 | _CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"]) 13 | 14 | 15 | def lru_cache(maxsize=100): 16 | """Least-recently-used cache decorator. 17 | 18 | Arguments to the cached function must be hashable. 19 | 20 | See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used 21 | 22 | """ 23 | def decorating_function(user_function): 24 | 25 | cache = dict() 26 | stats = [0, 0] # make statistics updateable non-locally 27 | HITS, MISSES = 0, 1 # names for the stats fields 28 | cache_get = cache.get # bound method to lookup key or return None 29 | _len = len # localize the global len() function 30 | lock = RLock() # linkedlist updates aren't threadsafe 31 | root = [] # root of the circular doubly linked list 32 | root[:] = [root, root, None, None] # initialize by pointing to self 33 | nonlocal_root = [root] # make updateable non-locally 34 | PREV, NEXT, KEY, RESULT = 0, 1, 2, 3 # names for the link fields 35 | 36 | assert maxsize and maxsize > 0, "maxsize %s not supported" % maxsize 37 | 38 | def wrapper(*args): 39 | # size limited caching that tracks accesses by recency 40 | key = args 41 | with lock: 42 | link = cache_get(key) 43 | if link is not None: 44 | # record recent use of the key by moving it to the 45 | # front of the list 46 | root, = nonlocal_root 47 | link_prev, link_next, key, result = link 48 | link_prev[NEXT] = link_next 49 | link_next[PREV] = link_prev 50 | last = root[PREV] 51 | last[NEXT] = root[PREV] = link 52 | link[PREV] = last 53 | link[NEXT] = root 54 | stats[HITS] += 1 55 | return result 56 | result = user_function(*args) 57 | with lock: 58 | root, = nonlocal_root 59 | if key in cache: 60 | # getting here means that this same key was added to the 61 | # cache while the lock was released. since the link 62 | # update is already done, we need only return the 63 | # computed result and update the count of misses. 64 | pass 65 | elif _len(cache) >= maxsize: 66 | # use the old root to store the new key and result 67 | oldroot = root 68 | oldroot[KEY] = key 69 | oldroot[RESULT] = result 70 | # empty the oldest link and make it the new root 71 | root = nonlocal_root[0] = oldroot[NEXT] 72 | oldkey = root[KEY] 73 | # oldvalue = root[RESULT] 74 | root[KEY] = root[RESULT] = None 75 | # now update the cache dictionary for the new links 76 | del cache[oldkey] 77 | cache[key] = oldroot 78 | else: 79 | # put result in a new link at the front of the list 80 | last = root[PREV] 81 | link = [last, root, key, result] 82 | last[NEXT] = root[PREV] = cache[key] = link 83 | stats[MISSES] += 1 84 | return result 85 | 86 | def cache_info(): 87 | """Report cache statistics""" 88 | with lock: 89 | return _CacheInfo(stats[HITS], stats[MISSES], maxsize, len(cache)) 90 | 91 | def cache_clear(): 92 | """Clear the cache and cache statistics""" 93 | with lock: 94 | cache.clear() 95 | root = nonlocal_root[0] 96 | root[:] = [root, root, None, None] 97 | stats[:] = [0, 0] 98 | 99 | wrapper.__wrapped__ = user_function 100 | wrapper.cache_info = cache_info 101 | wrapper.cache_clear = cache_clear 102 | return update_wrapper(wrapper, user_function) 103 | 104 | return decorating_function 105 | -------------------------------------------------------------------------------- /psycopg2-3.8/_psycopg.cpython-38-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.8/_psycopg.cpython-38-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /psycopg2-3.8/compat.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | __all__ = ['string_types', 'text_type', 'lru_cache'] 4 | 5 | if sys.version_info[0] == 2: 6 | # Python 2 7 | PY2 = True 8 | PY3 = False 9 | string_types = basestring, 10 | text_type = unicode 11 | from ._lru_cache import lru_cache 12 | 13 | else: 14 | # Python 3 15 | PY2 = False 16 | PY3 = True 17 | string_types = str, 18 | text_type = str 19 | from functools import lru_cache 20 | -------------------------------------------------------------------------------- /psycopg2-3.8/errors.py: -------------------------------------------------------------------------------- 1 | """Error classes for PostgreSQL error codes 2 | """ 3 | 4 | # psycopg/errors.py - SQLSTATE and DB-API exceptions 5 | # 6 | # Copyright (C) 2018-2019 Daniele Varrazzo 7 | # Copyright (C) 2020 The Psycopg Team 8 | # 9 | # psycopg2 is free software: you can redistribute it and/or modify it 10 | # under the terms of the GNU Lesser General Public License as published 11 | # by the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # In addition, as a special exception, the copyright holders give 15 | # permission to link this program with the OpenSSL library (or with 16 | # modified versions of OpenSSL that use the same license as OpenSSL), 17 | # and distribute linked combinations including the two. 18 | # 19 | # You must obey the GNU Lesser General Public License in all respects for 20 | # all of the code used other than OpenSSL. 21 | # 22 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 23 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 25 | # License for more details. 26 | 27 | # 28 | # NOTE: the exceptions are injected into this module by the C extention. 29 | # 30 | 31 | 32 | def lookup(code): 33 | """Lookup an error code and return its exception class. 34 | 35 | Raise `!KeyError` if the code is not found. 36 | """ 37 | from psycopg2._psycopg import sqlstate_errors # avoid circular import 38 | return sqlstate_errors[code] 39 | -------------------------------------------------------------------------------- /psycopg2-3.8/tz.py: -------------------------------------------------------------------------------- 1 | """tzinfo implementations for psycopg2 2 | 3 | This module holds two different tzinfo implementations that can be used as 4 | the 'tzinfo' argument to datetime constructors, directly passed to psycopg 5 | functions or used to set the .tzinfo_factory attribute in cursors. 6 | """ 7 | # psycopg/tz.py - tzinfo implementation 8 | # 9 | # Copyright (C) 2003-2019 Federico Di Gregorio 10 | # Copyright (C) 2020 The Psycopg Team 11 | # 12 | # psycopg2 is free software: you can redistribute it and/or modify it 13 | # under the terms of the GNU Lesser General Public License as published 14 | # by the Free Software Foundation, either version 3 of the License, or 15 | # (at your option) any later version. 16 | # 17 | # In addition, as a special exception, the copyright holders give 18 | # permission to link this program with the OpenSSL library (or with 19 | # modified versions of OpenSSL that use the same license as OpenSSL), 20 | # and distribute linked combinations including the two. 21 | # 22 | # You must obey the GNU Lesser General Public License in all respects for 23 | # all of the code used other than OpenSSL. 24 | # 25 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 26 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 27 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 28 | # License for more details. 29 | 30 | import datetime 31 | import time 32 | 33 | ZERO = datetime.timedelta(0) 34 | 35 | 36 | class FixedOffsetTimezone(datetime.tzinfo): 37 | """Fixed offset in minutes east from UTC. 38 | 39 | This is exactly the implementation__ found in Python 2.3.x documentation, 40 | with a small change to the `!__init__()` method to allow for pickling 41 | and a default name in the form ``sHH:MM`` (``s`` is the sign.). 42 | 43 | The implementation also caches instances. During creation, if a 44 | FixedOffsetTimezone instance has previously been created with the same 45 | offset and name that instance will be returned. This saves memory and 46 | improves comparability. 47 | 48 | .. __: https://docs.python.org/library/datetime.html 49 | """ 50 | _name = None 51 | _offset = ZERO 52 | 53 | _cache = {} 54 | 55 | def __init__(self, offset=None, name=None): 56 | if offset is not None: 57 | self._offset = datetime.timedelta(minutes=offset) 58 | if name is not None: 59 | self._name = name 60 | 61 | def __new__(cls, offset=None, name=None): 62 | """Return a suitable instance created earlier if it exists 63 | """ 64 | key = (offset, name) 65 | try: 66 | return cls._cache[key] 67 | except KeyError: 68 | tz = super(FixedOffsetTimezone, cls).__new__(cls, offset, name) 69 | cls._cache[key] = tz 70 | return tz 71 | 72 | def __repr__(self): 73 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 74 | return "psycopg2.tz.FixedOffsetTimezone(offset=%r, name=%r)" \ 75 | % (offset_mins, self._name) 76 | 77 | def __getinitargs__(self): 78 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 79 | return offset_mins, self._name 80 | 81 | def utcoffset(self, dt): 82 | return self._offset 83 | 84 | def tzname(self, dt): 85 | if self._name is not None: 86 | return self._name 87 | else: 88 | seconds = self._offset.seconds + self._offset.days * 86400 89 | hours, seconds = divmod(seconds, 3600) 90 | minutes = seconds / 60 91 | if minutes: 92 | return "%+03d:%d" % (hours, minutes) 93 | else: 94 | return "%+03d" % hours 95 | 96 | def dst(self, dt): 97 | return ZERO 98 | 99 | 100 | STDOFFSET = datetime.timedelta(seconds=-time.timezone) 101 | if time.daylight: 102 | DSTOFFSET = datetime.timedelta(seconds=-time.altzone) 103 | else: 104 | DSTOFFSET = STDOFFSET 105 | DSTDIFF = DSTOFFSET - STDOFFSET 106 | 107 | 108 | class LocalTimezone(datetime.tzinfo): 109 | """Platform idea of local timezone. 110 | 111 | This is the exact implementation from the Python 2.3 documentation. 112 | """ 113 | def utcoffset(self, dt): 114 | if self._isdst(dt): 115 | return DSTOFFSET 116 | else: 117 | return STDOFFSET 118 | 119 | def dst(self, dt): 120 | if self._isdst(dt): 121 | return DSTDIFF 122 | else: 123 | return ZERO 124 | 125 | def tzname(self, dt): 126 | return time.tzname[self._isdst(dt)] 127 | 128 | def _isdst(self, dt): 129 | tt = (dt.year, dt.month, dt.day, 130 | dt.hour, dt.minute, dt.second, 131 | dt.weekday(), 0, -1) 132 | stamp = time.mktime(tt) 133 | tt = time.localtime(stamp) 134 | return tt.tm_isdst > 0 135 | 136 | 137 | LOCAL = LocalTimezone() 138 | 139 | # TODO: pre-generate some interesting time zones? 140 | -------------------------------------------------------------------------------- /psycopg2-3.9/__init__.py: -------------------------------------------------------------------------------- 1 | """A Python driver for PostgreSQL 2 | 3 | psycopg is a PostgreSQL_ database adapter for the Python_ programming 4 | language. This is version 2, a complete rewrite of the original code to 5 | provide new-style classes for connection and cursor objects and other sweet 6 | candies. Like the original, psycopg 2 was written with the aim of being very 7 | small and fast, and stable as a rock. 8 | 9 | Homepage: https://psycopg.org/ 10 | 11 | .. _PostgreSQL: https://www.postgresql.org/ 12 | .. _Python: https://www.python.org/ 13 | 14 | :Groups: 15 | * `Connections creation`: connect 16 | * `Value objects constructors`: Binary, Date, DateFromTicks, Time, 17 | TimeFromTicks, Timestamp, TimestampFromTicks 18 | """ 19 | # psycopg/__init__.py - initialization of the psycopg module 20 | # 21 | # Copyright (C) 2003-2019 Federico Di Gregorio 22 | # Copyright (C) 2020-2021 The Psycopg Team 23 | # 24 | # psycopg2 is free software: you can redistribute it and/or modify it 25 | # under the terms of the GNU Lesser General Public License as published 26 | # by the Free Software Foundation, either version 3 of the License, or 27 | # (at your option) any later version. 28 | # 29 | # In addition, as a special exception, the copyright holders give 30 | # permission to link this program with the OpenSSL library (or with 31 | # modified versions of OpenSSL that use the same license as OpenSSL), 32 | # and distribute linked combinations including the two. 33 | # 34 | # You must obey the GNU Lesser General Public License in all respects for 35 | # all of the code used other than OpenSSL. 36 | # 37 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 38 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 39 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 40 | # License for more details. 41 | 42 | # Import modules needed by _psycopg to allow tools like py2exe to do 43 | # their work without bothering about the module dependencies. 44 | 45 | # Note: the first internal import should be _psycopg, otherwise the real cause 46 | # of a failed loading of the C module may get hidden, see 47 | # https://archives.postgresql.org/psycopg/2011-02/msg00044.php 48 | 49 | # Import the DBAPI-2.0 stuff into top-level module. 50 | 51 | from psycopg2._psycopg import ( # noqa 52 | BINARY, NUMBER, STRING, DATETIME, ROWID, 53 | 54 | Binary, Date, Time, Timestamp, 55 | DateFromTicks, TimeFromTicks, TimestampFromTicks, 56 | 57 | Error, Warning, DataError, DatabaseError, ProgrammingError, IntegrityError, 58 | InterfaceError, InternalError, NotSupportedError, OperationalError, 59 | 60 | _connect, apilevel, threadsafety, paramstyle, 61 | __version__, __libpq_version__, 62 | ) 63 | 64 | 65 | # Register default adapters. 66 | 67 | from psycopg2 import extensions as _ext 68 | _ext.register_adapter(tuple, _ext.SQL_IN) 69 | _ext.register_adapter(type(None), _ext.NoneAdapter) 70 | 71 | # Register the Decimal adapter here instead of in the C layer. 72 | # This way a new class is registered for each sub-interpreter. 73 | # See ticket #52 74 | from decimal import Decimal # noqa 75 | from psycopg2._psycopg import Decimal as Adapter # noqa 76 | _ext.register_adapter(Decimal, Adapter) 77 | del Decimal, Adapter 78 | 79 | 80 | def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs): 81 | """ 82 | Create a new database connection. 83 | 84 | The connection parameters can be specified as a string: 85 | 86 | conn = psycopg2.connect("dbname=test user=postgres password=secret") 87 | 88 | or using a set of keyword arguments: 89 | 90 | conn = psycopg2.connect(database="test", user="postgres", password="secret") 91 | 92 | Or as a mix of both. The basic connection parameters are: 93 | 94 | - *dbname*: the database name 95 | - *database*: the database name (only as keyword argument) 96 | - *user*: user name used to authenticate 97 | - *password*: password used to authenticate 98 | - *host*: database host address (defaults to UNIX socket if not provided) 99 | - *port*: connection port number (defaults to 5432 if not provided) 100 | 101 | Using the *connection_factory* parameter a different class or connections 102 | factory can be specified. It should be a callable object taking a dsn 103 | argument. 104 | 105 | Using the *cursor_factory* parameter, a new default cursor factory will be 106 | used by cursor(). 107 | 108 | Using *async*=True an asynchronous connection will be created. *async_* is 109 | a valid alias (for Python versions where ``async`` is a keyword). 110 | 111 | Any other keyword parameter will be passed to the underlying client 112 | library: the list of supported parameters depends on the library version. 113 | 114 | """ 115 | kwasync = {} 116 | if 'async' in kwargs: 117 | kwasync['async'] = kwargs.pop('async') 118 | if 'async_' in kwargs: 119 | kwasync['async_'] = kwargs.pop('async_') 120 | 121 | dsn = _ext.make_dsn(dsn, **kwargs) 122 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 123 | if cursor_factory is not None: 124 | conn.cursor_factory = cursor_factory 125 | 126 | return conn 127 | -------------------------------------------------------------------------------- /psycopg2-3.9/_ipaddress.py: -------------------------------------------------------------------------------- 1 | """Implementation of the ipaddres-based network types adaptation 2 | """ 3 | 4 | # psycopg/_ipaddress.py - Ipaddres-based network types adaptation 5 | # 6 | # Copyright (C) 2016-2019 Daniele Varrazzo 7 | # Copyright (C) 2020-2021 The Psycopg Team 8 | # 9 | # psycopg2 is free software: you can redistribute it and/or modify it 10 | # under the terms of the GNU Lesser General Public License as published 11 | # by the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # In addition, as a special exception, the copyright holders give 15 | # permission to link this program with the OpenSSL library (or with 16 | # modified versions of OpenSSL that use the same license as OpenSSL), 17 | # and distribute linked combinations including the two. 18 | # 19 | # You must obey the GNU Lesser General Public License in all respects for 20 | # all of the code used other than OpenSSL. 21 | # 22 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 23 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 25 | # License for more details. 26 | 27 | from psycopg2.extensions import ( 28 | new_type, new_array_type, register_type, register_adapter, QuotedString) 29 | 30 | # The module is imported on register_ipaddress 31 | ipaddress = None 32 | 33 | # The typecasters are created only once 34 | _casters = None 35 | 36 | 37 | def register_ipaddress(conn_or_curs=None): 38 | """ 39 | Register conversion support between `ipaddress` objects and `network types`__. 40 | 41 | :param conn_or_curs: the scope where to register the type casters. 42 | If `!None` register them globally. 43 | 44 | After the function is called, PostgreSQL :sql:`inet` values will be 45 | converted into `~ipaddress.IPv4Interface` or `~ipaddress.IPv6Interface` 46 | objects, :sql:`cidr` values into into `~ipaddress.IPv4Network` or 47 | `~ipaddress.IPv6Network`. 48 | 49 | .. __: https://www.postgresql.org/docs/current/static/datatype-net-types.html 50 | """ 51 | global ipaddress 52 | import ipaddress 53 | 54 | global _casters 55 | if _casters is None: 56 | _casters = _make_casters() 57 | 58 | for c in _casters: 59 | register_type(c, conn_or_curs) 60 | 61 | for t in [ipaddress.IPv4Interface, ipaddress.IPv6Interface, 62 | ipaddress.IPv4Network, ipaddress.IPv6Network]: 63 | register_adapter(t, adapt_ipaddress) 64 | 65 | 66 | def _make_casters(): 67 | inet = new_type((869,), 'INET', cast_interface) 68 | ainet = new_array_type((1041,), 'INET[]', inet) 69 | 70 | cidr = new_type((650,), 'CIDR', cast_network) 71 | acidr = new_array_type((651,), 'CIDR[]', cidr) 72 | 73 | return [inet, ainet, cidr, acidr] 74 | 75 | 76 | def cast_interface(s, cur=None): 77 | if s is None: 78 | return None 79 | # Py2 version force the use of unicode. meh. 80 | return ipaddress.ip_interface(str(s)) 81 | 82 | 83 | def cast_network(s, cur=None): 84 | if s is None: 85 | return None 86 | return ipaddress.ip_network(str(s)) 87 | 88 | 89 | def adapt_ipaddress(obj): 90 | return QuotedString(str(obj)) 91 | -------------------------------------------------------------------------------- /psycopg2-3.9/_psycopg.cpython-39-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2-3.9/_psycopg.cpython-39-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /psycopg2-3.9/errors.py: -------------------------------------------------------------------------------- 1 | """Error classes for PostgreSQL error codes 2 | """ 3 | 4 | # psycopg/errors.py - SQLSTATE and DB-API exceptions 5 | # 6 | # Copyright (C) 2018-2019 Daniele Varrazzo 7 | # Copyright (C) 2020-2021 The Psycopg Team 8 | # 9 | # psycopg2 is free software: you can redistribute it and/or modify it 10 | # under the terms of the GNU Lesser General Public License as published 11 | # by the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # In addition, as a special exception, the copyright holders give 15 | # permission to link this program with the OpenSSL library (or with 16 | # modified versions of OpenSSL that use the same license as OpenSSL), 17 | # and distribute linked combinations including the two. 18 | # 19 | # You must obey the GNU Lesser General Public License in all respects for 20 | # all of the code used other than OpenSSL. 21 | # 22 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 23 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 25 | # License for more details. 26 | 27 | # 28 | # NOTE: the exceptions are injected into this module by the C extention. 29 | # 30 | 31 | 32 | def lookup(code): 33 | """Lookup an error code and return its exception class. 34 | 35 | Raise `!KeyError` if the code is not found. 36 | """ 37 | from psycopg2._psycopg import sqlstate_errors # avoid circular import 38 | return sqlstate_errors[code] 39 | -------------------------------------------------------------------------------- /psycopg2-3.9/tz.py: -------------------------------------------------------------------------------- 1 | """tzinfo implementations for psycopg2 2 | 3 | This module holds two different tzinfo implementations that can be used as 4 | the 'tzinfo' argument to datetime constructors, directly passed to psycopg 5 | functions or used to set the .tzinfo_factory attribute in cursors. 6 | """ 7 | # psycopg/tz.py - tzinfo implementation 8 | # 9 | # Copyright (C) 2003-2019 Federico Di Gregorio 10 | # Copyright (C) 2020-2021 The Psycopg Team 11 | # 12 | # psycopg2 is free software: you can redistribute it and/or modify it 13 | # under the terms of the GNU Lesser General Public License as published 14 | # by the Free Software Foundation, either version 3 of the License, or 15 | # (at your option) any later version. 16 | # 17 | # In addition, as a special exception, the copyright holders give 18 | # permission to link this program with the OpenSSL library (or with 19 | # modified versions of OpenSSL that use the same license as OpenSSL), 20 | # and distribute linked combinations including the two. 21 | # 22 | # You must obey the GNU Lesser General Public License in all respects for 23 | # all of the code used other than OpenSSL. 24 | # 25 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 26 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 27 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 28 | # License for more details. 29 | 30 | import datetime 31 | import time 32 | 33 | ZERO = datetime.timedelta(0) 34 | 35 | 36 | class FixedOffsetTimezone(datetime.tzinfo): 37 | """Fixed offset in minutes east from UTC. 38 | 39 | This is exactly the implementation__ found in Python 2.3.x documentation, 40 | with a small change to the `!__init__()` method to allow for pickling 41 | and a default name in the form ``sHH:MM`` (``s`` is the sign.). 42 | 43 | The implementation also caches instances. During creation, if a 44 | FixedOffsetTimezone instance has previously been created with the same 45 | offset and name that instance will be returned. This saves memory and 46 | improves comparability. 47 | 48 | .. versionchanged:: 2.9 49 | 50 | The constructor can take either a timedelta or a number of minutes of 51 | offset. Previously only minutes were supported. 52 | 53 | .. __: https://docs.python.org/library/datetime.html 54 | """ 55 | _name = None 56 | _offset = ZERO 57 | 58 | _cache = {} 59 | 60 | def __init__(self, offset=None, name=None): 61 | if offset is not None: 62 | if not isinstance(offset, datetime.timedelta): 63 | offset = datetime.timedelta(minutes=offset) 64 | self._offset = offset 65 | if name is not None: 66 | self._name = name 67 | 68 | def __new__(cls, offset=None, name=None): 69 | """Return a suitable instance created earlier if it exists 70 | """ 71 | key = (offset, name) 72 | try: 73 | return cls._cache[key] 74 | except KeyError: 75 | tz = super().__new__(cls, offset, name) 76 | cls._cache[key] = tz 77 | return tz 78 | 79 | def __repr__(self): 80 | return "psycopg2.tz.FixedOffsetTimezone(offset=%r, name=%r)" \ 81 | % (self._offset, self._name) 82 | 83 | def __eq__(self, other): 84 | if isinstance(other, FixedOffsetTimezone): 85 | return self._offset == other._offset 86 | else: 87 | return NotImplemented 88 | 89 | def __ne__(self, other): 90 | if isinstance(other, FixedOffsetTimezone): 91 | return self._offset != other._offset 92 | else: 93 | return NotImplemented 94 | 95 | def __getinitargs__(self): 96 | return self._offset, self._name 97 | 98 | def utcoffset(self, dt): 99 | return self._offset 100 | 101 | def tzname(self, dt): 102 | if self._name is not None: 103 | return self._name 104 | 105 | minutes, seconds = divmod(self._offset.total_seconds(), 60) 106 | hours, minutes = divmod(minutes, 60) 107 | rv = "%+03d" % hours 108 | if minutes or seconds: 109 | rv += ":%02d" % minutes 110 | if seconds: 111 | rv += ":%02d" % seconds 112 | 113 | return rv 114 | 115 | def dst(self, dt): 116 | return ZERO 117 | 118 | 119 | STDOFFSET = datetime.timedelta(seconds=-time.timezone) 120 | if time.daylight: 121 | DSTOFFSET = datetime.timedelta(seconds=-time.altzone) 122 | else: 123 | DSTOFFSET = STDOFFSET 124 | DSTDIFF = DSTOFFSET - STDOFFSET 125 | 126 | 127 | class LocalTimezone(datetime.tzinfo): 128 | """Platform idea of local timezone. 129 | 130 | This is the exact implementation from the Python 2.3 documentation. 131 | """ 132 | def utcoffset(self, dt): 133 | if self._isdst(dt): 134 | return DSTOFFSET 135 | else: 136 | return STDOFFSET 137 | 138 | def dst(self, dt): 139 | if self._isdst(dt): 140 | return DSTDIFF 141 | else: 142 | return ZERO 143 | 144 | def tzname(self, dt): 145 | return time.tzname[self._isdst(dt)] 146 | 147 | def _isdst(self, dt): 148 | tt = (dt.year, dt.month, dt.day, 149 | dt.hour, dt.minute, dt.second, 150 | dt.weekday(), 0, -1) 151 | stamp = time.mktime(tt) 152 | tt = time.localtime(stamp) 153 | return tt.tm_isdst > 0 154 | 155 | 156 | LOCAL = LocalTimezone() 157 | 158 | # TODO: pre-generate some interesting time zones? 159 | -------------------------------------------------------------------------------- /psycopg2/__init__.py: -------------------------------------------------------------------------------- 1 | """A Python driver for PostgreSQL 2 | 3 | psycopg is a PostgreSQL_ database adapter for the Python_ programming 4 | language. This is version 2, a complete rewrite of the original code to 5 | provide new-style classes for connection and cursor objects and other sweet 6 | candies. Like the original, psycopg 2 was written with the aim of being very 7 | small and fast, and stable as a rock. 8 | 9 | Homepage: http://initd.org/projects/psycopg2 10 | 11 | .. _PostgreSQL: http://www.postgresql.org/ 12 | .. _Python: http://www.python.org/ 13 | 14 | :Groups: 15 | * `Connections creation`: connect 16 | * `Value objects constructors`: Binary, Date, DateFromTicks, Time, 17 | TimeFromTicks, Timestamp, TimestampFromTicks 18 | """ 19 | # psycopg/__init__.py - initialization of the psycopg module 20 | # 21 | # Copyright (C) 2003-2010 Federico Di Gregorio 22 | # 23 | # psycopg2 is free software: you can redistribute it and/or modify it 24 | # under the terms of the GNU Lesser General Public License as published 25 | # by the Free Software Foundation, either version 3 of the License, or 26 | # (at your option) any later version. 27 | # 28 | # In addition, as a special exception, the copyright holders give 29 | # permission to link this program with the OpenSSL library (or with 30 | # modified versions of OpenSSL that use the same license as OpenSSL), 31 | # and distribute linked combinations including the two. 32 | # 33 | # You must obey the GNU Lesser General Public License in all respects for 34 | # all of the code used other than OpenSSL. 35 | # 36 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 37 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 38 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 39 | # License for more details. 40 | 41 | # Import modules needed by _psycopg to allow tools like py2exe to do 42 | # their work without bothering about the module dependencies. 43 | 44 | # Note: the first internal import should be _psycopg, otherwise the real cause 45 | # of a failed loading of the C module may get hidden, see 46 | # http://archives.postgresql.org/psycopg/2011-02/msg00044.php 47 | 48 | # Import the DBAPI-2.0 stuff into top-level module. 49 | 50 | from psycopg2._psycopg import ( # noqa 51 | BINARY, NUMBER, STRING, DATETIME, ROWID, 52 | 53 | Binary, Date, Time, Timestamp, 54 | DateFromTicks, TimeFromTicks, TimestampFromTicks, 55 | 56 | Error, Warning, DataError, DatabaseError, ProgrammingError, IntegrityError, 57 | InterfaceError, InternalError, NotSupportedError, OperationalError, 58 | 59 | _connect, apilevel, threadsafety, paramstyle, 60 | __version__, __libpq_version__, 61 | ) 62 | 63 | from psycopg2 import tz # noqa 64 | 65 | 66 | # Register default adapters. 67 | 68 | import psycopg2.extensions as _ext 69 | _ext.register_adapter(tuple, _ext.SQL_IN) 70 | _ext.register_adapter(type(None), _ext.NoneAdapter) 71 | 72 | # Register the Decimal adapter here instead of in the C layer. 73 | # This way a new class is registered for each sub-interpreter. 74 | # See ticket #52 75 | try: 76 | from decimal import Decimal 77 | except ImportError: 78 | pass 79 | else: 80 | from psycopg2._psycopg import Decimal as Adapter 81 | _ext.register_adapter(Decimal, Adapter) 82 | del Decimal, Adapter 83 | 84 | 85 | def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs): 86 | """ 87 | Create a new database connection. 88 | 89 | The connection parameters can be specified as a string: 90 | 91 | conn = psycopg2.connect("dbname=test user=postgres password=secret") 92 | 93 | or using a set of keyword arguments: 94 | 95 | conn = psycopg2.connect(database="test", user="postgres", password="secret") 96 | 97 | Or as a mix of both. The basic connection parameters are: 98 | 99 | - *dbname*: the database name 100 | - *database*: the database name (only as keyword argument) 101 | - *user*: user name used to authenticate 102 | - *password*: password used to authenticate 103 | - *host*: database host address (defaults to UNIX socket if not provided) 104 | - *port*: connection port number (defaults to 5432 if not provided) 105 | 106 | Using the *connection_factory* parameter a different class or connections 107 | factory can be specified. It should be a callable object taking a dsn 108 | argument. 109 | 110 | Using the *cursor_factory* parameter, a new default cursor factory will be 111 | used by cursor(). 112 | 113 | Using *async*=True an asynchronous connection will be created. *async_* is 114 | a valid alias (for Python versions where ``async`` is a keyword). 115 | 116 | Any other keyword parameter will be passed to the underlying client 117 | library: the list of supported parameters depends on the library version. 118 | 119 | """ 120 | kwasync = {} 121 | if 'async' in kwargs: 122 | kwasync['async'] = kwargs.pop('async') 123 | if 'async_' in kwargs: 124 | kwasync['async_'] = kwargs.pop('async_') 125 | 126 | if dsn is None and not kwargs: 127 | raise TypeError('missing dsn and no parameters') 128 | 129 | dsn = _ext.make_dsn(dsn, **kwargs) 130 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 131 | if cursor_factory is not None: 132 | conn.cursor_factory = cursor_factory 133 | 134 | return conn 135 | -------------------------------------------------------------------------------- /psycopg2/_ipaddress.py: -------------------------------------------------------------------------------- 1 | """Implementation of the ipaddres-based network types adaptation 2 | """ 3 | 4 | # psycopg/_ipaddress.py - Ipaddres-based network types adaptation 5 | # 6 | # Copyright (C) 2016 Daniele Varrazzo 7 | # 8 | # psycopg2 is free software: you can redistribute it and/or modify it 9 | # under the terms of the GNU Lesser General Public License as published 10 | # by the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # In addition, as a special exception, the copyright holders give 14 | # permission to link this program with the OpenSSL library (or with 15 | # modified versions of OpenSSL that use the same license as OpenSSL), 16 | # and distribute linked combinations including the two. 17 | # 18 | # You must obey the GNU Lesser General Public License in all respects for 19 | # all of the code used other than OpenSSL. 20 | # 21 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 22 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 24 | # License for more details. 25 | 26 | from psycopg2.extensions import ( 27 | new_type, new_array_type, register_type, register_adapter, QuotedString) 28 | 29 | # The module is imported on register_ipaddress 30 | ipaddress = None 31 | 32 | # The typecasters are created only once 33 | _casters = None 34 | 35 | 36 | def register_ipaddress(conn_or_curs=None): 37 | """ 38 | Register conversion support between `ipaddress` objects and `network types`__. 39 | 40 | :param conn_or_curs: the scope where to register the type casters. 41 | If `!None` register them globally. 42 | 43 | After the function is called, PostgreSQL :sql:`inet` values will be 44 | converted into `~ipaddress.IPv4Interface` or `~ipaddress.IPv6Interface` 45 | objects, :sql:`cidr` values into into `~ipaddress.IPv4Network` or 46 | `~ipaddress.IPv6Network`. 47 | 48 | .. __: https://www.postgresql.org/docs/current/static/datatype-net-types.html 49 | """ 50 | global ipaddress 51 | import ipaddress 52 | 53 | global _casters 54 | if _casters is None: 55 | _casters = _make_casters() 56 | 57 | for c in _casters: 58 | register_type(c, conn_or_curs) 59 | 60 | for t in [ipaddress.IPv4Interface, ipaddress.IPv6Interface, 61 | ipaddress.IPv4Network, ipaddress.IPv6Network]: 62 | register_adapter(t, adapt_ipaddress) 63 | 64 | 65 | def _make_casters(): 66 | inet = new_type((869,), 'INET', cast_interface) 67 | ainet = new_array_type((1041,), 'INET[]', inet) 68 | 69 | cidr = new_type((650,), 'CIDR', cast_network) 70 | acidr = new_array_type((651,), 'CIDR[]', cidr) 71 | 72 | return [inet, ainet, cidr, acidr] 73 | 74 | 75 | def cast_interface(s, cur=None): 76 | if s is None: 77 | return None 78 | # Py2 version force the use of unicode. meh. 79 | return ipaddress.ip_interface(unicode(s)) 80 | 81 | 82 | def cast_network(s, cur=None): 83 | if s is None: 84 | return None 85 | return ipaddress.ip_network(unicode(s)) 86 | 87 | 88 | def adapt_ipaddress(obj): 89 | return QuotedString(str(obj)) 90 | -------------------------------------------------------------------------------- /psycopg2/_psycopg.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/psycopg2/_psycopg.so -------------------------------------------------------------------------------- /psycopg2/psycopg1.py: -------------------------------------------------------------------------------- 1 | """psycopg 1.1.x compatibility module 2 | 3 | This module uses the new style connection and cursor types to build a psycopg 4 | 1.1.1.x compatibility layer. It should be considered a temporary hack to run 5 | old code while porting to psycopg 2. Import it as follows:: 6 | 7 | from psycopg2 import psycopg1 as psycopg 8 | """ 9 | # psycopg/psycopg1.py - psycopg 1.1.x compatibility module 10 | # 11 | # Copyright (C) 2003-2010 Federico Di Gregorio 12 | # 13 | # psycopg2 is free software: you can redistribute it and/or modify it 14 | # under the terms of the GNU Lesser General Public License as published 15 | # by the Free Software Foundation, either version 3 of the License, or 16 | # (at your option) any later version. 17 | # 18 | # In addition, as a special exception, the copyright holders give 19 | # permission to link this program with the OpenSSL library (or with 20 | # modified versions of OpenSSL that use the same license as OpenSSL), 21 | # and distribute linked combinations including the two. 22 | # 23 | # You must obey the GNU Lesser General Public License in all respects for 24 | # all of the code used other than OpenSSL. 25 | # 26 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 27 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 28 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 29 | # License for more details. 30 | 31 | import psycopg2._psycopg as _2psycopg # noqa 32 | from psycopg2.extensions import cursor as _2cursor 33 | from psycopg2.extensions import connection as _2connection 34 | 35 | from psycopg2 import * # noqa 36 | import psycopg2.extensions as _ext 37 | _2connect = connect 38 | 39 | 40 | def connect(*args, **kwargs): 41 | """connect(dsn, ...) -> new psycopg 1.1.x compatible connection object""" 42 | kwargs['connection_factory'] = connection 43 | conn = _2connect(*args, **kwargs) 44 | conn.set_isolation_level(_ext.ISOLATION_LEVEL_READ_COMMITTED) 45 | return conn 46 | 47 | 48 | class connection(_2connection): 49 | """psycopg 1.1.x connection.""" 50 | 51 | def cursor(self): 52 | """cursor() -> new psycopg 1.1.x compatible cursor object""" 53 | return _2connection.cursor(self, cursor_factory=cursor) 54 | 55 | def autocommit(self, on_off=1): 56 | """autocommit(on_off=1) -> switch autocommit on (1) or off (0)""" 57 | if on_off > 0: 58 | self.set_isolation_level(_ext.ISOLATION_LEVEL_AUTOCOMMIT) 59 | else: 60 | self.set_isolation_level(_ext.ISOLATION_LEVEL_READ_COMMITTED) 61 | 62 | 63 | class cursor(_2cursor): 64 | """psycopg 1.1.x cursor. 65 | 66 | Note that this cursor implements the exact procedure used by psycopg 1 to 67 | build dictionaries out of result rows. The DictCursor in the 68 | psycopg.extras modules implements a much better and faster algorithm. 69 | """ 70 | 71 | def __build_dict(self, row): 72 | res = {} 73 | for i in range(len(self.description)): 74 | res[self.description[i][0]] = row[i] 75 | return res 76 | 77 | def dictfetchone(self): 78 | row = _2cursor.fetchone(self) 79 | if row: 80 | return self.__build_dict(row) 81 | else: 82 | return row 83 | 84 | def dictfetchmany(self, size): 85 | res = [] 86 | rows = _2cursor.fetchmany(self, size) 87 | for row in rows: 88 | res.append(self.__build_dict(row)) 89 | return res 90 | 91 | def dictfetchall(self): 92 | res = [] 93 | rows = _2cursor.fetchall(self) 94 | for row in rows: 95 | res.append(self.__build_dict(row)) 96 | return res 97 | -------------------------------------------------------------------------------- /psycopg2/tz.py: -------------------------------------------------------------------------------- 1 | """tzinfo implementations for psycopg2 2 | 3 | This module holds two different tzinfo implementations that can be used as 4 | the 'tzinfo' argument to datetime constructors, directly passed to psycopg 5 | functions or used to set the .tzinfo_factory attribute in cursors. 6 | """ 7 | # psycopg/tz.py - tzinfo implementation 8 | # 9 | # Copyright (C) 2003-2010 Federico Di Gregorio 10 | # 11 | # psycopg2 is free software: you can redistribute it and/or modify it 12 | # under the terms of the GNU Lesser General Public License as published 13 | # by the Free Software Foundation, either version 3 of the License, or 14 | # (at your option) any later version. 15 | # 16 | # In addition, as a special exception, the copyright holders give 17 | # permission to link this program with the OpenSSL library (or with 18 | # modified versions of OpenSSL that use the same license as OpenSSL), 19 | # and distribute linked combinations including the two. 20 | # 21 | # You must obey the GNU Lesser General Public License in all respects for 22 | # all of the code used other than OpenSSL. 23 | # 24 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 25 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 26 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 27 | # License for more details. 28 | 29 | import datetime 30 | import time 31 | 32 | ZERO = datetime.timedelta(0) 33 | 34 | 35 | class FixedOffsetTimezone(datetime.tzinfo): 36 | """Fixed offset in minutes east from UTC. 37 | 38 | This is exactly the implementation__ found in Python 2.3.x documentation, 39 | with a small change to the `!__init__()` method to allow for pickling 40 | and a default name in the form ``sHH:MM`` (``s`` is the sign.). 41 | 42 | The implementation also caches instances. During creation, if a 43 | FixedOffsetTimezone instance has previously been created with the same 44 | offset and name that instance will be returned. This saves memory and 45 | improves comparability. 46 | 47 | .. __: http://docs.python.org/library/datetime.html#datetime-tzinfo 48 | """ 49 | _name = None 50 | _offset = ZERO 51 | 52 | _cache = {} 53 | 54 | def __init__(self, offset=None, name=None): 55 | if offset is not None: 56 | self._offset = datetime.timedelta(minutes=offset) 57 | if name is not None: 58 | self._name = name 59 | 60 | def __new__(cls, offset=None, name=None): 61 | """Return a suitable instance created earlier if it exists 62 | """ 63 | key = (offset, name) 64 | try: 65 | return cls._cache[key] 66 | except KeyError: 67 | tz = super(FixedOffsetTimezone, cls).__new__(cls, offset, name) 68 | cls._cache[key] = tz 69 | return tz 70 | 71 | def __repr__(self): 72 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 73 | return "psycopg2.tz.FixedOffsetTimezone(offset=%r, name=%r)" \ 74 | % (offset_mins, self._name) 75 | 76 | def __getinitargs__(self): 77 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 78 | return (offset_mins, self._name) 79 | 80 | def utcoffset(self, dt): 81 | return self._offset 82 | 83 | def tzname(self, dt): 84 | if self._name is not None: 85 | return self._name 86 | else: 87 | seconds = self._offset.seconds + self._offset.days * 86400 88 | hours, seconds = divmod(seconds, 3600) 89 | minutes = seconds / 60 90 | if minutes: 91 | return "%+03d:%d" % (hours, minutes) 92 | else: 93 | return "%+03d" % hours 94 | 95 | def dst(self, dt): 96 | return ZERO 97 | 98 | 99 | STDOFFSET = datetime.timedelta(seconds=-time.timezone) 100 | if time.daylight: 101 | DSTOFFSET = datetime.timedelta(seconds=-time.altzone) 102 | else: 103 | DSTOFFSET = STDOFFSET 104 | DSTDIFF = DSTOFFSET - STDOFFSET 105 | 106 | 107 | class LocalTimezone(datetime.tzinfo): 108 | """Platform idea of local timezone. 109 | 110 | This is the exact implementation from the Python 2.3 documentation. 111 | """ 112 | def utcoffset(self, dt): 113 | if self._isdst(dt): 114 | return DSTOFFSET 115 | else: 116 | return STDOFFSET 117 | 118 | def dst(self, dt): 119 | if self._isdst(dt): 120 | return DSTDIFF 121 | else: 122 | return ZERO 123 | 124 | def tzname(self, dt): 125 | return time.tzname[self._isdst(dt)] 126 | 127 | def _isdst(self, dt): 128 | tt = (dt.year, dt.month, dt.day, 129 | dt.hour, dt.minute, dt.second, 130 | dt.weekday(), 0, -1) 131 | stamp = time.mktime(tt) 132 | tt = time.localtime(stamp) 133 | return tt.tm_isdst > 0 134 | 135 | LOCAL = LocalTimezone() 136 | 137 | # TODO: pre-generate some interesting time zones? 138 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.6/__init__.py: -------------------------------------------------------------------------------- 1 | """A Python driver for PostgreSQL 2 | 3 | psycopg is a PostgreSQL_ database adapter for the Python_ programming 4 | language. This is version 2, a complete rewrite of the original code to 5 | provide new-style classes for connection and cursor objects and other sweet 6 | candies. Like the original, psycopg 2 was written with the aim of being very 7 | small and fast, and stable as a rock. 8 | 9 | Homepage: http://initd.org/projects/psycopg2 10 | 11 | .. _PostgreSQL: http://www.postgresql.org/ 12 | .. _Python: http://www.python.org/ 13 | 14 | :Groups: 15 | * `Connections creation`: connect 16 | * `Value objects constructors`: Binary, Date, DateFromTicks, Time, 17 | TimeFromTicks, Timestamp, TimestampFromTicks 18 | """ 19 | # psycopg/__init__.py - initialization of the psycopg module 20 | # 21 | # Copyright (C) 2003-2010 Federico Di Gregorio 22 | # 23 | # psycopg2 is free software: you can redistribute it and/or modify it 24 | # under the terms of the GNU Lesser General Public License as published 25 | # by the Free Software Foundation, either version 3 of the License, or 26 | # (at your option) any later version. 27 | # 28 | # In addition, as a special exception, the copyright holders give 29 | # permission to link this program with the OpenSSL library (or with 30 | # modified versions of OpenSSL that use the same license as OpenSSL), 31 | # and distribute linked combinations including the two. 32 | # 33 | # You must obey the GNU Lesser General Public License in all respects for 34 | # all of the code used other than OpenSSL. 35 | # 36 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 37 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 38 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 39 | # License for more details. 40 | 41 | # Import modules needed by _psycopg to allow tools like py2exe to do 42 | # their work without bothering about the module dependencies. 43 | 44 | # Note: the first internal import should be _psycopg, otherwise the real cause 45 | # of a failed loading of the C module may get hidden, see 46 | # http://archives.postgresql.org/psycopg/2011-02/msg00044.php 47 | 48 | # Import the DBAPI-2.0 stuff into top-level module. 49 | 50 | from psycopg2._psycopg import ( # noqa 51 | BINARY, NUMBER, STRING, DATETIME, ROWID, 52 | 53 | Binary, Date, Time, Timestamp, 54 | DateFromTicks, TimeFromTicks, TimestampFromTicks, 55 | 56 | Error, Warning, DataError, DatabaseError, ProgrammingError, IntegrityError, 57 | InterfaceError, InternalError, NotSupportedError, OperationalError, 58 | 59 | _connect, apilevel, threadsafety, paramstyle, 60 | __version__, __libpq_version__, 61 | ) 62 | 63 | from psycopg2 import tz # noqa 64 | 65 | 66 | # Register default adapters. 67 | 68 | import psycopg2.extensions as _ext 69 | _ext.register_adapter(tuple, _ext.SQL_IN) 70 | _ext.register_adapter(type(None), _ext.NoneAdapter) 71 | 72 | # Register the Decimal adapter here instead of in the C layer. 73 | # This way a new class is registered for each sub-interpreter. 74 | # See ticket #52 75 | try: 76 | from decimal import Decimal 77 | except ImportError: 78 | pass 79 | else: 80 | from psycopg2._psycopg import Decimal as Adapter 81 | _ext.register_adapter(Decimal, Adapter) 82 | del Decimal, Adapter 83 | 84 | 85 | def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs): 86 | """ 87 | Create a new database connection. 88 | 89 | The connection parameters can be specified as a string: 90 | 91 | conn = psycopg2.connect("dbname=test user=postgres password=secret") 92 | 93 | or using a set of keyword arguments: 94 | 95 | conn = psycopg2.connect(database="test", user="postgres", password="secret") 96 | 97 | Or as a mix of both. The basic connection parameters are: 98 | 99 | - *dbname*: the database name 100 | - *database*: the database name (only as keyword argument) 101 | - *user*: user name used to authenticate 102 | - *password*: password used to authenticate 103 | - *host*: database host address (defaults to UNIX socket if not provided) 104 | - *port*: connection port number (defaults to 5432 if not provided) 105 | 106 | Using the *connection_factory* parameter a different class or connections 107 | factory can be specified. It should be a callable object taking a dsn 108 | argument. 109 | 110 | Using the *cursor_factory* parameter, a new default cursor factory will be 111 | used by cursor(). 112 | 113 | Using *async*=True an asynchronous connection will be created. *async_* is 114 | a valid alias (for Python versions where ``async`` is a keyword). 115 | 116 | Any other keyword parameter will be passed to the underlying client 117 | library: the list of supported parameters depends on the library version. 118 | 119 | """ 120 | kwasync = {} 121 | if 'async' in kwargs: 122 | kwasync['async'] = kwargs.pop('async') 123 | if 'async_' in kwargs: 124 | kwasync['async_'] = kwargs.pop('async_') 125 | 126 | if dsn is None and not kwargs: 127 | raise TypeError('missing dsn and no parameters') 128 | 129 | dsn = _ext.make_dsn(dsn, **kwargs) 130 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 131 | if cursor_factory is not None: 132 | conn.cursor_factory = cursor_factory 133 | 134 | return conn 135 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.6/_ipaddress.py: -------------------------------------------------------------------------------- 1 | """Implementation of the ipaddres-based network types adaptation 2 | """ 3 | 4 | # psycopg/_ipaddress.py - Ipaddres-based network types adaptation 5 | # 6 | # Copyright (C) 2016 Daniele Varrazzo 7 | # 8 | # psycopg2 is free software: you can redistribute it and/or modify it 9 | # under the terms of the GNU Lesser General Public License as published 10 | # by the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # In addition, as a special exception, the copyright holders give 14 | # permission to link this program with the OpenSSL library (or with 15 | # modified versions of OpenSSL that use the same license as OpenSSL), 16 | # and distribute linked combinations including the two. 17 | # 18 | # You must obey the GNU Lesser General Public License in all respects for 19 | # all of the code used other than OpenSSL. 20 | # 21 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 22 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 24 | # License for more details. 25 | 26 | from psycopg2.extensions import ( 27 | new_type, new_array_type, register_type, register_adapter, QuotedString) 28 | 29 | # The module is imported on register_ipaddress 30 | ipaddress = None 31 | 32 | # The typecasters are created only once 33 | _casters = None 34 | 35 | 36 | def register_ipaddress(conn_or_curs=None): 37 | """ 38 | Register conversion support between `ipaddress` objects and `network types`__. 39 | 40 | :param conn_or_curs: the scope where to register the type casters. 41 | If `!None` register them globally. 42 | 43 | After the function is called, PostgreSQL :sql:`inet` values will be 44 | converted into `~ipaddress.IPv4Interface` or `~ipaddress.IPv6Interface` 45 | objects, :sql:`cidr` values into into `~ipaddress.IPv4Network` or 46 | `~ipaddress.IPv6Network`. 47 | 48 | .. __: https://www.postgresql.org/docs/current/static/datatype-net-types.html 49 | """ 50 | global ipaddress 51 | import ipaddress 52 | 53 | global _casters 54 | if _casters is None: 55 | _casters = _make_casters() 56 | 57 | for c in _casters: 58 | register_type(c, conn_or_curs) 59 | 60 | for t in [ipaddress.IPv4Interface, ipaddress.IPv6Interface, 61 | ipaddress.IPv4Network, ipaddress.IPv6Network]: 62 | register_adapter(t, adapt_ipaddress) 63 | 64 | 65 | def _make_casters(): 66 | inet = new_type((869,), 'INET', cast_interface) 67 | ainet = new_array_type((1041,), 'INET[]', inet) 68 | 69 | cidr = new_type((650,), 'CIDR', cast_network) 70 | acidr = new_array_type((651,), 'CIDR[]', cidr) 71 | 72 | return [inet, ainet, cidr, acidr] 73 | 74 | 75 | def cast_interface(s, cur=None): 76 | if s is None: 77 | return None 78 | # Py2 version force the use of unicode. meh. 79 | return ipaddress.ip_interface(str(s)) 80 | 81 | 82 | def cast_network(s, cur=None): 83 | if s is None: 84 | return None 85 | return ipaddress.ip_network(str(s)) 86 | 87 | 88 | def adapt_ipaddress(obj): 89 | return QuotedString(str(obj)) 90 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.6/_psycopg.cpython-36m-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/with_ssl_support/psycopg2-3.6/_psycopg.cpython-36m-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.6/psycopg1.py: -------------------------------------------------------------------------------- 1 | """psycopg 1.1.x compatibility module 2 | 3 | This module uses the new style connection and cursor types to build a psycopg 4 | 1.1.1.x compatibility layer. It should be considered a temporary hack to run 5 | old code while porting to psycopg 2. Import it as follows:: 6 | 7 | from psycopg2 import psycopg1 as psycopg 8 | """ 9 | # psycopg/psycopg1.py - psycopg 1.1.x compatibility module 10 | # 11 | # Copyright (C) 2003-2010 Federico Di Gregorio 12 | # 13 | # psycopg2 is free software: you can redistribute it and/or modify it 14 | # under the terms of the GNU Lesser General Public License as published 15 | # by the Free Software Foundation, either version 3 of the License, or 16 | # (at your option) any later version. 17 | # 18 | # In addition, as a special exception, the copyright holders give 19 | # permission to link this program with the OpenSSL library (or with 20 | # modified versions of OpenSSL that use the same license as OpenSSL), 21 | # and distribute linked combinations including the two. 22 | # 23 | # You must obey the GNU Lesser General Public License in all respects for 24 | # all of the code used other than OpenSSL. 25 | # 26 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 27 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 28 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 29 | # License for more details. 30 | 31 | import psycopg2._psycopg as _2psycopg # noqa 32 | from psycopg2.extensions import cursor as _2cursor 33 | from psycopg2.extensions import connection as _2connection 34 | 35 | from psycopg2 import * # noqa 36 | import psycopg2.extensions as _ext 37 | _2connect = connect 38 | 39 | 40 | def connect(*args, **kwargs): 41 | """connect(dsn, ...) -> new psycopg 1.1.x compatible connection object""" 42 | kwargs['connection_factory'] = connection 43 | conn = _2connect(*args, **kwargs) 44 | conn.set_isolation_level(_ext.ISOLATION_LEVEL_READ_COMMITTED) 45 | return conn 46 | 47 | 48 | class connection(_2connection): 49 | """psycopg 1.1.x connection.""" 50 | 51 | def cursor(self): 52 | """cursor() -> new psycopg 1.1.x compatible cursor object""" 53 | return _2connection.cursor(self, cursor_factory=cursor) 54 | 55 | def autocommit(self, on_off=1): 56 | """autocommit(on_off=1) -> switch autocommit on (1) or off (0)""" 57 | if on_off > 0: 58 | self.set_isolation_level(_ext.ISOLATION_LEVEL_AUTOCOMMIT) 59 | else: 60 | self.set_isolation_level(_ext.ISOLATION_LEVEL_READ_COMMITTED) 61 | 62 | 63 | class cursor(_2cursor): 64 | """psycopg 1.1.x cursor. 65 | 66 | Note that this cursor implements the exact procedure used by psycopg 1 to 67 | build dictionaries out of result rows. The DictCursor in the 68 | psycopg.extras modules implements a much better and faster algorithm. 69 | """ 70 | 71 | def __build_dict(self, row): 72 | res = {} 73 | for i in range(len(self.description)): 74 | res[self.description[i][0]] = row[i] 75 | return res 76 | 77 | def dictfetchone(self): 78 | row = _2cursor.fetchone(self) 79 | if row: 80 | return self.__build_dict(row) 81 | else: 82 | return row 83 | 84 | def dictfetchmany(self, size): 85 | res = [] 86 | rows = _2cursor.fetchmany(self, size) 87 | for row in rows: 88 | res.append(self.__build_dict(row)) 89 | return res 90 | 91 | def dictfetchall(self): 92 | res = [] 93 | rows = _2cursor.fetchall(self) 94 | for row in rows: 95 | res.append(self.__build_dict(row)) 96 | return res 97 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.6/tz.py: -------------------------------------------------------------------------------- 1 | """tzinfo implementations for psycopg2 2 | 3 | This module holds two different tzinfo implementations that can be used as 4 | the 'tzinfo' argument to datetime constructors, directly passed to psycopg 5 | functions or used to set the .tzinfo_factory attribute in cursors. 6 | """ 7 | # psycopg/tz.py - tzinfo implementation 8 | # 9 | # Copyright (C) 2003-2010 Federico Di Gregorio 10 | # 11 | # psycopg2 is free software: you can redistribute it and/or modify it 12 | # under the terms of the GNU Lesser General Public License as published 13 | # by the Free Software Foundation, either version 3 of the License, or 14 | # (at your option) any later version. 15 | # 16 | # In addition, as a special exception, the copyright holders give 17 | # permission to link this program with the OpenSSL library (or with 18 | # modified versions of OpenSSL that use the same license as OpenSSL), 19 | # and distribute linked combinations including the two. 20 | # 21 | # You must obey the GNU Lesser General Public License in all respects for 22 | # all of the code used other than OpenSSL. 23 | # 24 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 25 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 26 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 27 | # License for more details. 28 | 29 | import datetime 30 | import time 31 | 32 | ZERO = datetime.timedelta(0) 33 | 34 | 35 | class FixedOffsetTimezone(datetime.tzinfo): 36 | """Fixed offset in minutes east from UTC. 37 | 38 | This is exactly the implementation__ found in Python 2.3.x documentation, 39 | with a small change to the `!__init__()` method to allow for pickling 40 | and a default name in the form ``sHH:MM`` (``s`` is the sign.). 41 | 42 | The implementation also caches instances. During creation, if a 43 | FixedOffsetTimezone instance has previously been created with the same 44 | offset and name that instance will be returned. This saves memory and 45 | improves comparability. 46 | 47 | .. __: http://docs.python.org/library/datetime.html#datetime-tzinfo 48 | """ 49 | _name = None 50 | _offset = ZERO 51 | 52 | _cache = {} 53 | 54 | def __init__(self, offset=None, name=None): 55 | if offset is not None: 56 | self._offset = datetime.timedelta(minutes=offset) 57 | if name is not None: 58 | self._name = name 59 | 60 | def __new__(cls, offset=None, name=None): 61 | """Return a suitable instance created earlier if it exists 62 | """ 63 | key = (offset, name) 64 | try: 65 | return cls._cache[key] 66 | except KeyError: 67 | tz = super(FixedOffsetTimezone, cls).__new__(cls, offset, name) 68 | cls._cache[key] = tz 69 | return tz 70 | 71 | def __repr__(self): 72 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 73 | return "psycopg2.tz.FixedOffsetTimezone(offset=%r, name=%r)" \ 74 | % (offset_mins, self._name) 75 | 76 | def __getinitargs__(self): 77 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 78 | return (offset_mins, self._name) 79 | 80 | def utcoffset(self, dt): 81 | return self._offset 82 | 83 | def tzname(self, dt): 84 | if self._name is not None: 85 | return self._name 86 | else: 87 | seconds = self._offset.seconds + self._offset.days * 86400 88 | hours, seconds = divmod(seconds, 3600) 89 | minutes = seconds / 60 90 | if minutes: 91 | return "%+03d:%d" % (hours, minutes) 92 | else: 93 | return "%+03d" % hours 94 | 95 | def dst(self, dt): 96 | return ZERO 97 | 98 | 99 | STDOFFSET = datetime.timedelta(seconds=-time.timezone) 100 | if time.daylight: 101 | DSTOFFSET = datetime.timedelta(seconds=-time.altzone) 102 | else: 103 | DSTOFFSET = STDOFFSET 104 | DSTDIFF = DSTOFFSET - STDOFFSET 105 | 106 | 107 | class LocalTimezone(datetime.tzinfo): 108 | """Platform idea of local timezone. 109 | 110 | This is the exact implementation from the Python 2.3 documentation. 111 | """ 112 | def utcoffset(self, dt): 113 | if self._isdst(dt): 114 | return DSTOFFSET 115 | else: 116 | return STDOFFSET 117 | 118 | def dst(self, dt): 119 | if self._isdst(dt): 120 | return DSTDIFF 121 | else: 122 | return ZERO 123 | 124 | def tzname(self, dt): 125 | return time.tzname[self._isdst(dt)] 126 | 127 | def _isdst(self, dt): 128 | tt = (dt.year, dt.month, dt.day, 129 | dt.hour, dt.minute, dt.second, 130 | dt.weekday(), 0, -1) 131 | stamp = time.mktime(tt) 132 | tt = time.localtime(stamp) 133 | return tt.tm_isdst > 0 134 | 135 | LOCAL = LocalTimezone() 136 | 137 | # TODO: pre-generate some interesting time zones? 138 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.7/__init__.py: -------------------------------------------------------------------------------- 1 | """A Python driver for PostgreSQL 2 | 3 | psycopg is a PostgreSQL_ database adapter for the Python_ programming 4 | language. This is version 2, a complete rewrite of the original code to 5 | provide new-style classes for connection and cursor objects and other sweet 6 | candies. Like the original, psycopg 2 was written with the aim of being very 7 | small and fast, and stable as a rock. 8 | 9 | Homepage: http://initd.org/projects/psycopg2 10 | 11 | .. _PostgreSQL: https://www.postgresql.org/ 12 | .. _Python: https://www.python.org/ 13 | 14 | :Groups: 15 | * `Connections creation`: connect 16 | * `Value objects constructors`: Binary, Date, DateFromTicks, Time, 17 | TimeFromTicks, Timestamp, TimestampFromTicks 18 | """ 19 | # psycopg/__init__.py - initialization of the psycopg module 20 | # 21 | # Copyright (C) 2003-2019 Federico Di Gregorio 22 | # 23 | # psycopg2 is free software: you can redistribute it and/or modify it 24 | # under the terms of the GNU Lesser General Public License as published 25 | # by the Free Software Foundation, either version 3 of the License, or 26 | # (at your option) any later version. 27 | # 28 | # In addition, as a special exception, the copyright holders give 29 | # permission to link this program with the OpenSSL library (or with 30 | # modified versions of OpenSSL that use the same license as OpenSSL), 31 | # and distribute linked combinations including the two. 32 | # 33 | # You must obey the GNU Lesser General Public License in all respects for 34 | # all of the code used other than OpenSSL. 35 | # 36 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 37 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 38 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 39 | # License for more details. 40 | 41 | # Import modules needed by _psycopg to allow tools like py2exe to do 42 | # their work without bothering about the module dependencies. 43 | 44 | # Note: the first internal import should be _psycopg, otherwise the real cause 45 | # of a failed loading of the C module may get hidden, see 46 | # https://archives.postgresql.org/psycopg/2011-02/msg00044.php 47 | 48 | # Import the DBAPI-2.0 stuff into top-level module. 49 | 50 | from psycopg2._psycopg import ( # noqa 51 | BINARY, NUMBER, STRING, DATETIME, ROWID, 52 | 53 | Binary, Date, Time, Timestamp, 54 | DateFromTicks, TimeFromTicks, TimestampFromTicks, 55 | 56 | Error, Warning, DataError, DatabaseError, ProgrammingError, IntegrityError, 57 | InterfaceError, InternalError, NotSupportedError, OperationalError, 58 | 59 | _connect, apilevel, threadsafety, paramstyle, 60 | __version__, __libpq_version__, 61 | ) 62 | 63 | from psycopg2 import tz # noqa 64 | 65 | 66 | # Register default adapters. 67 | 68 | from psycopg2 import extensions as _ext 69 | _ext.register_adapter(tuple, _ext.SQL_IN) 70 | _ext.register_adapter(type(None), _ext.NoneAdapter) 71 | 72 | # Register the Decimal adapter here instead of in the C layer. 73 | # This way a new class is registered for each sub-interpreter. 74 | # See ticket #52 75 | from decimal import Decimal # noqa 76 | from psycopg2._psycopg import Decimal as Adapter # noqa 77 | _ext.register_adapter(Decimal, Adapter) 78 | del Decimal, Adapter 79 | 80 | 81 | def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs): 82 | """ 83 | Create a new database connection. 84 | 85 | The connection parameters can be specified as a string: 86 | 87 | conn = psycopg2.connect("dbname=test user=postgres password=secret") 88 | 89 | or using a set of keyword arguments: 90 | 91 | conn = psycopg2.connect(database="test", user="postgres", password="secret") 92 | 93 | Or as a mix of both. The basic connection parameters are: 94 | 95 | - *dbname*: the database name 96 | - *database*: the database name (only as keyword argument) 97 | - *user*: user name used to authenticate 98 | - *password*: password used to authenticate 99 | - *host*: database host address (defaults to UNIX socket if not provided) 100 | - *port*: connection port number (defaults to 5432 if not provided) 101 | 102 | Using the *connection_factory* parameter a different class or connections 103 | factory can be specified. It should be a callable object taking a dsn 104 | argument. 105 | 106 | Using the *cursor_factory* parameter, a new default cursor factory will be 107 | used by cursor(). 108 | 109 | Using *async*=True an asynchronous connection will be created. *async_* is 110 | a valid alias (for Python versions where ``async`` is a keyword). 111 | 112 | Any other keyword parameter will be passed to the underlying client 113 | library: the list of supported parameters depends on the library version. 114 | 115 | """ 116 | kwasync = {} 117 | if 'async' in kwargs: 118 | kwasync['async'] = kwargs.pop('async') 119 | if 'async_' in kwargs: 120 | kwasync['async_'] = kwargs.pop('async_') 121 | 122 | if dsn is None and not kwargs: 123 | raise TypeError('missing dsn and no parameters') 124 | 125 | dsn = _ext.make_dsn(dsn, **kwargs) 126 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 127 | if cursor_factory is not None: 128 | conn.cursor_factory = cursor_factory 129 | 130 | return conn 131 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.7/_ipaddress.py: -------------------------------------------------------------------------------- 1 | """Implementation of the ipaddres-based network types adaptation 2 | """ 3 | 4 | # psycopg/_ipaddress.py - Ipaddres-based network types adaptation 5 | # 6 | # Copyright (C) 2016-2019 Daniele Varrazzo 7 | # 8 | # psycopg2 is free software: you can redistribute it and/or modify it 9 | # under the terms of the GNU Lesser General Public License as published 10 | # by the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # In addition, as a special exception, the copyright holders give 14 | # permission to link this program with the OpenSSL library (or with 15 | # modified versions of OpenSSL that use the same license as OpenSSL), 16 | # and distribute linked combinations including the two. 17 | # 18 | # You must obey the GNU Lesser General Public License in all respects for 19 | # all of the code used other than OpenSSL. 20 | # 21 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 22 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 24 | # License for more details. 25 | 26 | from psycopg2.extensions import ( 27 | new_type, new_array_type, register_type, register_adapter, QuotedString) 28 | from psycopg2.compat import text_type 29 | 30 | # The module is imported on register_ipaddress 31 | ipaddress = None 32 | 33 | # The typecasters are created only once 34 | _casters = None 35 | 36 | 37 | def register_ipaddress(conn_or_curs=None): 38 | """ 39 | Register conversion support between `ipaddress` objects and `network types`__. 40 | 41 | :param conn_or_curs: the scope where to register the type casters. 42 | If `!None` register them globally. 43 | 44 | After the function is called, PostgreSQL :sql:`inet` values will be 45 | converted into `~ipaddress.IPv4Interface` or `~ipaddress.IPv6Interface` 46 | objects, :sql:`cidr` values into into `~ipaddress.IPv4Network` or 47 | `~ipaddress.IPv6Network`. 48 | 49 | .. __: https://www.postgresql.org/docs/current/static/datatype-net-types.html 50 | """ 51 | global ipaddress 52 | import ipaddress 53 | 54 | global _casters 55 | if _casters is None: 56 | _casters = _make_casters() 57 | 58 | for c in _casters: 59 | register_type(c, conn_or_curs) 60 | 61 | for t in [ipaddress.IPv4Interface, ipaddress.IPv6Interface, 62 | ipaddress.IPv4Network, ipaddress.IPv6Network]: 63 | register_adapter(t, adapt_ipaddress) 64 | 65 | 66 | def _make_casters(): 67 | inet = new_type((869,), 'INET', cast_interface) 68 | ainet = new_array_type((1041,), 'INET[]', inet) 69 | 70 | cidr = new_type((650,), 'CIDR', cast_network) 71 | acidr = new_array_type((651,), 'CIDR[]', cidr) 72 | 73 | return [inet, ainet, cidr, acidr] 74 | 75 | 76 | def cast_interface(s, cur=None): 77 | if s is None: 78 | return None 79 | # Py2 version force the use of unicode. meh. 80 | return ipaddress.ip_interface(text_type(s)) 81 | 82 | 83 | def cast_network(s, cur=None): 84 | if s is None: 85 | return None 86 | return ipaddress.ip_network(text_type(s)) 87 | 88 | 89 | def adapt_ipaddress(obj): 90 | return QuotedString(str(obj)) 91 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.7/_lru_cache.py: -------------------------------------------------------------------------------- 1 | """ 2 | LRU cache implementation for Python 2.7 3 | 4 | Ported from http://code.activestate.com/recipes/578078/ and simplified for our 5 | use (only support maxsize > 0 and positional arguments). 6 | """ 7 | 8 | from collections import namedtuple 9 | from functools import update_wrapper 10 | from threading import RLock 11 | 12 | _CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"]) 13 | 14 | 15 | def lru_cache(maxsize=100): 16 | """Least-recently-used cache decorator. 17 | 18 | Arguments to the cached function must be hashable. 19 | 20 | See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used 21 | 22 | """ 23 | def decorating_function(user_function): 24 | 25 | cache = dict() 26 | stats = [0, 0] # make statistics updateable non-locally 27 | HITS, MISSES = 0, 1 # names for the stats fields 28 | cache_get = cache.get # bound method to lookup key or return None 29 | _len = len # localize the global len() function 30 | lock = RLock() # linkedlist updates aren't threadsafe 31 | root = [] # root of the circular doubly linked list 32 | root[:] = [root, root, None, None] # initialize by pointing to self 33 | nonlocal_root = [root] # make updateable non-locally 34 | PREV, NEXT, KEY, RESULT = 0, 1, 2, 3 # names for the link fields 35 | 36 | assert maxsize and maxsize > 0, "maxsize %s not supported" % maxsize 37 | 38 | def wrapper(*args): 39 | # size limited caching that tracks accesses by recency 40 | key = args 41 | with lock: 42 | link = cache_get(key) 43 | if link is not None: 44 | # record recent use of the key by moving it to the 45 | # front of the list 46 | root, = nonlocal_root 47 | link_prev, link_next, key, result = link 48 | link_prev[NEXT] = link_next 49 | link_next[PREV] = link_prev 50 | last = root[PREV] 51 | last[NEXT] = root[PREV] = link 52 | link[PREV] = last 53 | link[NEXT] = root 54 | stats[HITS] += 1 55 | return result 56 | result = user_function(*args) 57 | with lock: 58 | root, = nonlocal_root 59 | if key in cache: 60 | # getting here means that this same key was added to the 61 | # cache while the lock was released. since the link 62 | # update is already done, we need only return the 63 | # computed result and update the count of misses. 64 | pass 65 | elif _len(cache) >= maxsize: 66 | # use the old root to store the new key and result 67 | oldroot = root 68 | oldroot[KEY] = key 69 | oldroot[RESULT] = result 70 | # empty the oldest link and make it the new root 71 | root = nonlocal_root[0] = oldroot[NEXT] 72 | oldkey = root[KEY] 73 | # oldvalue = root[RESULT] 74 | root[KEY] = root[RESULT] = None 75 | # now update the cache dictionary for the new links 76 | del cache[oldkey] 77 | cache[key] = oldroot 78 | else: 79 | # put result in a new link at the front of the list 80 | last = root[PREV] 81 | link = [last, root, key, result] 82 | last[NEXT] = root[PREV] = cache[key] = link 83 | stats[MISSES] += 1 84 | return result 85 | 86 | def cache_info(): 87 | """Report cache statistics""" 88 | with lock: 89 | return _CacheInfo(stats[HITS], stats[MISSES], maxsize, len(cache)) 90 | 91 | def cache_clear(): 92 | """Clear the cache and cache statistics""" 93 | with lock: 94 | cache.clear() 95 | root = nonlocal_root[0] 96 | root[:] = [root, root, None, None] 97 | stats[:] = [0, 0] 98 | 99 | wrapper.__wrapped__ = user_function 100 | wrapper.cache_info = cache_info 101 | wrapper.cache_clear = cache_clear 102 | return update_wrapper(wrapper, user_function) 103 | 104 | return decorating_function 105 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.7/_psycopg.cpython-37m-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/with_ssl_support/psycopg2-3.7/_psycopg.cpython-37m-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.7/compat.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | __all__ = ['string_types', 'text_type', 'lru_cache'] 4 | 5 | if sys.version_info[0] == 2: 6 | # Python 2 7 | PY2 = True 8 | PY3 = False 9 | string_types = basestring, 10 | text_type = unicode 11 | from ._lru_cache import lru_cache 12 | 13 | else: 14 | # Python 3 15 | PY2 = False 16 | PY3 = True 17 | string_types = str, 18 | text_type = str 19 | from functools import lru_cache 20 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.7/errors.py: -------------------------------------------------------------------------------- 1 | """Error classes for PostgreSQL error codes 2 | """ 3 | 4 | # psycopg/errors.py - SQLSTATE and DB-API exceptions 5 | # 6 | # Copyright (C) 2018-2019 Daniele Varrazzo 7 | # 8 | # psycopg2 is free software: you can redistribute it and/or modify it 9 | # under the terms of the GNU Lesser General Public License as published 10 | # by the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # In addition, as a special exception, the copyright holders give 14 | # permission to link this program with the OpenSSL library (or with 15 | # modified versions of OpenSSL that use the same license as OpenSSL), 16 | # and distribute linked combinations including the two. 17 | # 18 | # You must obey the GNU Lesser General Public License in all respects for 19 | # all of the code used other than OpenSSL. 20 | # 21 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 22 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 24 | # License for more details. 25 | 26 | # 27 | # NOTE: the exceptions are injected into this module by the C extention. 28 | # 29 | 30 | 31 | def lookup(code): 32 | """Lookup an error code and return its exception class. 33 | 34 | Raise `!KeyError` if the code is not found. 35 | """ 36 | from psycopg2._psycopg import sqlstate_errors # avoid circular import 37 | return sqlstate_errors[code] 38 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.7/pool.py: -------------------------------------------------------------------------------- 1 | """Connection pooling for psycopg2 2 | 3 | This module implements thread-safe (and not) connection pools. 4 | """ 5 | # psycopg/pool.py - pooling code for psycopg 6 | # 7 | # Copyright (C) 2003-2019 Federico Di Gregorio 8 | # 9 | # psycopg2 is free software: you can redistribute it and/or modify it 10 | # under the terms of the GNU Lesser General Public License as published 11 | # by the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # In addition, as a special exception, the copyright holders give 15 | # permission to link this program with the OpenSSL library (or with 16 | # modified versions of OpenSSL that use the same license as OpenSSL), 17 | # and distribute linked combinations including the two. 18 | # 19 | # You must obey the GNU Lesser General Public License in all respects for 20 | # all of the code used other than OpenSSL. 21 | # 22 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 23 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 25 | # License for more details. 26 | 27 | import psycopg2 28 | from psycopg2 import extensions as _ext 29 | 30 | 31 | class PoolError(psycopg2.Error): 32 | pass 33 | 34 | 35 | class AbstractConnectionPool(object): 36 | """Generic key-based pooling code.""" 37 | 38 | def __init__(self, minconn, maxconn, *args, **kwargs): 39 | """Initialize the connection pool. 40 | 41 | New 'minconn' connections are created immediately calling 'connfunc' 42 | with given parameters. The connection pool will support a maximum of 43 | about 'maxconn' connections. 44 | """ 45 | self.minconn = int(minconn) 46 | self.maxconn = int(maxconn) 47 | self.closed = False 48 | 49 | self._args = args 50 | self._kwargs = kwargs 51 | 52 | self._pool = [] 53 | self._used = {} 54 | self._rused = {} # id(conn) -> key map 55 | self._keys = 0 56 | 57 | for i in range(self.minconn): 58 | self._connect() 59 | 60 | def _connect(self, key=None): 61 | """Create a new connection and assign it to 'key' if not None.""" 62 | conn = psycopg2.connect(*self._args, **self._kwargs) 63 | if key is not None: 64 | self._used[key] = conn 65 | self._rused[id(conn)] = key 66 | else: 67 | self._pool.append(conn) 68 | return conn 69 | 70 | def _getkey(self): 71 | """Return a new unique key.""" 72 | self._keys += 1 73 | return self._keys 74 | 75 | def _getconn(self, key=None): 76 | """Get a free connection and assign it to 'key' if not None.""" 77 | if self.closed: 78 | raise PoolError("connection pool is closed") 79 | if key is None: 80 | key = self._getkey() 81 | 82 | if key in self._used: 83 | return self._used[key] 84 | 85 | if self._pool: 86 | self._used[key] = conn = self._pool.pop() 87 | self._rused[id(conn)] = key 88 | return conn 89 | else: 90 | if len(self._used) == self.maxconn: 91 | raise PoolError("connection pool exhausted") 92 | return self._connect(key) 93 | 94 | def _putconn(self, conn, key=None, close=False): 95 | """Put away a connection.""" 96 | if self.closed: 97 | raise PoolError("connection pool is closed") 98 | 99 | if key is None: 100 | key = self._rused.get(id(conn)) 101 | if key is None: 102 | raise PoolError("trying to put unkeyed connection") 103 | 104 | if len(self._pool) < self.minconn and not close: 105 | # Return the connection into a consistent state before putting 106 | # it back into the pool 107 | if not conn.closed: 108 | status = conn.info.transaction_status 109 | if status == _ext.TRANSACTION_STATUS_UNKNOWN: 110 | # server connection lost 111 | conn.close() 112 | elif status != _ext.TRANSACTION_STATUS_IDLE: 113 | # connection in error or in transaction 114 | conn.rollback() 115 | self._pool.append(conn) 116 | else: 117 | # regular idle connection 118 | self._pool.append(conn) 119 | # If the connection is closed, we just discard it. 120 | else: 121 | conn.close() 122 | 123 | # here we check for the presence of key because it can happen that a 124 | # thread tries to put back a connection after a call to close 125 | if not self.closed or key in self._used: 126 | del self._used[key] 127 | del self._rused[id(conn)] 128 | 129 | def _closeall(self): 130 | """Close all connections. 131 | 132 | Note that this can lead to some code fail badly when trying to use 133 | an already closed connection. If you call .closeall() make sure 134 | your code can deal with it. 135 | """ 136 | if self.closed: 137 | raise PoolError("connection pool is closed") 138 | for conn in self._pool + list(self._used.values()): 139 | try: 140 | conn.close() 141 | except Exception: 142 | pass 143 | self.closed = True 144 | 145 | 146 | class SimpleConnectionPool(AbstractConnectionPool): 147 | """A connection pool that can't be shared across different threads.""" 148 | 149 | getconn = AbstractConnectionPool._getconn 150 | putconn = AbstractConnectionPool._putconn 151 | closeall = AbstractConnectionPool._closeall 152 | 153 | 154 | class ThreadedConnectionPool(AbstractConnectionPool): 155 | """A connection pool that works with the threading module.""" 156 | 157 | def __init__(self, minconn, maxconn, *args, **kwargs): 158 | """Initialize the threading lock.""" 159 | import threading 160 | AbstractConnectionPool.__init__( 161 | self, minconn, maxconn, *args, **kwargs) 162 | self._lock = threading.Lock() 163 | 164 | def getconn(self, key=None): 165 | """Get a free connection and assign it to 'key' if not None.""" 166 | self._lock.acquire() 167 | try: 168 | return self._getconn(key) 169 | finally: 170 | self._lock.release() 171 | 172 | def putconn(self, conn=None, key=None, close=False): 173 | """Put away an unused connection.""" 174 | self._lock.acquire() 175 | try: 176 | self._putconn(conn, key, close) 177 | finally: 178 | self._lock.release() 179 | 180 | def closeall(self): 181 | """Close all connections (even the one currently in use.)""" 182 | self._lock.acquire() 183 | try: 184 | self._closeall() 185 | finally: 186 | self._lock.release() 187 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.7/tz.py: -------------------------------------------------------------------------------- 1 | """tzinfo implementations for psycopg2 2 | 3 | This module holds two different tzinfo implementations that can be used as 4 | the 'tzinfo' argument to datetime constructors, directly passed to psycopg 5 | functions or used to set the .tzinfo_factory attribute in cursors. 6 | """ 7 | # psycopg/tz.py - tzinfo implementation 8 | # 9 | # Copyright (C) 2003-2019 Federico Di Gregorio 10 | # 11 | # psycopg2 is free software: you can redistribute it and/or modify it 12 | # under the terms of the GNU Lesser General Public License as published 13 | # by the Free Software Foundation, either version 3 of the License, or 14 | # (at your option) any later version. 15 | # 16 | # In addition, as a special exception, the copyright holders give 17 | # permission to link this program with the OpenSSL library (or with 18 | # modified versions of OpenSSL that use the same license as OpenSSL), 19 | # and distribute linked combinations including the two. 20 | # 21 | # You must obey the GNU Lesser General Public License in all respects for 22 | # all of the code used other than OpenSSL. 23 | # 24 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 25 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 26 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 27 | # License for more details. 28 | 29 | import datetime 30 | import time 31 | 32 | ZERO = datetime.timedelta(0) 33 | 34 | 35 | class FixedOffsetTimezone(datetime.tzinfo): 36 | """Fixed offset in minutes east from UTC. 37 | 38 | This is exactly the implementation__ found in Python 2.3.x documentation, 39 | with a small change to the `!__init__()` method to allow for pickling 40 | and a default name in the form ``sHH:MM`` (``s`` is the sign.). 41 | 42 | The implementation also caches instances. During creation, if a 43 | FixedOffsetTimezone instance has previously been created with the same 44 | offset and name that instance will be returned. This saves memory and 45 | improves comparability. 46 | 47 | .. __: https://docs.python.org/library/datetime.html 48 | """ 49 | _name = None 50 | _offset = ZERO 51 | 52 | _cache = {} 53 | 54 | def __init__(self, offset=None, name=None): 55 | if offset is not None: 56 | self._offset = datetime.timedelta(minutes=offset) 57 | if name is not None: 58 | self._name = name 59 | 60 | def __new__(cls, offset=None, name=None): 61 | """Return a suitable instance created earlier if it exists 62 | """ 63 | key = (offset, name) 64 | try: 65 | return cls._cache[key] 66 | except KeyError: 67 | tz = super(FixedOffsetTimezone, cls).__new__(cls, offset, name) 68 | cls._cache[key] = tz 69 | return tz 70 | 71 | def __repr__(self): 72 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 73 | return "psycopg2.tz.FixedOffsetTimezone(offset=%r, name=%r)" \ 74 | % (offset_mins, self._name) 75 | 76 | def __getinitargs__(self): 77 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 78 | return offset_mins, self._name 79 | 80 | def utcoffset(self, dt): 81 | return self._offset 82 | 83 | def tzname(self, dt): 84 | if self._name is not None: 85 | return self._name 86 | else: 87 | seconds = self._offset.seconds + self._offset.days * 86400 88 | hours, seconds = divmod(seconds, 3600) 89 | minutes = seconds / 60 90 | if minutes: 91 | return "%+03d:%d" % (hours, minutes) 92 | else: 93 | return "%+03d" % hours 94 | 95 | def dst(self, dt): 96 | return ZERO 97 | 98 | 99 | STDOFFSET = datetime.timedelta(seconds=-time.timezone) 100 | if time.daylight: 101 | DSTOFFSET = datetime.timedelta(seconds=-time.altzone) 102 | else: 103 | DSTOFFSET = STDOFFSET 104 | DSTDIFF = DSTOFFSET - STDOFFSET 105 | 106 | 107 | class LocalTimezone(datetime.tzinfo): 108 | """Platform idea of local timezone. 109 | 110 | This is the exact implementation from the Python 2.3 documentation. 111 | """ 112 | def utcoffset(self, dt): 113 | if self._isdst(dt): 114 | return DSTOFFSET 115 | else: 116 | return STDOFFSET 117 | 118 | def dst(self, dt): 119 | if self._isdst(dt): 120 | return DSTDIFF 121 | else: 122 | return ZERO 123 | 124 | def tzname(self, dt): 125 | return time.tzname[self._isdst(dt)] 126 | 127 | def _isdst(self, dt): 128 | tt = (dt.year, dt.month, dt.day, 129 | dt.hour, dt.minute, dt.second, 130 | dt.weekday(), 0, -1) 131 | stamp = time.mktime(tt) 132 | tt = time.localtime(stamp) 133 | return tt.tm_isdst > 0 134 | 135 | 136 | LOCAL = LocalTimezone() 137 | 138 | # TODO: pre-generate some interesting time zones? 139 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.8/__init__.py: -------------------------------------------------------------------------------- 1 | """A Python driver for PostgreSQL 2 | 3 | psycopg is a PostgreSQL_ database adapter for the Python_ programming 4 | language. This is version 2, a complete rewrite of the original code to 5 | provide new-style classes for connection and cursor objects and other sweet 6 | candies. Like the original, psycopg 2 was written with the aim of being very 7 | small and fast, and stable as a rock. 8 | 9 | Homepage: https://psycopg.org/ 10 | 11 | .. _PostgreSQL: https://www.postgresql.org/ 12 | .. _Python: https://www.python.org/ 13 | 14 | :Groups: 15 | * `Connections creation`: connect 16 | * `Value objects constructors`: Binary, Date, DateFromTicks, Time, 17 | TimeFromTicks, Timestamp, TimestampFromTicks 18 | """ 19 | # psycopg/__init__.py - initialization of the psycopg module 20 | # 21 | # Copyright (C) 2003-2019 Federico Di Gregorio 22 | # Copyright (C) 2020 The Psycopg Team 23 | # 24 | # psycopg2 is free software: you can redistribute it and/or modify it 25 | # under the terms of the GNU Lesser General Public License as published 26 | # by the Free Software Foundation, either version 3 of the License, or 27 | # (at your option) any later version. 28 | # 29 | # In addition, as a special exception, the copyright holders give 30 | # permission to link this program with the OpenSSL library (or with 31 | # modified versions of OpenSSL that use the same license as OpenSSL), 32 | # and distribute linked combinations including the two. 33 | # 34 | # You must obey the GNU Lesser General Public License in all respects for 35 | # all of the code used other than OpenSSL. 36 | # 37 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 38 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 39 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 40 | # License for more details. 41 | 42 | # Import modules needed by _psycopg to allow tools like py2exe to do 43 | # their work without bothering about the module dependencies. 44 | 45 | # Note: the first internal import should be _psycopg, otherwise the real cause 46 | # of a failed loading of the C module may get hidden, see 47 | # https://archives.postgresql.org/psycopg/2011-02/msg00044.php 48 | 49 | # Import the DBAPI-2.0 stuff into top-level module. 50 | 51 | from psycopg2._psycopg import ( # noqa 52 | BINARY, NUMBER, STRING, DATETIME, ROWID, 53 | 54 | Binary, Date, Time, Timestamp, 55 | DateFromTicks, TimeFromTicks, TimestampFromTicks, 56 | 57 | Error, Warning, DataError, DatabaseError, ProgrammingError, IntegrityError, 58 | InterfaceError, InternalError, NotSupportedError, OperationalError, 59 | 60 | _connect, apilevel, threadsafety, paramstyle, 61 | __version__, __libpq_version__, 62 | ) 63 | 64 | from psycopg2 import tz # noqa 65 | 66 | 67 | # Register default adapters. 68 | 69 | from psycopg2 import extensions as _ext 70 | _ext.register_adapter(tuple, _ext.SQL_IN) 71 | _ext.register_adapter(type(None), _ext.NoneAdapter) 72 | 73 | # Register the Decimal adapter here instead of in the C layer. 74 | # This way a new class is registered for each sub-interpreter. 75 | # See ticket #52 76 | from decimal import Decimal # noqa 77 | from psycopg2._psycopg import Decimal as Adapter # noqa 78 | _ext.register_adapter(Decimal, Adapter) 79 | del Decimal, Adapter 80 | 81 | 82 | def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs): 83 | """ 84 | Create a new database connection. 85 | 86 | The connection parameters can be specified as a string: 87 | 88 | conn = psycopg2.connect("dbname=test user=postgres password=secret") 89 | 90 | or using a set of keyword arguments: 91 | 92 | conn = psycopg2.connect(database="test", user="postgres", password="secret") 93 | 94 | Or as a mix of both. The basic connection parameters are: 95 | 96 | - *dbname*: the database name 97 | - *database*: the database name (only as keyword argument) 98 | - *user*: user name used to authenticate 99 | - *password*: password used to authenticate 100 | - *host*: database host address (defaults to UNIX socket if not provided) 101 | - *port*: connection port number (defaults to 5432 if not provided) 102 | 103 | Using the *connection_factory* parameter a different class or connections 104 | factory can be specified. It should be a callable object taking a dsn 105 | argument. 106 | 107 | Using the *cursor_factory* parameter, a new default cursor factory will be 108 | used by cursor(). 109 | 110 | Using *async*=True an asynchronous connection will be created. *async_* is 111 | a valid alias (for Python versions where ``async`` is a keyword). 112 | 113 | Any other keyword parameter will be passed to the underlying client 114 | library: the list of supported parameters depends on the library version. 115 | 116 | """ 117 | kwasync = {} 118 | if 'async' in kwargs: 119 | kwasync['async'] = kwargs.pop('async') 120 | if 'async_' in kwargs: 121 | kwasync['async_'] = kwargs.pop('async_') 122 | 123 | if dsn is None and not kwargs: 124 | raise TypeError('missing dsn and no parameters') 125 | 126 | dsn = _ext.make_dsn(dsn, **kwargs) 127 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 128 | if cursor_factory is not None: 129 | conn.cursor_factory = cursor_factory 130 | 131 | return conn 132 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.8/_ipaddress.py: -------------------------------------------------------------------------------- 1 | """Implementation of the ipaddres-based network types adaptation 2 | """ 3 | 4 | # psycopg/_ipaddress.py - Ipaddres-based network types adaptation 5 | # 6 | # Copyright (C) 2016-2019 Daniele Varrazzo 7 | # Copyright (C) 2020 The Psycopg Team 8 | # 9 | # psycopg2 is free software: you can redistribute it and/or modify it 10 | # under the terms of the GNU Lesser General Public License as published 11 | # by the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # In addition, as a special exception, the copyright holders give 15 | # permission to link this program with the OpenSSL library (or with 16 | # modified versions of OpenSSL that use the same license as OpenSSL), 17 | # and distribute linked combinations including the two. 18 | # 19 | # You must obey the GNU Lesser General Public License in all respects for 20 | # all of the code used other than OpenSSL. 21 | # 22 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 23 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 25 | # License for more details. 26 | 27 | from psycopg2.extensions import ( 28 | new_type, new_array_type, register_type, register_adapter, QuotedString) 29 | from psycopg2.compat import text_type 30 | 31 | # The module is imported on register_ipaddress 32 | ipaddress = None 33 | 34 | # The typecasters are created only once 35 | _casters = None 36 | 37 | 38 | def register_ipaddress(conn_or_curs=None): 39 | """ 40 | Register conversion support between `ipaddress` objects and `network types`__. 41 | 42 | :param conn_or_curs: the scope where to register the type casters. 43 | If `!None` register them globally. 44 | 45 | After the function is called, PostgreSQL :sql:`inet` values will be 46 | converted into `~ipaddress.IPv4Interface` or `~ipaddress.IPv6Interface` 47 | objects, :sql:`cidr` values into into `~ipaddress.IPv4Network` or 48 | `~ipaddress.IPv6Network`. 49 | 50 | .. __: https://www.postgresql.org/docs/current/static/datatype-net-types.html 51 | """ 52 | global ipaddress 53 | import ipaddress 54 | 55 | global _casters 56 | if _casters is None: 57 | _casters = _make_casters() 58 | 59 | for c in _casters: 60 | register_type(c, conn_or_curs) 61 | 62 | for t in [ipaddress.IPv4Interface, ipaddress.IPv6Interface, 63 | ipaddress.IPv4Network, ipaddress.IPv6Network]: 64 | register_adapter(t, adapt_ipaddress) 65 | 66 | 67 | def _make_casters(): 68 | inet = new_type((869,), 'INET', cast_interface) 69 | ainet = new_array_type((1041,), 'INET[]', inet) 70 | 71 | cidr = new_type((650,), 'CIDR', cast_network) 72 | acidr = new_array_type((651,), 'CIDR[]', cidr) 73 | 74 | return [inet, ainet, cidr, acidr] 75 | 76 | 77 | def cast_interface(s, cur=None): 78 | if s is None: 79 | return None 80 | # Py2 version force the use of unicode. meh. 81 | return ipaddress.ip_interface(text_type(s)) 82 | 83 | 84 | def cast_network(s, cur=None): 85 | if s is None: 86 | return None 87 | return ipaddress.ip_network(text_type(s)) 88 | 89 | 90 | def adapt_ipaddress(obj): 91 | return QuotedString(str(obj)) 92 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.8/_lru_cache.py: -------------------------------------------------------------------------------- 1 | """ 2 | LRU cache implementation for Python 2.7 3 | 4 | Ported from http://code.activestate.com/recipes/578078/ and simplified for our 5 | use (only support maxsize > 0 and positional arguments). 6 | """ 7 | 8 | from collections import namedtuple 9 | from functools import update_wrapper 10 | from threading import RLock 11 | 12 | _CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"]) 13 | 14 | 15 | def lru_cache(maxsize=100): 16 | """Least-recently-used cache decorator. 17 | 18 | Arguments to the cached function must be hashable. 19 | 20 | See: http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used 21 | 22 | """ 23 | def decorating_function(user_function): 24 | 25 | cache = dict() 26 | stats = [0, 0] # make statistics updateable non-locally 27 | HITS, MISSES = 0, 1 # names for the stats fields 28 | cache_get = cache.get # bound method to lookup key or return None 29 | _len = len # localize the global len() function 30 | lock = RLock() # linkedlist updates aren't threadsafe 31 | root = [] # root of the circular doubly linked list 32 | root[:] = [root, root, None, None] # initialize by pointing to self 33 | nonlocal_root = [root] # make updateable non-locally 34 | PREV, NEXT, KEY, RESULT = 0, 1, 2, 3 # names for the link fields 35 | 36 | assert maxsize and maxsize > 0, "maxsize %s not supported" % maxsize 37 | 38 | def wrapper(*args): 39 | # size limited caching that tracks accesses by recency 40 | key = args 41 | with lock: 42 | link = cache_get(key) 43 | if link is not None: 44 | # record recent use of the key by moving it to the 45 | # front of the list 46 | root, = nonlocal_root 47 | link_prev, link_next, key, result = link 48 | link_prev[NEXT] = link_next 49 | link_next[PREV] = link_prev 50 | last = root[PREV] 51 | last[NEXT] = root[PREV] = link 52 | link[PREV] = last 53 | link[NEXT] = root 54 | stats[HITS] += 1 55 | return result 56 | result = user_function(*args) 57 | with lock: 58 | root, = nonlocal_root 59 | if key in cache: 60 | # getting here means that this same key was added to the 61 | # cache while the lock was released. since the link 62 | # update is already done, we need only return the 63 | # computed result and update the count of misses. 64 | pass 65 | elif _len(cache) >= maxsize: 66 | # use the old root to store the new key and result 67 | oldroot = root 68 | oldroot[KEY] = key 69 | oldroot[RESULT] = result 70 | # empty the oldest link and make it the new root 71 | root = nonlocal_root[0] = oldroot[NEXT] 72 | oldkey = root[KEY] 73 | # oldvalue = root[RESULT] 74 | root[KEY] = root[RESULT] = None 75 | # now update the cache dictionary for the new links 76 | del cache[oldkey] 77 | cache[key] = oldroot 78 | else: 79 | # put result in a new link at the front of the list 80 | last = root[PREV] 81 | link = [last, root, key, result] 82 | last[NEXT] = root[PREV] = cache[key] = link 83 | stats[MISSES] += 1 84 | return result 85 | 86 | def cache_info(): 87 | """Report cache statistics""" 88 | with lock: 89 | return _CacheInfo(stats[HITS], stats[MISSES], maxsize, len(cache)) 90 | 91 | def cache_clear(): 92 | """Clear the cache and cache statistics""" 93 | with lock: 94 | cache.clear() 95 | root = nonlocal_root[0] 96 | root[:] = [root, root, None, None] 97 | stats[:] = [0, 0] 98 | 99 | wrapper.__wrapped__ = user_function 100 | wrapper.cache_info = cache_info 101 | wrapper.cache_clear = cache_clear 102 | return update_wrapper(wrapper, user_function) 103 | 104 | return decorating_function 105 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.8/_psycopg.cpython-38-x86_64-linux-gnu.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/with_ssl_support/psycopg2-3.8/_psycopg.cpython-38-x86_64-linux-gnu.so -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.8/compat.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | __all__ = ['string_types', 'text_type', 'lru_cache'] 4 | 5 | if sys.version_info[0] == 2: 6 | # Python 2 7 | PY2 = True 8 | PY3 = False 9 | string_types = basestring, 10 | text_type = unicode 11 | from ._lru_cache import lru_cache 12 | 13 | else: 14 | # Python 3 15 | PY2 = False 16 | PY3 = True 17 | string_types = str, 18 | text_type = str 19 | from functools import lru_cache 20 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.8/errors.py: -------------------------------------------------------------------------------- 1 | """Error classes for PostgreSQL error codes 2 | """ 3 | 4 | # psycopg/errors.py - SQLSTATE and DB-API exceptions 5 | # 6 | # Copyright (C) 2018-2019 Daniele Varrazzo 7 | # Copyright (C) 2020 The Psycopg Team 8 | # 9 | # psycopg2 is free software: you can redistribute it and/or modify it 10 | # under the terms of the GNU Lesser General Public License as published 11 | # by the Free Software Foundation, either version 3 of the License, or 12 | # (at your option) any later version. 13 | # 14 | # In addition, as a special exception, the copyright holders give 15 | # permission to link this program with the OpenSSL library (or with 16 | # modified versions of OpenSSL that use the same license as OpenSSL), 17 | # and distribute linked combinations including the two. 18 | # 19 | # You must obey the GNU Lesser General Public License in all respects for 20 | # all of the code used other than OpenSSL. 21 | # 22 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 23 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 24 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 25 | # License for more details. 26 | 27 | # 28 | # NOTE: the exceptions are injected into this module by the C extention. 29 | # 30 | 31 | 32 | def lookup(code): 33 | """Lookup an error code and return its exception class. 34 | 35 | Raise `!KeyError` if the code is not found. 36 | """ 37 | from psycopg2._psycopg import sqlstate_errors # avoid circular import 38 | return sqlstate_errors[code] 39 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2-3.8/tz.py: -------------------------------------------------------------------------------- 1 | """tzinfo implementations for psycopg2 2 | 3 | This module holds two different tzinfo implementations that can be used as 4 | the 'tzinfo' argument to datetime constructors, directly passed to psycopg 5 | functions or used to set the .tzinfo_factory attribute in cursors. 6 | """ 7 | # psycopg/tz.py - tzinfo implementation 8 | # 9 | # Copyright (C) 2003-2019 Federico Di Gregorio 10 | # Copyright (C) 2020 The Psycopg Team 11 | # 12 | # psycopg2 is free software: you can redistribute it and/or modify it 13 | # under the terms of the GNU Lesser General Public License as published 14 | # by the Free Software Foundation, either version 3 of the License, or 15 | # (at your option) any later version. 16 | # 17 | # In addition, as a special exception, the copyright holders give 18 | # permission to link this program with the OpenSSL library (or with 19 | # modified versions of OpenSSL that use the same license as OpenSSL), 20 | # and distribute linked combinations including the two. 21 | # 22 | # You must obey the GNU Lesser General Public License in all respects for 23 | # all of the code used other than OpenSSL. 24 | # 25 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 26 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 27 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 28 | # License for more details. 29 | 30 | import datetime 31 | import time 32 | 33 | ZERO = datetime.timedelta(0) 34 | 35 | 36 | class FixedOffsetTimezone(datetime.tzinfo): 37 | """Fixed offset in minutes east from UTC. 38 | 39 | This is exactly the implementation__ found in Python 2.3.x documentation, 40 | with a small change to the `!__init__()` method to allow for pickling 41 | and a default name in the form ``sHH:MM`` (``s`` is the sign.). 42 | 43 | The implementation also caches instances. During creation, if a 44 | FixedOffsetTimezone instance has previously been created with the same 45 | offset and name that instance will be returned. This saves memory and 46 | improves comparability. 47 | 48 | .. __: https://docs.python.org/library/datetime.html 49 | """ 50 | _name = None 51 | _offset = ZERO 52 | 53 | _cache = {} 54 | 55 | def __init__(self, offset=None, name=None): 56 | if offset is not None: 57 | self._offset = datetime.timedelta(minutes=offset) 58 | if name is not None: 59 | self._name = name 60 | 61 | def __new__(cls, offset=None, name=None): 62 | """Return a suitable instance created earlier if it exists 63 | """ 64 | key = (offset, name) 65 | try: 66 | return cls._cache[key] 67 | except KeyError: 68 | tz = super(FixedOffsetTimezone, cls).__new__(cls, offset, name) 69 | cls._cache[key] = tz 70 | return tz 71 | 72 | def __repr__(self): 73 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 74 | return "psycopg2.tz.FixedOffsetTimezone(offset=%r, name=%r)" \ 75 | % (offset_mins, self._name) 76 | 77 | def __getinitargs__(self): 78 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 79 | return offset_mins, self._name 80 | 81 | def utcoffset(self, dt): 82 | return self._offset 83 | 84 | def tzname(self, dt): 85 | if self._name is not None: 86 | return self._name 87 | else: 88 | seconds = self._offset.seconds + self._offset.days * 86400 89 | hours, seconds = divmod(seconds, 3600) 90 | minutes = seconds / 60 91 | if minutes: 92 | return "%+03d:%d" % (hours, minutes) 93 | else: 94 | return "%+03d" % hours 95 | 96 | def dst(self, dt): 97 | return ZERO 98 | 99 | 100 | STDOFFSET = datetime.timedelta(seconds=-time.timezone) 101 | if time.daylight: 102 | DSTOFFSET = datetime.timedelta(seconds=-time.altzone) 103 | else: 104 | DSTOFFSET = STDOFFSET 105 | DSTDIFF = DSTOFFSET - STDOFFSET 106 | 107 | 108 | class LocalTimezone(datetime.tzinfo): 109 | """Platform idea of local timezone. 110 | 111 | This is the exact implementation from the Python 2.3 documentation. 112 | """ 113 | def utcoffset(self, dt): 114 | if self._isdst(dt): 115 | return DSTOFFSET 116 | else: 117 | return STDOFFSET 118 | 119 | def dst(self, dt): 120 | if self._isdst(dt): 121 | return DSTDIFF 122 | else: 123 | return ZERO 124 | 125 | def tzname(self, dt): 126 | return time.tzname[self._isdst(dt)] 127 | 128 | def _isdst(self, dt): 129 | tt = (dt.year, dt.month, dt.day, 130 | dt.hour, dt.minute, dt.second, 131 | dt.weekday(), 0, -1) 132 | stamp = time.mktime(tt) 133 | tt = time.localtime(stamp) 134 | return tt.tm_isdst > 0 135 | 136 | 137 | LOCAL = LocalTimezone() 138 | 139 | # TODO: pre-generate some interesting time zones? 140 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2/__init__.py: -------------------------------------------------------------------------------- 1 | """A Python driver for PostgreSQL 2 | 3 | psycopg is a PostgreSQL_ database adapter for the Python_ programming 4 | language. This is version 2, a complete rewrite of the original code to 5 | provide new-style classes for connection and cursor objects and other sweet 6 | candies. Like the original, psycopg 2 was written with the aim of being very 7 | small and fast, and stable as a rock. 8 | 9 | Homepage: http://initd.org/projects/psycopg2 10 | 11 | .. _PostgreSQL: http://www.postgresql.org/ 12 | .. _Python: http://www.python.org/ 13 | 14 | :Groups: 15 | * `Connections creation`: connect 16 | * `Value objects constructors`: Binary, Date, DateFromTicks, Time, 17 | TimeFromTicks, Timestamp, TimestampFromTicks 18 | """ 19 | # psycopg/__init__.py - initialization of the psycopg module 20 | # 21 | # Copyright (C) 2003-2010 Federico Di Gregorio 22 | # 23 | # psycopg2 is free software: you can redistribute it and/or modify it 24 | # under the terms of the GNU Lesser General Public License as published 25 | # by the Free Software Foundation, either version 3 of the License, or 26 | # (at your option) any later version. 27 | # 28 | # In addition, as a special exception, the copyright holders give 29 | # permission to link this program with the OpenSSL library (or with 30 | # modified versions of OpenSSL that use the same license as OpenSSL), 31 | # and distribute linked combinations including the two. 32 | # 33 | # You must obey the GNU Lesser General Public License in all respects for 34 | # all of the code used other than OpenSSL. 35 | # 36 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 37 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 38 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 39 | # License for more details. 40 | 41 | # Import modules needed by _psycopg to allow tools like py2exe to do 42 | # their work without bothering about the module dependencies. 43 | 44 | # Note: the first internal import should be _psycopg, otherwise the real cause 45 | # of a failed loading of the C module may get hidden, see 46 | # http://archives.postgresql.org/psycopg/2011-02/msg00044.php 47 | 48 | # Import the DBAPI-2.0 stuff into top-level module. 49 | 50 | from psycopg2._psycopg import ( # noqa 51 | BINARY, NUMBER, STRING, DATETIME, ROWID, 52 | 53 | Binary, Date, Time, Timestamp, 54 | DateFromTicks, TimeFromTicks, TimestampFromTicks, 55 | 56 | Error, Warning, DataError, DatabaseError, ProgrammingError, IntegrityError, 57 | InterfaceError, InternalError, NotSupportedError, OperationalError, 58 | 59 | _connect, apilevel, threadsafety, paramstyle, 60 | __version__, __libpq_version__, 61 | ) 62 | 63 | from psycopg2 import tz # noqa 64 | 65 | 66 | # Register default adapters. 67 | 68 | import psycopg2.extensions as _ext 69 | _ext.register_adapter(tuple, _ext.SQL_IN) 70 | _ext.register_adapter(type(None), _ext.NoneAdapter) 71 | 72 | # Register the Decimal adapter here instead of in the C layer. 73 | # This way a new class is registered for each sub-interpreter. 74 | # See ticket #52 75 | try: 76 | from decimal import Decimal 77 | except ImportError: 78 | pass 79 | else: 80 | from psycopg2._psycopg import Decimal as Adapter 81 | _ext.register_adapter(Decimal, Adapter) 82 | del Decimal, Adapter 83 | 84 | 85 | def connect(dsn=None, connection_factory=None, cursor_factory=None, **kwargs): 86 | """ 87 | Create a new database connection. 88 | 89 | The connection parameters can be specified as a string: 90 | 91 | conn = psycopg2.connect("dbname=test user=postgres password=secret") 92 | 93 | or using a set of keyword arguments: 94 | 95 | conn = psycopg2.connect(database="test", user="postgres", password="secret") 96 | 97 | Or as a mix of both. The basic connection parameters are: 98 | 99 | - *dbname*: the database name 100 | - *database*: the database name (only as keyword argument) 101 | - *user*: user name used to authenticate 102 | - *password*: password used to authenticate 103 | - *host*: database host address (defaults to UNIX socket if not provided) 104 | - *port*: connection port number (defaults to 5432 if not provided) 105 | 106 | Using the *connection_factory* parameter a different class or connections 107 | factory can be specified. It should be a callable object taking a dsn 108 | argument. 109 | 110 | Using the *cursor_factory* parameter, a new default cursor factory will be 111 | used by cursor(). 112 | 113 | Using *async*=True an asynchronous connection will be created. *async_* is 114 | a valid alias (for Python versions where ``async`` is a keyword). 115 | 116 | Any other keyword parameter will be passed to the underlying client 117 | library: the list of supported parameters depends on the library version. 118 | 119 | """ 120 | kwasync = {} 121 | if 'async' in kwargs: 122 | kwasync['async'] = kwargs.pop('async') 123 | if 'async_' in kwargs: 124 | kwasync['async_'] = kwargs.pop('async_') 125 | 126 | if dsn is None and not kwargs: 127 | raise TypeError('missing dsn and no parameters') 128 | 129 | dsn = _ext.make_dsn(dsn, **kwargs) 130 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 131 | if cursor_factory is not None: 132 | conn.cursor_factory = cursor_factory 133 | 134 | return conn 135 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2/_ipaddress.py: -------------------------------------------------------------------------------- 1 | """Implementation of the ipaddres-based network types adaptation 2 | """ 3 | 4 | # psycopg/_ipaddress.py - Ipaddres-based network types adaptation 5 | # 6 | # Copyright (C) 2016 Daniele Varrazzo 7 | # 8 | # psycopg2 is free software: you can redistribute it and/or modify it 9 | # under the terms of the GNU Lesser General Public License as published 10 | # by the Free Software Foundation, either version 3 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # In addition, as a special exception, the copyright holders give 14 | # permission to link this program with the OpenSSL library (or with 15 | # modified versions of OpenSSL that use the same license as OpenSSL), 16 | # and distribute linked combinations including the two. 17 | # 18 | # You must obey the GNU Lesser General Public License in all respects for 19 | # all of the code used other than OpenSSL. 20 | # 21 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 22 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 23 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 24 | # License for more details. 25 | 26 | from psycopg2.extensions import ( 27 | new_type, new_array_type, register_type, register_adapter, QuotedString) 28 | 29 | # The module is imported on register_ipaddress 30 | ipaddress = None 31 | 32 | # The typecasters are created only once 33 | _casters = None 34 | 35 | 36 | def register_ipaddress(conn_or_curs=None): 37 | """ 38 | Register conversion support between `ipaddress` objects and `network types`__. 39 | 40 | :param conn_or_curs: the scope where to register the type casters. 41 | If `!None` register them globally. 42 | 43 | After the function is called, PostgreSQL :sql:`inet` values will be 44 | converted into `~ipaddress.IPv4Interface` or `~ipaddress.IPv6Interface` 45 | objects, :sql:`cidr` values into into `~ipaddress.IPv4Network` or 46 | `~ipaddress.IPv6Network`. 47 | 48 | .. __: https://www.postgresql.org/docs/current/static/datatype-net-types.html 49 | """ 50 | global ipaddress 51 | import ipaddress 52 | 53 | global _casters 54 | if _casters is None: 55 | _casters = _make_casters() 56 | 57 | for c in _casters: 58 | register_type(c, conn_or_curs) 59 | 60 | for t in [ipaddress.IPv4Interface, ipaddress.IPv6Interface, 61 | ipaddress.IPv4Network, ipaddress.IPv6Network]: 62 | register_adapter(t, adapt_ipaddress) 63 | 64 | 65 | def _make_casters(): 66 | inet = new_type((869,), 'INET', cast_interface) 67 | ainet = new_array_type((1041,), 'INET[]', inet) 68 | 69 | cidr = new_type((650,), 'CIDR', cast_network) 70 | acidr = new_array_type((651,), 'CIDR[]', cidr) 71 | 72 | return [inet, ainet, cidr, acidr] 73 | 74 | 75 | def cast_interface(s, cur=None): 76 | if s is None: 77 | return None 78 | # Py2 version force the use of unicode. meh. 79 | return ipaddress.ip_interface(unicode(s)) 80 | 81 | 82 | def cast_network(s, cur=None): 83 | if s is None: 84 | return None 85 | return ipaddress.ip_network(unicode(s)) 86 | 87 | 88 | def adapt_ipaddress(obj): 89 | return QuotedString(str(obj)) 90 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2/_psycopg.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jkehler/awslambda-psycopg2/92bd3dcf81f1fbb888726d3babedd53cab439b06/with_ssl_support/psycopg2/_psycopg.so -------------------------------------------------------------------------------- /with_ssl_support/psycopg2/psycopg1.py: -------------------------------------------------------------------------------- 1 | """psycopg 1.1.x compatibility module 2 | 3 | This module uses the new style connection and cursor types to build a psycopg 4 | 1.1.1.x compatibility layer. It should be considered a temporary hack to run 5 | old code while porting to psycopg 2. Import it as follows:: 6 | 7 | from psycopg2 import psycopg1 as psycopg 8 | """ 9 | # psycopg/psycopg1.py - psycopg 1.1.x compatibility module 10 | # 11 | # Copyright (C) 2003-2010 Federico Di Gregorio 12 | # 13 | # psycopg2 is free software: you can redistribute it and/or modify it 14 | # under the terms of the GNU Lesser General Public License as published 15 | # by the Free Software Foundation, either version 3 of the License, or 16 | # (at your option) any later version. 17 | # 18 | # In addition, as a special exception, the copyright holders give 19 | # permission to link this program with the OpenSSL library (or with 20 | # modified versions of OpenSSL that use the same license as OpenSSL), 21 | # and distribute linked combinations including the two. 22 | # 23 | # You must obey the GNU Lesser General Public License in all respects for 24 | # all of the code used other than OpenSSL. 25 | # 26 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 27 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 28 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 29 | # License for more details. 30 | 31 | import psycopg2._psycopg as _2psycopg # noqa 32 | from psycopg2.extensions import cursor as _2cursor 33 | from psycopg2.extensions import connection as _2connection 34 | 35 | from psycopg2 import * # noqa 36 | import psycopg2.extensions as _ext 37 | _2connect = connect 38 | 39 | 40 | def connect(*args, **kwargs): 41 | """connect(dsn, ...) -> new psycopg 1.1.x compatible connection object""" 42 | kwargs['connection_factory'] = connection 43 | conn = _2connect(*args, **kwargs) 44 | conn.set_isolation_level(_ext.ISOLATION_LEVEL_READ_COMMITTED) 45 | return conn 46 | 47 | 48 | class connection(_2connection): 49 | """psycopg 1.1.x connection.""" 50 | 51 | def cursor(self): 52 | """cursor() -> new psycopg 1.1.x compatible cursor object""" 53 | return _2connection.cursor(self, cursor_factory=cursor) 54 | 55 | def autocommit(self, on_off=1): 56 | """autocommit(on_off=1) -> switch autocommit on (1) or off (0)""" 57 | if on_off > 0: 58 | self.set_isolation_level(_ext.ISOLATION_LEVEL_AUTOCOMMIT) 59 | else: 60 | self.set_isolation_level(_ext.ISOLATION_LEVEL_READ_COMMITTED) 61 | 62 | 63 | class cursor(_2cursor): 64 | """psycopg 1.1.x cursor. 65 | 66 | Note that this cursor implements the exact procedure used by psycopg 1 to 67 | build dictionaries out of result rows. The DictCursor in the 68 | psycopg.extras modules implements a much better and faster algorithm. 69 | """ 70 | 71 | def __build_dict(self, row): 72 | res = {} 73 | for i in range(len(self.description)): 74 | res[self.description[i][0]] = row[i] 75 | return res 76 | 77 | def dictfetchone(self): 78 | row = _2cursor.fetchone(self) 79 | if row: 80 | return self.__build_dict(row) 81 | else: 82 | return row 83 | 84 | def dictfetchmany(self, size): 85 | res = [] 86 | rows = _2cursor.fetchmany(self, size) 87 | for row in rows: 88 | res.append(self.__build_dict(row)) 89 | return res 90 | 91 | def dictfetchall(self): 92 | res = [] 93 | rows = _2cursor.fetchall(self) 94 | for row in rows: 95 | res.append(self.__build_dict(row)) 96 | return res 97 | -------------------------------------------------------------------------------- /with_ssl_support/psycopg2/tz.py: -------------------------------------------------------------------------------- 1 | """tzinfo implementations for psycopg2 2 | 3 | This module holds two different tzinfo implementations that can be used as 4 | the 'tzinfo' argument to datetime constructors, directly passed to psycopg 5 | functions or used to set the .tzinfo_factory attribute in cursors. 6 | """ 7 | # psycopg/tz.py - tzinfo implementation 8 | # 9 | # Copyright (C) 2003-2010 Federico Di Gregorio 10 | # 11 | # psycopg2 is free software: you can redistribute it and/or modify it 12 | # under the terms of the GNU Lesser General Public License as published 13 | # by the Free Software Foundation, either version 3 of the License, or 14 | # (at your option) any later version. 15 | # 16 | # In addition, as a special exception, the copyright holders give 17 | # permission to link this program with the OpenSSL library (or with 18 | # modified versions of OpenSSL that use the same license as OpenSSL), 19 | # and distribute linked combinations including the two. 20 | # 21 | # You must obey the GNU Lesser General Public License in all respects for 22 | # all of the code used other than OpenSSL. 23 | # 24 | # psycopg2 is distributed in the hope that it will be useful, but WITHOUT 25 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 26 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 27 | # License for more details. 28 | 29 | import datetime 30 | import time 31 | 32 | ZERO = datetime.timedelta(0) 33 | 34 | 35 | class FixedOffsetTimezone(datetime.tzinfo): 36 | """Fixed offset in minutes east from UTC. 37 | 38 | This is exactly the implementation__ found in Python 2.3.x documentation, 39 | with a small change to the `!__init__()` method to allow for pickling 40 | and a default name in the form ``sHH:MM`` (``s`` is the sign.). 41 | 42 | The implementation also caches instances. During creation, if a 43 | FixedOffsetTimezone instance has previously been created with the same 44 | offset and name that instance will be returned. This saves memory and 45 | improves comparability. 46 | 47 | .. __: http://docs.python.org/library/datetime.html#datetime-tzinfo 48 | """ 49 | _name = None 50 | _offset = ZERO 51 | 52 | _cache = {} 53 | 54 | def __init__(self, offset=None, name=None): 55 | if offset is not None: 56 | self._offset = datetime.timedelta(minutes=offset) 57 | if name is not None: 58 | self._name = name 59 | 60 | def __new__(cls, offset=None, name=None): 61 | """Return a suitable instance created earlier if it exists 62 | """ 63 | key = (offset, name) 64 | try: 65 | return cls._cache[key] 66 | except KeyError: 67 | tz = super(FixedOffsetTimezone, cls).__new__(cls, offset, name) 68 | cls._cache[key] = tz 69 | return tz 70 | 71 | def __repr__(self): 72 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 73 | return "psycopg2.tz.FixedOffsetTimezone(offset=%r, name=%r)" \ 74 | % (offset_mins, self._name) 75 | 76 | def __getinitargs__(self): 77 | offset_mins = self._offset.seconds // 60 + self._offset.days * 24 * 60 78 | return (offset_mins, self._name) 79 | 80 | def utcoffset(self, dt): 81 | return self._offset 82 | 83 | def tzname(self, dt): 84 | if self._name is not None: 85 | return self._name 86 | else: 87 | seconds = self._offset.seconds + self._offset.days * 86400 88 | hours, seconds = divmod(seconds, 3600) 89 | minutes = seconds / 60 90 | if minutes: 91 | return "%+03d:%d" % (hours, minutes) 92 | else: 93 | return "%+03d" % hours 94 | 95 | def dst(self, dt): 96 | return ZERO 97 | 98 | 99 | STDOFFSET = datetime.timedelta(seconds=-time.timezone) 100 | if time.daylight: 101 | DSTOFFSET = datetime.timedelta(seconds=-time.altzone) 102 | else: 103 | DSTOFFSET = STDOFFSET 104 | DSTDIFF = DSTOFFSET - STDOFFSET 105 | 106 | 107 | class LocalTimezone(datetime.tzinfo): 108 | """Platform idea of local timezone. 109 | 110 | This is the exact implementation from the Python 2.3 documentation. 111 | """ 112 | def utcoffset(self, dt): 113 | if self._isdst(dt): 114 | return DSTOFFSET 115 | else: 116 | return STDOFFSET 117 | 118 | def dst(self, dt): 119 | if self._isdst(dt): 120 | return DSTDIFF 121 | else: 122 | return ZERO 123 | 124 | def tzname(self, dt): 125 | return time.tzname[self._isdst(dt)] 126 | 127 | def _isdst(self, dt): 128 | tt = (dt.year, dt.month, dt.day, 129 | dt.hour, dt.minute, dt.second, 130 | dt.weekday(), 0, -1) 131 | stamp = time.mktime(tt) 132 | tt = time.localtime(stamp) 133 | return tt.tm_isdst > 0 134 | 135 | LOCAL = LocalTimezone() 136 | 137 | # TODO: pre-generate some interesting time zones? 138 | --------------------------------------------------------------------------------