当前位置: 首页>>代码示例>>Python>>正文


Python extras.Range方法代码示例

本文整理汇总了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 
开发者ID:SEL-Columbia,项目名称:dokomoforms,代码行数:22,代码来源:util.py

示例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) 
开发者ID:SEL-Columbia,项目名称:dokomoforms,代码行数:22,代码来源:util.py

示例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) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:21,代码来源:test_types_extras.py

示例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, '[]')) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:22,代码来源:test_types_extras.py

示例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 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:10,代码来源:ranges.py

示例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) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:13,代码来源:test_types_extras.py

示例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) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:13,代码来源:test_types_extras.py

示例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) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:12,代码来源:test_types_extras.py

示例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) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:17,代码来源:test_types_extras.py

示例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)) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:7,代码来源:test_types_extras.py

示例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), ()) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:5,代码来源:test_types_extras.py

示例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. 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:14,代码来源:test_types_extras.py

示例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) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:17,代码来源:test_types_extras.py

示例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) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:17,代码来源:test_types_extras.py

示例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) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:17,代码来源:test_types_extras.py


注:本文中的psycopg2.extras.Range方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。