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


Python pyamf.register_class函数代码示例

本文整理汇总了Python中pyamf.register_class函数的典型用法代码示例。如果您正苦于以下问题:Python register_class函数的具体用法?Python register_class怎么用?Python register_class使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了register_class函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_person

    def test_person(self):
        pyamf.register_class(models.Person, 'Person')

        person_key = ndb.Key('Contact', 'p')
        person = models.Person(
            key=person_key,
            first_name='Foo',
            last_name='Bar',
        )

        bytes = (
            b'\n\x0b\rPerson', (
                b'\t_key\x06Qagx0ZXN0YmVkLXRlc3RyDgsSB0NvbnRhY3QiAXAM',
                b'\x19phone_number\x01',
                b'\x0faddress\x01',
                b'\x15first_name\x06\x07Foo',
                b'\x13last_name\x06\x07Bar',
            ),
            b'\x01'
        )

        self.assertEncodes(person, bytes)

        def check_person(ret):
            self.assertIsInstance(ret, models.Person)
            self.assertEqual(ret, person)

        self.assertDecodes(bytes, check_person)
开发者ID:nervatura,项目名称:nerva2py,代码行数:28,代码来源:test_ndb.py

示例2: test_company

    def test_company(self):
        pyamf.register_class(models.Company, 'Company')

        company_key = ndb.Key('Contact', 'c')

        company = models.Company(
            key=company_key,
            name='Acme Ltd',
        )

        bytes = (
            b'\n\x0b\x0fCompany', (
                b'\t_key\x06Qagx0ZXN0YmVkLXRlc3RyDgsSB0NvbnRhY3QiAWMM',
                b'\x19phone_number\x01',
                b'\x0faddress\x01',
                b'\tname\x06\x11Acme Ltd',
            ),
            b'\x01'
        )

        self.assertEncodes(company, bytes)

        def check_company(ret):
            self.assertIsInstance(ret, models.Company)
            self.assertEqual(ret, company)

        self.assertDecodes(bytes, check_company)
开发者ID:nervatura,项目名称:nerva2py,代码行数:27,代码来源:test_ndb.py

示例3: test_but_missing

    def test_but_missing(self):
        """
        .model is set to a key but the entity does not exist - pyamf must
        handle the encode and decode cases.
        """
        pyamf.register_class(models.Pet, 'pet')
        pyamf.register_class(models.SuperModel, 'supermodel')

        pet_key = ndb.Key('Pet', 'foobar')
        model_key = ndb.Key('SuperModel', 'barfoo')

        self.assertIsNone(model_key.get())

        pet = models.Pet(key=pet_key, model=model_key)

        pet.put()

        bytes = (
            b'\n\x0b\x07pet', (
                b'\t_key\x06Uagx0ZXN0YmVkLXRlc3RyDwsSA1BldCIGZm9vYmFyDA',
                b'\x0bmodel\x06gagx0ZXN0YmVkLXRlc3RyFgsSClN1cGVyTW9kZWwiBmJhcm'
                b'Zvbww',
                b'\tname\x01',
            ),
            b'\x01'
        )

        self.assertEncodes(pet, bytes)
        self.assertDecodes(bytes, pet)
开发者ID:nervatura,项目名称:nerva2py,代码行数:29,代码来源:test_ndb.py

示例4: test_expando

    def test_expando(self):
        pyamf.register_class(models.SuperHero, 'SH')
        superman = models.SuperHero(name='Clark Kent', can_fly=True)

        superman.has_cape = True

        bytes = (
            b'\n\x0b\x05SH', (
                b'\x0fcan_fly\x03',
                b'\rslogan\x01',
                b'\tname\x06\x15Clark Kent',
                b'\x11has_cape\x03',
                b'\t_key\x01',
            ),
            b'\x01'
        )

        self.assertEncodes(superman, bytes)

        def check_superman(ret):
            self.assertIsInstance(ret, models.SuperHero)
            self.assertEqual(ret, superman)
            self.assertTrue(ret.has_cape)

        self.assertDecodes(bytes, check_superman)
