|
8 | 8 |
|
9 | 9 | $ pip install postgres
|
10 | 10 |
|
| 11 | +We `test <https://travis-ci.org/gittip/postgres.py>`_ against Python 2.6, 2.7, |
| 12 | +3.2, and 3.3. We don't yet have a testing matrix for different versions of |
| 13 | +:py:mod:`psycopg2` or PostgreSQL. |
| 14 | +
|
| 15 | +Importing :py:mod:`postgres` under Python 2 will cause the registration of |
| 16 | +typecasters in psycopg2 to ensure that you get unicode instead of bytestrings |
| 17 | +for text data, according to `this advice`_. |
| 18 | +
|
11 | 19 |
|
12 | 20 | Tutorial
|
13 | 21 | --------
|
|
128 | 136 | .. _psycopg2: http://initd.org/psycopg/
|
129 | 137 | .. _GitHub: https://github.com/gittip/postgres
|
130 | 138 | .. _PyPI: https://pypi.python.org/pypi/postgres
|
| 139 | +.. _this advice: http://initd.org/psycopg/docs/usage.html#unicode-handling |
131 | 140 | .. _DB-API 2.0: http://www.python.org/dev/peps/pep-0249/
|
132 | 141 | .. _SQL injection: http://en.wikipedia.org/wiki/SQL_injection
|
133 | 142 |
|
|
136 | 145 |
|
137 | 146 | try: # Python 2
|
138 | 147 | import urlparse
|
139 |
| -except ImportError: # Python 3 |
140 |
| - import urllib.parse as urlparse |
141 | 148 |
|
142 |
| -import psycopg2 |
| 149 | + # "Note: In Python 2, if you want to uniformly receive all your database |
| 150 | + # input in Unicode, you can register the related typecasters globally as |
| 151 | + # soon as Psycopg is imported." |
| 152 | + # -- http://initd.org/psycopg/docs/usage.html#unicode-handling |
143 | 153 |
|
144 |
| -# "Note: In Python 2, if you want to uniformly receive all your database input |
145 |
| -# in Unicode, you can register the related typecasters globally as soon as |
146 |
| -# Psycopg is imported." |
147 |
| -# -- http://initd.org/psycopg/docs/usage.html#unicode-handling |
| 154 | + import psycopg2.extensions |
| 155 | + psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) |
| 156 | + psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY) |
148 | 157 |
|
149 |
| -import psycopg2.extensions |
150 |
| -psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) |
151 |
| -psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY) |
| 158 | +except ImportError: # Python 3 |
| 159 | + import urllib.parse as urlparse |
152 | 160 |
|
| 161 | +import psycopg2 |
153 | 162 | from psycopg2.extras import RealDictCursor
|
154 | 163 | from psycopg2.pool import ThreadedConnectionPool as ConnectionPool
|
155 | 164 |
|
@@ -225,10 +234,6 @@ class Postgres(object):
|
225 | 234 | not our simple API (:py:meth:`~postgres.Postgres.run` /
|
226 | 235 | :py:meth:`~postgres.Postgres.one` / :py:meth:`~postgres.Postgres.rows`).
|
227 | 236 |
|
228 |
| - Features: |
229 |
| -
|
230 |
| - - Get back unicode instead of bytestrings. |
231 |
| -
|
232 | 237 | >>> import postgres
|
233 | 238 | >>> db = postgres.Postgres("postgres://jrandom@localhost/test")
|
234 | 239 |
|
|
0 commit comments