[Python-modules-commits] [python-vertica] 01/05: Import python-vertica_0.5.8.orig.tar.gz

Jean Baptiste Favre jbfavre-guest at moszumanska.debian.org
Sat Apr 23 08:33:02 UTC 2016


This is an automated email from the git hooks/post-receive script.

jbfavre-guest pushed a commit to branch master
in repository python-vertica.

commit f023f12a95089c1178b78e28da29d6842bfc3865
Author: Jean Baptiste Favre <debian at jbfavre.org>
Date:   Sat Apr 23 09:12:24 2016 +0200

    Import python-vertica_0.5.8.orig.tar.gz
---
 README.md                            | 26 +++++++++++++++-
 requirements.txt                     |  1 +
 setup.py                             |  4 +--
 vertica_python/__init__.py           |  2 +-
 vertica_python/vertica/connection.py | 58 ++++++++++++++++++------------------
 vertica_python/vertica/cursor.py     |  4 ++-
 6 files changed, 61 insertions(+), 34 deletions(-)

diff --git a/README.md b/README.md
index f8adf91..1b7b030 100644
--- a/README.md
+++ b/README.md
@@ -67,7 +67,9 @@ conn_info = {'host': '127.0.0.1',
              # 10 minutes timeout on queries
              'read_timeout': 600,
              # default throw error on invalid UTF-8 results
-             'unicode_error': 'strict'}
+             'unicode_error': 'strict'
+             # SSL is disabled by default
+             'ssl': False}
 
 # simple connection, with manual close
 connection = vertica_python.connect(**conn_info)