开发者ID:nervatura,项目名称:nerva2py,代码行数:25,代码来源:test_ndb.py

示例5: test_external

    def test_external(self):
        class A(object):
            pass

        class B:
            pass

        self.assertRaises(AttributeError, pyamf.register_class, A, metadata=["external"])
        self.assertRaises(AttributeError, pyamf.register_class, B, metadata=["external"])

        A.__readamf__ = None
        B.__readamf__ = None

        self.assertRaises(AttributeError, pyamf.register_class, A, metadata=["external"])
        self.assertRaises(AttributeError, pyamf.register_class, B, metadata=["external"])

        A.__readamf__ = lambda x: None
        B.__readamf__ = lambda x: None

        self.assertRaises(AttributeError, pyamf.register_class, A, metadata=["external"])
        self.assertRaises(AttributeError, pyamf.register_class, B, metadata=["external"])

        A.__writeamf__ = "foo"
        B.__writeamf__ = "bar"

        self.assertRaises(TypeError, pyamf.register_class, A, metadata=["external"])
        self.assertRaises(TypeError, pyamf.register_class, B, metadata=["external"])

        A.__writeamf__ = lambda x: None
        B.__writeamf__ = lambda x: None

        pyamf.register_class(A, metadata=["external"])
        pyamf.register_class(B, metadata=["external"])
开发者ID:kruser,项目名称:zualoo,代码行数:33,代码来源:test_basic.py

示例6: test_simple

    def test_simple(self):
        class A(object):
            pass

        pyamf.register_class(A, 'A', attrs=['a'])

        class B(A):
            pass

        pyamf.register_class(B, 'B', attrs=['b'])

        x = B()
        x.a = 'spam'
        x.b = 'eggs'

        stream = util.BufferedByteStream()
        encoder = pyamf._get_encoder_class(pyamf.AMF0)(stream)

        encoder.writeElement(x)

        self.assertEquals(stream.getvalue(), '\x10\x00\x01B\x00\x01b\x02\x00'
            '\x04eggs\x00\x01a\x02\x00\x04spam\x00\x00\t')

        pyamf.unregister_class(A)
        pyamf.unregister_class(B)
开发者ID:wayne-abarquez,项目名称:vizzuality,代码行数:25,代码来源:test_amf0.py

示例7: test_setstate_classic

    def test_setstate_classic(self):
        self.executed = False

        class Foo:
            tc = self

            def __init__(self, *args, **kwargs):
                self.tc.fail("__init__ called")

            def __setstate__(self, state):
                self.tc.executed = True
                self.__dict__.update(state)

        pyamf.register_class(Foo, 'foo')

        self.buf.write('\x10\x00\x03\x66\x6f\x6f\x00\x04\x65\x67\x67\x73\x01\x01\x00\x04')
        self.buf.write('\x73\x70\x61\x6d\x02\x00\x05\x68\x65\x6c\x6c\x6f\x00\x00\x09')
        self.buf.seek(0)

        foo = self.decoder.readElement()

        self.assertTrue(self.executed)
        self.assertTrue(isinstance(foo, Foo))
        self.assertEquals(foo.spam, 'hello')
        self.assertEquals(foo.eggs, True)

        pyamf.unregister_class(Foo)
开发者ID:wayne-abarquez,项目名称:vizzuality,代码行数:27,代码来源:test_amf0.py

示例8: test_typed_object

    def test_typed_object(self):
        pyamf.register_class(Spam, alias="org.pyamf.spam")

        x = Spam()
        x.baz = "hello"

        self.assertEncoded(x, "\x10\x00\x0eorg.pyamf.spam\x00\x03baz" "\x02\x00\x05hello\x00\x00\t")
开发者ID:boggob,项目名称:bogs-xbmc-addons,代码行数:7,代码来源:test_amf0.py

