本文整理汇总了Python中psycopg2.extras.Range方法的典型用法代码示例。如果您正苦于以下问题:Python extras.Range方法的具体用法?Python extras.Range怎么用?Python extras.Range使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psycopg2.extras
的用法示例。
在下文中一共展示了extras.Range方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: jsonify
# 需要导入模块: from psycopg2 import extras [as 别名]
# 或者: from psycopg2.extras import Range [as 别名]
def jsonify(obj, *, raise_exception=False) -> object:
"""Convert the given object to something JSON can handle."""
if isinstance(obj, Base):
return obj._asdict()
if isinstance(obj, bytes):
return obj.decode()
if isinstance(obj, (datetime.date, datetime.time)):
return obj.isoformat()
if isinstance(obj, Decimal): # might want to return a string instead
return float(obj)
if isinstance(obj, Range):
left, right = obj._bounds
return '{}{},{}{}'.format(left, obj.lower, obj.upper, right)
if raise_exception:
raise NotJSONifiableError(obj)
return obj
# Might want to use restless.utils.MoreTypesJSONEncoder as base class
示例2: default
# 需要导入模块: from psycopg2 import extras [as 别名]
# 或者: from psycopg2.extras import Range [as 别名]
def default(self, obj):
"""Handle special types for json.dumps.
If obj is a model from dokomoforms.models, return a dictionary
representation.
If obj is a datetime.date or datetime.time, return an
ISO 8601 representation string.
If obj is a psycpg2 Range, return its string representation.
Otherwise, throw a TypeError.
See
https://docs.python.org/3/library/json.html#json.JSONEncoder.default
"""
try:
return jsonify(obj, raise_exception=True)
except NotJSONifiableError:
return super().default(obj)
示例3: test_keywords
# 需要导入模块: from psycopg2 import extras [as 别名]
# 或者: from psycopg2.extras import Range [as 别名]
def test_keywords(self):
from psycopg2.extras import Range
r = Range(upper=20)
self.assertEqual(r.lower, None)
self.assertEqual(r.upper, 20)
self.assert_(not r.isempty)
self.assert_(r.lower_inf)
self.assert_(not r.upper_inf)
self.assert_(not r.lower_inc)
self.assert_(not r.upper_inc)
r = Range(lower=10, bounds='(]')
self.assertEqual(r.lower, 10)
self.assertEqual(r.upper, None)
self.assert_(not r.isempty)
self.assert_(not r.lower_inf)
self.assert_(r.upper_inf)
self.assert_(not r.lower_inc)
self.assert_(not r.upper_inc)
示例4: test_eq_hash
# 需要导入模块: from psycopg2 import extras [as 别名]
# 或者: from psycopg2.extras import Range [as 别名]
def test_eq_hash(self):
from psycopg2.extras import Range
def assert_equal(r1, r2):
self.assert_(r1 == r2)
self.assert_(hash(r1) == hash(r2))
assert_equal(Range(empty=True), Range(empty=True))
assert_equal(Range(), Range())
assert_equal(Range(10, None), Range(10, None))
assert_equal(Range(10, 20), Range(10, 20))
assert_equal(Range(10, 20), Range(10, 20, '[)'))
assert_equal(Range(10, 20, '[]'), Range(10, 20, '[]'))
def assert_not_equal(r1, r2):
self.assert_(r1 != r2)
self.assert_(hash(r1) != hash(r2))
assert_not_equal(Range(10, 20), Range(10, 21))
assert_not_equal(Range(10, 20), Range(11, 20))
assert_not_equal(Range(10, 20, '[)'), Range(10, 20, '[]'))
示例5: get_prep_value
# 需要导入模块: from psycopg2 import extras [as 别名]
# 或者: from psycopg2.extras import Range [as 别名]
def get_prep_value(self, value):
if value is None:
return None
elif isinstance(value, Range):
return value
elif isinstance(value, (list, tuple)):
return self.range_type(value[0], value[1])
return value
示例6: test_noparam
# 需要导入模块: from psycopg2 import extras [as 别名]
# 或者: from psycopg2.extras import Range [as 别名]
def test_noparam(self):
from psycopg2.extras import Range
r = Range()
self.assert_(not r.isempty)
self.assertEqual(r.lower, None)
self.assertEqual(r.upper, None)
self.assert_(r.lower_inf)
self.assert_(r.upper_inf)
self.assert_(not r.lower_inc)
self.assert_(not r.upper_inc)
示例7: test_empty
# 需要导入模块: from psycopg2 import extras [as 别名]
# 或者: from psycopg2.extras import Range [as 别名]
def test_empty(self):
from psycopg2.extras import Range
r = Range(empty=True)
self.assert_(r.isempty)
self.assertEqual(r.lower, None)
self.assertEqual(r.upper, None)
self.assert_(not r.lower_inf)
self.assert_(not r.upper_inf)
self.assert_(not r.lower_inc)
self.assert_(not r.upper_inc)
示例8: test_nobounds
# 需要导入模块: from psycopg2 import extras [as 别名]
# 或者: from psycopg2.extras import Range [as 别名]
def test_nobounds(self):
from psycopg2.extras import Range
r = Range(10, 20)
self.assertEqual(r.lower, 10)
self.assertEqual(r.upper, 20)
self.assert_(not r.isempty)
self.assert_(not r.lower_inf)
self.assert_(not r.upper_inf)
self.assert_(r.lower_inc)
self.assert_(not r.upper_inc)
示例9: test_bounds
# 需要导入模块: from psycopg2 import extras [as 别名]
# 或者: from psycopg2.extras import Range [as 别名]
def test_bounds(self):
from psycopg2.extras import Range
for bounds, lower_inc, upper_inc in [
('[)', True, False),
('(]', False, True),
('()', False, False),
('[]', True, True),]:
r = Range(10, 20, bounds)
self.assertEqual(r.lower, 10)
self.assertEqual(r.upper, 20)
self.assert_(not r.isempty)
self.assert_(not r.lower_inf)
self.assert_(not r.upper_inf)
self.assertEqual(r.lower_inc, lower_inc)
self.assertEqual(r.upper_inc, upper_inc)
示例10: test_nonzero
# 需要导入模块: from psycopg2 import extras [as 别名]
# 或者: from psycopg2.extras import Range [as 别名]
def test_nonzero(self):
from psycopg2.extras import Range
self.assert_(Range())
self.assert_(Range(10, 20))
self.assert_(not Range(empty=True))
示例11: test_eq_wrong_type
# 需要导入模块: from psycopg2 import extras [as 别名]
# 或者: from psycopg2.extras import Range [as 别名]
def test_eq_wrong_type(self):
from psycopg2.extras import Range
self.assertNotEqual(Range(10, 20), ())
示例12: test_eq_subclass
# 需要导入模块: from psycopg2 import extras [as 别名]
# 或者: from psycopg2.extras import Range [as 别名]
def test_eq_subclass(self):
from psycopg2.extras import Range, NumericRange
class IntRange(NumericRange): pass
class PositiveIntRange(IntRange): pass
self.assertEqual(Range(10, 20), IntRange(10, 20))
self.assertEqual(PositiveIntRange(10, 20), IntRange(10, 20))
# as the postgres docs describe for the server-side stuff,
# ordering is rather arbitrary, but will remain stable
# and consistent.
示例13: test_gt_ordering
# 需要导入模块: from psycopg2 import extras [as 别名]
# 或者: from psycopg2.extras import Range [as 别名]
def test_gt_ordering(self):
from psycopg2.extras import Range
self.assert_(not Range(empty=True) > Range(0, 4))
self.assert_(Range(1, 2) > Range(0, 4))
self.assert_(not Range(0, 4) > Range(1, 2))
self.assert_(Range(1, 2) > Range())
self.assert_(not Range() > Range(1, 2))
self.assert_(Range(1) > Range(upper=1))
self.assert_(not Range() > Range())
self.assert_(not Range(empty=True) > Range(empty=True))
self.assert_(not Range(1, 2) > Range(1, 2))
with py3_raises_typeerror():
self.assert_(not 1 > Range(1, 2))
with py3_raises_typeerror():
self.assert_(Range(1, 2) > 1)
示例14: test_le_ordering
# 需要导入模块: from psycopg2 import extras [as 别名]
# 或者: from psycopg2.extras import Range [as 别名]
def test_le_ordering(self):
from psycopg2.extras import Range
self.assert_(Range(empty=True) <= Range(0, 4))
self.assert_(not Range(1, 2) <= Range(0, 4))
self.assert_(Range(0, 4) <= Range(1, 2))
self.assert_(not Range(1, 2) <= Range())
self.assert_(Range() <= Range(1, 2))
self.assert_(not Range(1) <= Range(upper=1))
self.assert_(Range() <= Range())
self.assert_(Range(empty=True) <= Range(empty=True))
self.assert_(Range(1, 2) <= Range(1, 2))
with py3_raises_typeerror():
self.assert_(1 <= Range(1, 2))
with py3_raises_typeerror():
self.assert_(not Range(1, 2) <= 1)
示例15: test_ge_ordering
# 需要导入模块: from psycopg2 import extras [as 别名]
# 或者: from psycopg2.extras import Range [as 别名]
def test_ge_ordering(self):
from psycopg2.extras import Range
self.assert_(not Range(empty=True) >= Range(0, 4))
self.assert_(Range(1, 2) >= Range(0, 4))
self.assert_(not Range(0, 4) >= Range(1, 2))
self.assert_(Range(1, 2) >= Range())
self.assert_(not Range() >= Range(1, 2))
self.assert_(Range(1) >= Range(upper=1))
self.assert_(Range() >= Range())
self.assert_(Range(empty=True) >= Range(empty=True))
self.assert_(Range(1, 2) >= Range(1, 2))
with py3_raises_typeerror():
self.assert_(not 1 >= Range(1, 2))
with py3_raises_typeerror():
self.assert_(Range(1, 2) >= 1)