當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。