示例9: test_simple

    def test_simple(self):
        class A(object):
            class __amf__:
                static = ('a')


        class B(A):
            class __amf__:
                static = ('b')

        pyamf.register_class(A, 'A')
        pyamf.register_class(B, 'B')

        x = B()
        x.a = 'spam'
        x.b = 'eggs'

        stream = util.BufferedByteStream()
        encoder = pyamf._get_encoder_class(pyamf.AMF0)(stream)

        encoder.writeElement(x)

        self.assertTrue(check_buffer(stream.getvalue(), ('\x10\x00\x01B', (
            '\x00\x01a\x02\x00\x04spam',
            '\x00\x01b\x02\x00\x04eggs'
        ), '\x00\x00\t')))
开发者ID:cardmagic,项目名称:PyAMF,代码行数:26,代码来源:test_amf0.py

示例10: GetEpisodeInfo

    def GetEpisodeInfo(self, key, url, playerId, contentRefId = None, contentId = None):
        self.log(u'ContentRefId:' + str(contentRefId) + u'contentId:' + str(contentId) + u', URL:' + url + u', playerId: ' + unicode(playerId) + u', key: ' + unicode(key) )  
        self.log(u"RemotingService", xbmc.LOGDEBUG)
        
        try:            
            if self.proxyConfig is not None: 
                self.proxyConfig.Enable()
            
            serviceName = 'com.brightcove.experience.ExperienceRuntimeFacade'
            service = self.GetRemotingService(key, serviceName)

            hashValue = self.GetAmfClassHash(serviceName)
            self.log(u'hashValue:' + str(hashValue))
         
            pyamf.register_class(ViewerExperienceRequest, 'com.brightcove.experience.ViewerExperienceRequest')
            pyamf.register_class(ContentOverride, 'com.brightcove.experience.ContentOverride')
            content_override = ContentOverride(contentRefId = contentRefId, contentId = contentId)
            viewer_exp_req = ViewerExperienceRequest(url, [content_override], int(playerId), key)
            
            self.log( content_override.tostring() )
            self.log( viewer_exp_req.tostring() )
    
            # Make the request
            response = service.getDataForExperience(hashValue, viewer_exp_req)
            
            self.log(u"response: " + utils.drepr(response), xbmc.LOGDEBUG)
        finally:
            if self.proxyConfig is not None: 
                self.proxyConfig.Disable()
    
        return response
开发者ID:Lusephur,项目名称:plugin-video-irishtv,代码行数:31,代码来源:brightcove.py

示例11: test_decode

    def test_decode(self):
        pyamf.register_class(ListModel, "list-model")

        decoder = pyamf.get_decoder(pyamf.AMF0)
        decoder.stream.write(
            "\x10\x00\nlist-model\x00\x07numbers\n\x00\x00"
            "\x00\x05\[email protected]\x00\x00\x00\x00\x00\x00\x00\[email protected]\x10\x00\x00\x00"
            "\x00\x00\x00\[email protected]\x18\x00\x00\x00\x00\x00\x00\[email protected] \x00\x00"
            "\x00\x00\x00\x00\[email protected]$\x00\x00\x00\x00\x00\x00\x00\x00\t"
        )
        decoder.stream.seek(0)

        x = decoder.readElement()

        self.assertTrue(isinstance(x, ListModel))
        self.assertTrue(hasattr(x, "numbers"))
        self.assertEquals(x.numbers, [2, 4, 6, 8, 10])

        decoder = pyamf.get_decoder(pyamf.AMF3)
        decoder.stream.write("\n\x0b\x15list-model\x0fnumbers\t\x0b\x01\x04\x02\x04" "\x04\x04\x06\x04\x08\x04\n\x01")
        decoder.stream.seek(0)

        x = decoder.readElement()

        self.assertTrue(isinstance(x, ListModel))
        self.assertTrue(hasattr(x, "numbers"))
        self.assertEquals(x.numbers, [2, 4, 6, 8, 10])
