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


Python copyreg.__newobj__方法代碼示例

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


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

示例1: test_issue24097

# 需要導入模塊: import copyreg [as 別名]
# 或者: from copyreg import __newobj__ [as 別名]
def test_issue24097(self):
        # Slot name is freed inside __getattr__ and is later used.
        class S(str):  # Not interned
            pass
        class A:
            __slotnames__ = [S('spam')]
            def __getattr__(self, attr):
                if attr == 'spam':
                    A.__slotnames__[:] = [S('spam')]
                    return 42
                else:
                    raise AttributeError

        import copyreg
        expected = (copyreg.__newobj__, (A,), (None, {'spam': 42}), None, None)
        self.assertEqual(A().__reduce__(2), expected)  # Shouldn't crash 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:18,代碼來源:test_descr.py

示例2: test_issue24097

# 需要導入模塊: import copyreg [as 別名]
# 或者: from copyreg import __newobj__ [as 別名]
def test_issue24097(self):
        # Slot name is freed inside __getattr__ and is later used.
        class S(str):  # Not interned
            pass
        class A:
            __slotnames__ = [S('spam')]
            def __getattr__(self, attr):
                if attr == 'spam':
                    A.__slotnames__[:] = [S('spam')]
                    return 42
                else:
                    raise AttributeError

        import copyreg
        expected = (copyreg.__newobj__, (A,), (None, {'spam': 42}), None, None)
        self.assertEqual(A().__reduce_ex__(2), expected)  # Shouldn't crash 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:18,代碼來源:test_descr.py

示例3: _check_reduce

# 需要導入模塊: import copyreg [as 別名]
# 或者: from copyreg import __newobj__ [as 別名]
def _check_reduce(self, proto, obj, args=(), kwargs={}, state=None,
                      listitems=None, dictitems=None):
        if proto >= 2:
            reduce_value = obj.__reduce_ex__(proto)
            if kwargs:
                self.assertEqual(reduce_value[0], copyreg.__newobj_ex__)
                self.assertEqual(reduce_value[1], (type(obj), args, kwargs))
            else:
                self.assertEqual(reduce_value[0], copyreg.__newobj__)
                self.assertEqual(reduce_value[1], (type(obj),) + args)
            self.assertEqual(reduce_value[2], state)
            if listitems is not None:
                self.assertListEqual(list(reduce_value[3]), listitems)
            else:
                self.assertIsNone(reduce_value[3])
            if dictitems is not None:
                self.assertDictEqual(dict(reduce_value[4]), dictitems)
            else:
                self.assertIsNone(reduce_value[4])
        else:
            base_type = type(obj).__base__
            reduce_value = (copyreg._reconstructor,
                            (type(obj),
                             base_type,
                             None if base_type is object else base_type(obj)))
            if state is not None:
                reduce_value += (state,)
            self.assertEqual(obj.__reduce_ex__(proto), reduce_value)
            self.assertEqual(obj.__reduce__(), reduce_value) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:31,代碼來源:test_descr.py

示例4: _check_reduce

# 需要導入模塊: import copyreg [as 別名]
# 或者: from copyreg import __newobj__ [as 別名]
def _check_reduce(self, proto, obj, args=(), kwargs={}, state=None,
                      listitems=None, dictitems=None):
        if proto >= 4:
            reduce_value = obj.__reduce_ex__(proto)
            self.assertEqual(reduce_value[:3],
                             (copyreg.__newobj_ex__,
                              (type(obj), args, kwargs),
                              state))
            if listitems is not None:
                self.assertListEqual(list(reduce_value[3]), listitems)
            else:
                self.assertIsNone(reduce_value[3])
            if dictitems is not None:
                self.assertDictEqual(dict(reduce_value[4]), dictitems)
            else:
                self.assertIsNone(reduce_value[4])
        elif proto >= 2:
            reduce_value = obj.__reduce_ex__(proto)
            self.assertEqual(reduce_value[:3],
                             (copyreg.__newobj__,
                              (type(obj),) + args,
                              state))
            if listitems is not None:
                self.assertListEqual(list(reduce_value[3]), listitems)
            else:
                self.assertIsNone(reduce_value[3])
            if dictitems is not None:
                self.assertDictEqual(dict(reduce_value[4]), dictitems)
            else:
                self.assertIsNone(reduce_value[4])
        else:
            base_type = type(obj).__base__
            reduce_value = (copyreg._reconstructor,
                            (type(obj),
                             base_type,
                             None if base_type is object else base_type(obj)))
            if state is not None:
                reduce_value += (state,)
            self.assertEqual(obj.__reduce_ex__(proto), reduce_value)
            self.assertEqual(obj.__reduce__(), reduce_value) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:42,代碼來源:test_descr.py

示例5: test__newobj__

# 需要導入模塊: import copyreg [as 別名]
# 或者: from copyreg import __newobj__ [as 別名]
def test__newobj__(self):
        
        #the second argument is omitted
        result = None
        result = copyreg.__newobj__(object)
        self.assertTrue(result != None,
            "The method __newobj__ did not return an object")
                        
        #the second argument is an int object
        result = None
        a = 1
        result = copyreg.__newobj__(int,a)
        self.assertTrue(result != None,
            "The method __newobj__ did not return an object")
            
        #the method accept multiple arguments
        reseult = None
        class customtype(object):
            def __new__(cls,b,c,d):
                return object.__new__(cls)
            def __init__(self):
                pass
        c = True
        d = "argu"
        e = 3
        result = copyreg.__newobj__(customtype,c,d,e)
        self.assertTrue(result != None,
            "The method __newobj__ did not return an object")


    #TODO: @skip("multiple_execute") 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:33,代碼來源:test_copyreg.py


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