@@ -79,6 +81,28 @@ with vertica_python.connect(**conn_info) as connection:
     # do things
 ```
 
+You can pass an `ssl.SSLContext` to `ssl` to customize the SSL connection options. For example,
+
+```python
+import vertica_python
+import ssl
+
+ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
+ssl_context.verify_mode = ssl.CERT_REQUIRED
+ssl_context.check_hostname = True
+ssl_context.load_verify_locations(cafile='/path/to/ca_file.pem')
+
+conn_info = {'host': '127.0.0.1',
+             'port': 5433,
+             'user': 'some_user',
+             'password': 'some_password',
+             'database': 'a_database',
+             'ssl': ssl_context}
+connection = vertica_python.connect(**conn_info)
+
+```
+
+See more on SSL options [here](https://docs.python.org/2/library/ssl.html).
 
 **Stream query results**:
 
diff --git a/requirements.txt b/requirements.txt
index 8b6b3b8..a60d073 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,3 @@
 python-dateutil>=1.5
 pytz
+ordereddict==1.1
diff --git a/setup.py b/setup.py
index 9c9fb1b..bb8fcfc 100644
--- a/setup.py
+++ b/setup.py
@@ -10,7 +10,7 @@ opts = ReqOpts(None, 'git')
 # version should use the format 'x.x.x' (instead of 'vx.x.x')
 setup(
     name='vertica-python',
-    version='0.5.6',
+    version='0.5.8',
     description='A native Python client for the Vertica database.',
     author='Justin Berka, Alex Kim, Kenneth Tran',
     author_email='justin.berka at gmail.com, alex.kim at uber.com, tran at uber.com',
@@ -18,7 +18,7 @@ setup(
     keywords="database vertica",
     packages=find_packages(),
     license="MIT",
-    install_requires=['python-dateutil>=1.5', 'pytz'],
+    install_requires=['python-dateutil>=1.5', 'pytz', 'ordereddict==1.1'],
     extras_require={'namedparams': ['psycopg2>=2.5.1']},
     classifiers=[
         "Development Status :: 3 - Alpha",
diff --git a/vertica_python/__init__.py b/vertica_python/__init__.py
index 5a7dc99..c0fb885 100644
--- a/vertica_python/__init__.py
+++ b/vertica_python/__init__.py
@@ -6,7 +6,7 @@ from vertica_python.vertica.connection import Connection
 # Main module for this library.
 
 # The version number of this library.
-version_info = (0, 5, 6)
+version_info = (0, 5, 8)
 
 __version__ = '.'.join(map(str, version_info))
 
diff --git a/vertica_python/vertica/connection.py b/vertica_python/vertica/connection.py
index 8bc9a1e..1865fbf 100644
--- a/vertica_python/vertica/connection.py
+++ b/vertica_python/vertica/connection.py
@@ -100,24 +100,31 @@ class Connection(object):
         if self.socket is not None:
             return self.socket
 
-        if self.options.get('ssl'):
-            # SSL
-            raw_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-            raw_socket.connect((self.options['host'], self.options['port']))
+        host = self.options.get('host')
+        port = self.options.get('port')
+        raw_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        raw_socket.connect((host, port))
+
+        ssl_options = self.options.get('ssl')
+        if ssl_options is not None and ssl_options is not False:
+            from ssl import CertificateError, SSLError
             raw_socket.sendall(messages.SslRequest().to_bytes())
             response = raw_socket.recv(1)
             if response == 'S':
-                # May want to add certs to this
-                raw_socket = ssl.wrap_socket(raw_socket)
+                try:
+                    if isinstance(ssl_options, ssl.SSLContext):
+                        raw_socket = ssl_options.wrap_socket(raw_socket, server_hostname=host)
+                    else:
+                        raw_socket = ssl.wrap_socket(raw_socket)
+                except CertificateError, e:
+                    raise errors.ConnectionError('SSL: ' + e.message)
+                except SSLError, e:
+                    raise errors.ConnectionError('SSL: ' + e.reason)
             else:
                 raise SSLNotSupported("SSL requested but not supported by server")
-        else:
-            # Non-SSL
-            raw_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-            raw_socket.connect((self.options['host'], self.options['port']))
 
         self.socket = raw_socket
-        return raw_socket
+        return self.socket
 
     def ssl(self):
         return self.socket is not None and isinstance(ssl.SSLSocket, self.socket)
@@ -171,24 +178,17 @@ class Connection(object):
 
     def read_message(self):
         try:
-            ready = select.select([self._socket()], [], [], self.options['read_timeout'])
-            if len(ready[0]) > 0:
-                type = self.read_bytes(1)
-                size = unpack('!I', self.read_bytes(4))[0]
-
-                if size < 4:
-                    raise errors.MessageError(
-                        "Bad message size: {0}".format(size)
-                    )
-                message = BackendMessage.factory(type, self.read_bytes(size - 4))
-                logger.debug('<= %s', message)
-                return message
-            else:
-                self.close()
-                raise errors.TimedOutError("Connection timed out")
-        except errors.TimedOutError:
-            raise
-        except Exception as e:
+            type = self.read_bytes(1)
+            size = unpack('!I', self.read_bytes(4))[0]
+
+            if size < 4:
+                raise errors.MessageError(
+                    "Bad message size: {0}".format(size)
+                )
+            message = BackendMessage.factory(type, self.read_bytes(size - 4))
+            logger.debug('<= %s', message)
+            return message
+        except (SystemError, IOError) as e:
             self.close_socket()
             raise errors.ConnectionError(e.message)
 
diff --git a/vertica_python/vertica/cursor.py b/vertica_python/vertica/cursor.py
index 4389951..611ffb9 100644
--- a/vertica_python/vertica/cursor.py
+++ b/vertica_python/vertica/cursor.py
@@ -3,6 +3,8 @@ from __future__ import absolute_import
 import re
 import logging
 
+from ordereddict import OrderedDict
+
 import vertica_python.errors as errors
 
 import vertica_python.vertica.messages as messages
@@ -249,7 +251,7 @@ class Cursor(object):
             raise Exception('Unrecognized cursor_type: %r' % self.cursor_type)
 
     def format_row_as_dict(self, row_data):
-        return dict(
+        return OrderedDict(
             (self.description[idx].name, self.description[idx].convert(value))
             for idx, value in enumerate(row_data.values)
         )

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-vertica.git



More information about the Python-modules-commits mailing list