本文整理汇总了Python中psycopg2.InterfaceError方法的典型用法代码示例。如果您正苦于以下问题:Python psycopg2.InterfaceError方法的具体用法?Python psycopg2.InterfaceError怎么用?Python psycopg2.InterfaceError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psycopg2
的用法示例。
在下文中一共展示了psycopg2.InterfaceError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_exit_without_active_connection
# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import InterfaceError [as 别名]
def test_exit_without_active_connection(executor):
quit_handler = MagicMock()
pgspecial = PGSpecial()
pgspecial.register(
quit_handler,
"\\q",
"\\q",
"Quit pgcli.",
arg_type=NO_QUERY,
case_sensitive=True,
aliases=(":q",),
)
with patch.object(executor, "conn", BrokenConnection()):
# we should be able to quit the app, even without active connection
run(executor, "\\q", pgspecial=pgspecial)
quit_handler.assert_called_once()
# an exception should be raised when running a query without active connection
with pytest.raises(psycopg2.InterfaceError):
run(executor, "select 1", pgspecial=pgspecial)
示例2: process
# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import InterfaceError [as 别名]
def process(self):
"""
Process the current cost usage report.
Args:
None
Returns:
(List) List of filenames downloaded.
"""
try:
return self._processor.process()
except (InterfaceError, DjangoInterfaceError, OperationalError) as err:
raise ReportProcessorDBError(str(err))
except Exception as err:
raise ReportProcessorError(str(err))
示例3: test_closing_in_separate_task
# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import InterfaceError [as 别名]
def test_closing_in_separate_task(connect, loop):
closed_event = asyncio.Event(loop=loop)
exec_created = asyncio.Event(loop=loop)
async def waiter(conn):
cur = await conn.cursor()
fut = cur.execute("SELECT pg_sleep(1000)")
exec_created.set()
await closed_event.wait()
with pytest.raises(psycopg2.InterfaceError):
await fut
async def closer(conn):
await exec_created.wait()
await conn.close()
closed_event.set()
conn = await connect()
await asyncio.gather(waiter(conn), closer(conn), loop=loop)
示例4: cursor
# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import InterfaceError [as 别名]
def cursor(self):
raise psycopg2.InterfaceError("I'm broken!")
示例5: parse
# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import InterfaceError [as 别名]
def parse(self, s, cur, _bsdec=_re.compile(r"\\(.)")):
"""Parse an hstore representation in a Python string.
The hstore is represented as something like::
"a"=>"1", "b"=>"2"
with backslash-escaped strings.
"""
if s is None:
return None
rv = {}
start = 0
for m in self._re_hstore.finditer(s):
if m is None or m.start() != start:
raise psycopg2.InterfaceError(
"error parsing hstore pair at char %d" % start)
k = _bsdec.sub(r'\1', m.group(1))
v = m.group(2)
if v is not None:
v = _bsdec.sub(r'\1', v)
rv[k] = v
start = m.end()
if start < len(s):
raise psycopg2.InterfaceError(
"error parsing hstore: unparsed data after char %d" % start)
return rv
示例6: tokenize
# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import InterfaceError [as 别名]
def tokenize(self, s):
rv = []
for m in self._re_tokenize.finditer(s):
if m is None:
raise psycopg2.InterfaceError("can't parse type: %r" % s)
if m.group(1) is not None:
rv.append(None)
elif m.group(2) is not None:
rv.append(self._re_undouble.sub(r"\1", m.group(2)))
else:
rv.append(m.group(3))
return rv
示例7: __init__
# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import InterfaceError [as 别名]
def __init__(self, config, local_config=None):
"""Initialize the parts needed to start making database connections
parameters:
config - the complete config for the app. If a real app, this
would be where a logger or other resources could be
found.
local_config - this is the namespace within the complete config
where the actual database parameters are found"""
super(ConnectionFactory, self).__init__()
self.config = config
if local_config is None:
local_config = config
self.dsn = (
"host=%(host)s "
"dbname=%(dbname)s "
"port=%(port)s "
"user=%(user)s "
"password=%(password)s"
% local_config
)
self.operational_exceptions = (
psycopg2.OperationalError,
psycopg2.InterfaceError,
socket.timeout
)
self.conditional_exceptions = (
psycopg2.ProgrammingError,
)
self.pool = {}
#--------------------------------------------------------------------------
示例8: cursor
# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import InterfaceError [as 别名]
def cursor(self):
"""Get a cursor, making sure the connection to the database is established."""
try:
cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
except psycopg2.InterfaceError:
self._connect()
cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
try:
cur.execute('SET search_path TO {},public'.format(self.schema))
except psycopg2.InternalError:
self._connect()
cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute('SET search_path TO {},public'.format(self.schema))
return cur
示例9: test_async_cursor_gone
# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import InterfaceError [as 别名]
def test_async_cursor_gone(self):
import gc
cur = self.conn.cursor()
cur.execute("select 42;");
del cur
gc.collect()
self.assertRaises(psycopg2.InterfaceError, self.wait, self.conn)
# The connection is still usable
cur = self.conn.cursor()
cur.execute("select 42;");
self.wait(self.conn)
self.assertEqual(cur.fetchone(), (42,))
示例10: test_with_closed
# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import InterfaceError [as 别名]
def test_with_closed(self):
def f():
with self.conn:
pass
self.conn.close()
self.assertRaises(psycopg2.InterfaceError, f)
示例11: test_isolation_level_closed
# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import InterfaceError [as 别名]
def test_isolation_level_closed(self):
cnn = self.connect()
cnn.close()
self.assertRaises(psycopg2.InterfaceError, getattr,
cnn, 'isolation_level')
self.assertRaises(psycopg2.InterfaceError,
cnn.set_isolation_level, 0)
self.assertRaises(psycopg2.InterfaceError,
cnn.set_isolation_level, 1)
示例12: test_closed
# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import InterfaceError [as 别名]
def test_closed(self):
self.conn.close()
self.assertRaises(psycopg2.InterfaceError,
self.conn.set_session,
psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE)
示例13: test_parse
# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import InterfaceError [as 别名]
def test_parse(self):
from psycopg2.extras import HstoreAdapter
def ok(s, d):
self.assertEqual(HstoreAdapter.parse(s, None), d)
ok(None, None)
ok('', {})
ok('"a"=>"1", "b"=>"2"', {'a': '1', 'b': '2'})
ok('"a" => "1" ,"b" => "2"', {'a': '1', 'b': '2'})
ok('"a"=>NULL, "b"=>"2"', {'a': None, 'b': '2'})
ok(r'"a"=>"\"", "\""=>"2"', {'a': '"', '"': '2'})
ok('"a"=>"\'", "\'"=>"2"', {'a': "'", "'": '2'})
ok('"a"=>"1", "b"=>NULL', {'a': '1', 'b': None})
ok(r'"a\\"=>"1"', {'a\\': '1'})
ok(r'"a\""=>"1"', {'a"': '1'})
ok(r'"a\\\""=>"1"', {r'a\"': '1'})
ok(r'"a\\\\\""=>"1"', {r'a\\"': '1'})
def ko(s):
self.assertRaises(psycopg2.InterfaceError,
HstoreAdapter.parse, s, None)
ko('a')
ko('"a"')
ko(r'"a\\""=>"1"')
ko(r'"a\\\\""=>"1"')
ko('"a=>"1"')
ko('"a"=>"1", "b"=>NUL')
示例14: test_write_after_close
# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import InterfaceError [as 别名]
def test_write_after_close(self):
lo = self.conn.lobject()
lo.close()
self.assertRaises(psycopg2.InterfaceError, lo.write, b("some data"))
示例15: test_read_after_close
# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import InterfaceError [as 别名]
def test_read_after_close(self):
lo = self.conn.lobject()
lo.close()
self.assertRaises(psycopg2.InterfaceError, lo.read, 5)