mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-25 10:23:43 +03:00
Dropped __all__ from modules
They were only used to generate docs with Epydoc, now largely forgotten. Imports in extras cleaned up to expose the API only.
This commit is contained in:
parent
d5d6a1f4c7
commit
2b554937f2
|
@ -166,7 +166,3 @@ def connect(dsn=None,
|
||||||
conn.cursor_factory = cursor_factory
|
conn.cursor_factory = cursor_factory
|
||||||
|
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
|
|
||||||
__all__ = filter(lambda k: not k.startswith('_'), locals().keys())
|
|
||||||
|
|
||||||
|
|
|
@ -175,5 +175,3 @@ for k, v in encodings.items():
|
||||||
encodings[k] = v
|
encodings[k] = v
|
||||||
|
|
||||||
del k, v
|
del k, v
|
||||||
|
|
||||||
__all__ = filter(lambda k: not k.startswith('_'), locals().keys())
|
|
||||||
|
|
|
@ -25,16 +25,15 @@ and classes untill a better place in the distribution is found.
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||||
# License for more details.
|
# License for more details.
|
||||||
|
|
||||||
import os
|
import os as _os
|
||||||
import sys
|
import sys as _sys
|
||||||
import time
|
import time as _time
|
||||||
import warnings
|
import re as _re
|
||||||
import re as regex
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import logging
|
import logging as _logging
|
||||||
except:
|
except:
|
||||||
logging = None
|
_logging = None
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from psycopg2 import extensions as _ext
|
from psycopg2 import extensions as _ext
|
||||||
|
@ -192,7 +191,7 @@ class DictRow(list):
|
||||||
self._index = data[1]
|
self._index = data[1]
|
||||||
|
|
||||||
# drop the crusty Py2 methods
|
# drop the crusty Py2 methods
|
||||||
if sys.version_info[0] > 2:
|
if _sys.version_info[0] > 2:
|
||||||
items = iteritems; del iteritems
|
items = iteritems; del iteritems
|
||||||
keys = iterkeys; del iterkeys
|
keys = iterkeys; del iterkeys
|
||||||
values = itervalues; del itervalues
|
values = itervalues; del itervalues
|
||||||
|
@ -354,7 +353,7 @@ class LoggingConnection(_connection):
|
||||||
instance from the standard logging module.
|
instance from the standard logging module.
|
||||||
"""
|
"""
|
||||||
self._logobj = logobj
|
self._logobj = logobj
|
||||||
if logging and isinstance(logobj, logging.Logger):
|
if _logging and isinstance(logobj, _logging.Logger):
|
||||||
self.log = self._logtologger
|
self.log = self._logtologger
|
||||||
else:
|
else:
|
||||||
self.log = self._logtofile
|
self.log = self._logtofile
|
||||||
|
@ -370,7 +369,7 @@ class LoggingConnection(_connection):
|
||||||
|
|
||||||
def _logtofile(self, msg, curs):
|
def _logtofile(self, msg, curs):
|
||||||
msg = self.filter(msg, curs)
|
msg = self.filter(msg, curs)
|
||||||
if msg: self._logobj.write(msg + os.linesep)
|
if msg: self._logobj.write(msg + _os.linesep)
|
||||||
|
|
||||||
def _logtologger(self, msg, curs):
|
def _logtologger(self, msg, curs):
|
||||||
msg = self.filter(msg, curs)
|
msg = self.filter(msg, curs)
|
||||||
|
@ -418,9 +417,9 @@ class MinTimeLoggingConnection(LoggingConnection):
|
||||||
self._mintime = mintime
|
self._mintime = mintime
|
||||||
|
|
||||||
def filter(self, msg, curs):
|
def filter(self, msg, curs):
|
||||||
t = (time.time() - curs.timestamp) * 1000
|
t = (_time.time() - curs.timestamp) * 1000
|
||||||
if t > self._mintime:
|
if t > self._mintime:
|
||||||
return msg + os.linesep + " (execution time: %d ms)" % t
|
return msg + _os.linesep + " (execution time: %d ms)" % t
|
||||||
|
|
||||||
def cursor(self, *args, **kwargs):
|
def cursor(self, *args, **kwargs):
|
||||||
kwargs.setdefault('cursor_factory', MinTimeLoggingCursor)
|
kwargs.setdefault('cursor_factory', MinTimeLoggingCursor)
|
||||||
|
@ -430,11 +429,11 @@ class MinTimeLoggingCursor(LoggingCursor):
|
||||||
"""The cursor sub-class companion to `MinTimeLoggingConnection`."""
|
"""The cursor sub-class companion to `MinTimeLoggingConnection`."""
|
||||||
|
|
||||||
def execute(self, query, vars=None):
|
def execute(self, query, vars=None):
|
||||||
self.timestamp = time.time()
|
self.timestamp = _time.time()
|
||||||
return LoggingCursor.execute(self, query, vars)
|
return LoggingCursor.execute(self, query, vars)
|
||||||
|
|
||||||
def callproc(self, procname, vars=None):
|
def callproc(self, procname, vars=None):
|
||||||
self.timestamp = time.time()
|
self.timestamp = _time.time()
|
||||||
return LoggingCursor.execute(self, procname, vars)
|
return LoggingCursor.execute(self, procname, vars)
|
||||||
|
|
||||||
|
|
||||||
|
@ -558,20 +557,21 @@ def register_tstz_w_secs(oids=None, conn_or_curs=None):
|
||||||
These are now correctly handled by the default type caster, so currently
|
These are now correctly handled by the default type caster, so currently
|
||||||
the function doesn't do anything.
|
the function doesn't do anything.
|
||||||
"""
|
"""
|
||||||
|
import warnings
|
||||||
warnings.warn("deprecated", DeprecationWarning)
|
warnings.warn("deprecated", DeprecationWarning)
|
||||||
|
|
||||||
|
|
||||||
import select
|
|
||||||
from psycopg2.extensions import POLL_OK, POLL_READ, POLL_WRITE
|
|
||||||
from psycopg2 import OperationalError
|
|
||||||
|
|
||||||
def wait_select(conn):
|
def wait_select(conn):
|
||||||
"""Wait until a connection or cursor has data available.
|
"""Wait until a connection or cursor has data available.
|
||||||
|
|
||||||
The function is an example of a wait callback to be registered with
|
The function is an example of a wait callback to be registered with
|
||||||
`~psycopg2.extensions.set_wait_callback()`. This function uses `!select()`
|
`~psycopg2.extensions.set_wait_callback()`. This function uses
|
||||||
to wait for data available.
|
:py:func:`~select.select()` to wait for data available.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
import select
|
||||||
|
from psycopg2.extensions import POLL_OK, POLL_READ, POLL_WRITE
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
state = conn.poll()
|
state = conn.poll()
|
||||||
if state == POLL_OK:
|
if state == POLL_OK:
|
||||||
|
@ -581,7 +581,7 @@ def wait_select(conn):
|
||||||
elif state == POLL_WRITE:
|
elif state == POLL_WRITE:
|
||||||
select.select([], [conn.fileno()], [])
|
select.select([], [conn.fileno()], [])
|
||||||
else:
|
else:
|
||||||
raise OperationalError("bad state from poll: %s" % state)
|
raise conn.OperationalError("bad state from poll: %s" % state)
|
||||||
|
|
||||||
|
|
||||||
def _solve_conn_curs(conn_or_curs):
|
def _solve_conn_curs(conn_or_curs):
|
||||||
|
@ -648,7 +648,7 @@ class HstoreAdapter(object):
|
||||||
|
|
||||||
getquoted = _getquoted_9
|
getquoted = _getquoted_9
|
||||||
|
|
||||||
_re_hstore = regex.compile(r"""
|
_re_hstore = _re.compile(r"""
|
||||||
# hstore key:
|
# hstore key:
|
||||||
# a string of normal or escaped chars
|
# a string of normal or escaped chars
|
||||||
"((?: [^"\\] | \\. )*)"
|
"((?: [^"\\] | \\. )*)"
|
||||||
|
@ -659,10 +659,10 @@ class HstoreAdapter(object):
|
||||||
| "((?: [^"\\] | \\. )*)"
|
| "((?: [^"\\] | \\. )*)"
|
||||||
)
|
)
|
||||||
(?:\s*,\s*|$) # pairs separated by comma or end of string.
|
(?:\s*,\s*|$) # pairs separated by comma or end of string.
|
||||||
""", regex.VERBOSE)
|
""", _re.VERBOSE)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse(self, s, cur, _bsdec=regex.compile(r"\\(.)")):
|
def parse(self, s, cur, _bsdec=_re.compile(r"\\(.)")):
|
||||||
"""Parse an hstore representation in a Python string.
|
"""Parse an hstore representation in a Python string.
|
||||||
|
|
||||||
The hstore is represented as something like::
|
The hstore is represented as something like::
|
||||||
|
@ -786,7 +786,7 @@ def register_hstore(conn_or_curs, globally=False, unicode=False,
|
||||||
array_oid = tuple([x for x in array_oid if x])
|
array_oid = tuple([x for x in array_oid if x])
|
||||||
|
|
||||||
# create and register the typecaster
|
# create and register the typecaster
|
||||||
if sys.version_info[0] < 3 and unicode:
|
if _sys.version_info[0] < 3 and unicode:
|
||||||
cast = HstoreAdapter.parse_unicode
|
cast = HstoreAdapter.parse_unicode
|
||||||
else:
|
else:
|
||||||
cast = HstoreAdapter.parse
|
cast = HstoreAdapter.parse
|
||||||
|
@ -852,13 +852,13 @@ class CompositeCaster(object):
|
||||||
|
|
||||||
return self._ctor(values)
|
return self._ctor(values)
|
||||||
|
|
||||||
_re_tokenize = regex.compile(r"""
|
_re_tokenize = _re.compile(r"""
|
||||||
\(? ([,)]) # an empty token, representing NULL
|
\(? ([,)]) # an empty token, representing NULL
|
||||||
| \(? " ((?: [^"] | "")*) " [,)] # or a quoted string
|
| \(? " ((?: [^"] | "")*) " [,)] # or a quoted string
|
||||||
| \(? ([^",)]+) [,)] # or an unquoted string
|
| \(? ([^",)]+) [,)] # or an unquoted string
|
||||||
""", regex.VERBOSE)
|
""", _re.VERBOSE)
|
||||||
|
|
||||||
_re_undouble = regex.compile(r'(["\\])\1')
|
_re_undouble = _re.compile(r'(["\\])\1')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def tokenize(self, s):
|
def tokenize(self, s):
|
||||||
|
@ -970,7 +970,3 @@ from psycopg2._json import json, Json, register_json, register_default_json
|
||||||
from psycopg2._range import Range, NumericRange
|
from psycopg2._range import Range, NumericRange
|
||||||
from psycopg2._range import DateRange, DateTimeRange, DateTimeTZRange
|
from psycopg2._range import DateRange, DateTimeRange, DateTimeTZRange
|
||||||
from psycopg2._range import register_range, RangeAdapter, RangeCaster
|
from psycopg2._range import register_range, RangeAdapter, RangeCaster
|
||||||
|
|
||||||
|
|
||||||
__all__ = filter(lambda k: not k.startswith('_'), locals().keys())
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user