开发者ID:jrolfs,项目名称:google-calendar-amf,代码行数:27,代码来源:test_google.py

示例12: test_decode_amf3

    def test_decode_amf3(self):
        pyamf.register_class(models.ListModel, "list-model")

        bytes = "\n\x0b\x15list-model\x0fnumbers\t\x0b\x01\x04\x02\x04\x04\x04" "\x06\x04\x08\x04\n\x01"

        x = self.decode(bytes, encoding=pyamf.AMF3)
        self._check_list(x)
开发者ID:Poorvak,项目名称:twitter_clone,代码行数:7,代码来源:test_xdb.py

示例13: test_get_reference

    def test_get_reference(self):
        x = amf3.Context()
        y = [1, 2, 3]
        z = {'spam': 'eggs'}

        spam_alias = pyamf.register_class(Spam, 'spam.eggs')

        class Foo:
            pass

        foo_alias = pyamf.register_class(Foo, 'foo.bar')

        a = amf3.ClassDefinition(spam_alias)
        b = amf3.ClassDefinition(foo_alias)

        ref1 = x.addObject(y)
        ref2 = x.addObject(z)
        x.addString('abc')
        x.addString('def')
        x.addClass(a, Spam)
        x.addClass(b, Foo)

        self.assertEqual(x.getObjectReference(y), ref1)
        self.assertEqual(x.getObjectReference(z), ref2)
        self.assertEqual(x.getObjectReference({}), -1)

        self.assertEqual(x.getStringReference('abc'), 0)
        self.assertEqual(x.getStringReference('def'), 1)
        self.assertEqual(x.getStringReference('asdfas'), -1)

        self.assertEqual(x.getClass(Spam), a)
        self.assertEqual(x.getClass(Foo), b)
        self.assertEqual(x.getClass(object()), None)
开发者ID:MyaThandarKyaw,项目名称:pyamf,代码行数:33,代码来源:test_amf3.py

示例14: test_dynamic

    def test_dynamic(self):
        pyamf.register_class(Spam, attr_func=ord, metadata=['dynamic'])

        alias = pyamf.CLASS_CACHE['%s.%s' % (Spam.__module__, Spam.__name__,)]

        self.assertTrue('dynamic' in alias.metadata)
        self.assertEquals(alias.attr_func, ord)
开发者ID:AbsMate,项目名称:bluecop-xbmc-repo,代码行数:7,代码来源:test_basic.py

示例15: BuildAmfRequest

    def BuildAmfRequest(self, key, url, exp_id, contentRefId = None, contentId = None):
       self.log(u'ContentRefId:' + str(contentRefId) + u'contentId:' + str(contentId) + u', ExperienceId:' + str(exp_id) + u', URL:' + url)  

       method = u"com.brightcove.experience.ExperienceRuntimeFacade.getDataForExperience"
       className = method[0:method.rfind('.')]
       hashValue = self.GetAmfClassHash(className)

       self.log(u'hashValue:' + str(hashValue))
 
       pyamf.register_class(ViewerExperienceRequest, u'com.brightcove.experience.ViewerExperienceRequest')
       pyamf.register_class(ContentOverride, u'com.brightcove.experience.ContentOverride')
       content_override = ContentOverride(contentRefId = contentRefId, contentId = contentId)
       viewer_exp_req = ViewerExperienceRequest(url, [content_override], int(exp_id), key)
    
       self.log( content_override.tostring() )
       self.log( viewer_exp_req.tostring() )
    
       env = remoting.Envelope(amfVersion=3)
       env.bodies.append(
          (
             "/1",
             remoting.Request(
                target=method,
                body=[hashValue, viewer_exp_req],
                envelope=env
             )
          )
       )
       return env
开发者ID:Lusephur,项目名称:plugin-video-irishtv,代码行数:29,代码来源:brightcove.py


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