當前位置: 首頁>>代碼示例>>Python>>正文


Python tzinfo.__new__方法代碼示例

本文整理匯總了Python中datetime.tzinfo.__new__方法的典型用法代碼示例。如果您正苦於以下問題:Python tzinfo.__new__方法的具體用法?Python tzinfo.__new__怎麽用?Python tzinfo.__new__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在datetime.tzinfo的用法示例。


在下文中一共展示了tzinfo.__new__方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __new__

# 需要導入模塊: from datetime import tzinfo [as 別名]
# 或者: from datetime.tzinfo import __new__ [as 別名]
def __new__(cls, offset, name=_Omitted):
            if not isinstance(offset, timedelta):
                raise TypeError("offset must be a timedelta")
            if name is cls._Omitted:
                if not offset:
                    return cls.utc
                name = None
            elif not isinstance(name, str):
                raise TypeError("name must be a string")
            if not cls._minoffset <= offset <= cls._maxoffset:
                raise ValueError(
                    "offset must be a timedelta "
                    "strictly between -timedelta(hours=24) and "
                    "timedelta(hours=24)."
                )
            return cls._create(offset, name) 
開發者ID:sdispater,項目名稱:tomlkit,代碼行數:18,代碼來源:_compat.py

示例2: test_subclass_date

# 需要導入模塊: from datetime import tzinfo [as 別名]
# 或者: from datetime.tzinfo import __new__ [as 別名]
def test_subclass_date(self):

        class C(self.theclass):
            theAnswer = 42

            def __new__(cls, *args, **kws):
                temp = kws.copy()
                extra = temp.pop('extra')
                result = self.theclass.__new__(cls, *args, **temp)
                result.extra = extra
                return result

            def newmeth(self, start):
                return start + self.year + self.month

        args = 2003, 4, 14

        dt1 = self.theclass(*args)
        dt2 = C(*args, **{'extra': 7})

        self.assertEqual(dt2.__class__, C)
        self.assertEqual(dt2.theAnswer, 42)
        self.assertEqual(dt2.extra, 7)
        self.assertEqual(dt1.toordinal(), dt2.toordinal())
        self.assertEqual(dt2.newmeth(-7), dt1.year + dt1.month - 7) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:test_datetime.py

示例3: test_subclass_time

# 需要導入模塊: from datetime import tzinfo [as 別名]
# 或者: from datetime.tzinfo import __new__ [as 別名]
def test_subclass_time(self):

        class C(self.theclass):
            theAnswer = 42

            def __new__(cls, *args, **kws):
                temp = kws.copy()
                extra = temp.pop('extra')
                result = self.theclass.__new__(cls, *args, **temp)
                result.extra = extra
                return result

            def newmeth(self, start):
                return start + self.hour + self.second

        args = 4, 5, 6

        dt1 = self.theclass(*args)
        dt2 = C(*args, **{'extra': 7})

        self.assertEqual(dt2.__class__, C)
        self.assertEqual(dt2.theAnswer, 42)
        self.assertEqual(dt2.extra, 7)
        self.assertEqual(dt1.isoformat(), dt2.isoformat())
        self.assertEqual(dt2.newmeth(-7), dt1.hour + dt1.second - 7) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:27,代碼來源:test_datetime.py

示例4: _create

# 需要導入模塊: from datetime import tzinfo [as 別名]
# 或者: from datetime.tzinfo import __new__ [as 別名]
def _create(cls, offset, name=None):
            self = tzinfo.__new__(cls)
            self._offset = offset
            self._name = name
            return self 
開發者ID:sdispater,項目名稱:tomlkit,代碼行數:7,代碼來源:_compat.py

示例5: test_pickling_base

# 需要導入模塊: from datetime import tzinfo [as 別名]
# 或者: from datetime.tzinfo import __new__ [as 別名]
def test_pickling_base(self):
        # There's no point to pickling tzinfo objects on their own (they
        # carry no data), but they need to be picklable anyway else
        # concrete subclasses can't be pickled.
        orig = tzinfo.__new__(tzinfo)
        self.assertIs(type(orig), tzinfo)
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertIs(type(derived), tzinfo) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_datetime.py

示例6: test_subclass_datetime

# 需要導入模塊: from datetime import tzinfo [as 別名]
# 或者: from datetime.tzinfo import __new__ [as 別名]
def test_subclass_datetime(self):

        class C(self.theclass):
            theAnswer = 42

            def __new__(cls, *args, **kws):
                temp = kws.copy()
                extra = temp.pop('extra')
                result = self.theclass.__new__(cls, *args, **temp)
                result.extra = extra
                return result

            def newmeth(self, start):
                return start + self.year + self.month + self.second

        args = 2003, 4, 14, 12, 13, 41

        dt1 = self.theclass(*args)
        dt2 = C(*args, **{'extra': 7})

        self.assertEqual(dt2.__class__, C)
        self.assertEqual(dt2.theAnswer, 42)
        self.assertEqual(dt2.extra, 7)
        self.assertEqual(dt1.toordinal(), dt2.toordinal())
        self.assertEqual(dt2.newmeth(-7), dt1.year + dt1.month +
                                          dt1.second - 7) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:28,代碼來源:test_datetime.py

示例7: test_subclass_timetz

# 需要導入模塊: from datetime import tzinfo [as 別名]
# 或者: from datetime.tzinfo import __new__ [as 別名]
def test_subclass_timetz(self):

        class C(self.theclass):
            theAnswer = 42

            def __new__(cls, *args, **kws):
                temp = kws.copy()
                extra = temp.pop('extra')
                result = self.theclass.__new__(cls, *args, **temp)
                result.extra = extra
                return result

            def newmeth(self, start):
                return start + self.hour + self.second

        args = 4, 5, 6, 500, FixedOffset(-300, "EST", 1)

        dt1 = self.theclass(*args)
        dt2 = C(*args, **{'extra': 7})

        self.assertEqual(dt2.__class__, C)
        self.assertEqual(dt2.theAnswer, 42)
        self.assertEqual(dt2.extra, 7)
        self.assertEqual(dt1.utcoffset(), dt2.utcoffset())
        self.assertEqual(dt2.newmeth(-7), dt1.hour + dt1.second - 7)


# Testing datetime objects with a non-None tzinfo. 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:30,代碼來源:test_datetime.py

示例8: test_pickling_base

# 需要導入模塊: from datetime import tzinfo [as 別名]
# 或者: from datetime.tzinfo import __new__ [as 別名]
def test_pickling_base(self):
        # There's no point to pickling tzinfo objects on their own (they
        # carry no data), but they need to be picklable anyway else
        # concrete subclasses can't be pickled.
        orig = tzinfo.__new__(tzinfo)
        self.assertTrue(type(orig) is tzinfo)
        for pickler, unpickler, proto in pickle_choices:
            green = pickler.dumps(orig, proto)
            derived = unpickler.loads(green)
            self.assertTrue(type(derived) is tzinfo) 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:12,代碼來源:test_datetime.py


注:本文中的datetime.tzinfo.__new__方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。