• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python pyamf.register_class函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_dynamic

    def test_dynamic(self):
        pyamf.register_class(Spam, 'abc.xyz')

        x = Spam({'spam': 'eggs'})
        self.encoder.writeElement(x)

        self.assertEqual(self.buf.getvalue(), '\n\x0b\x0fabc.xyz\tspam\x06\teggs\x01')
开发者ID:MyaThandarKyaw,项目名称:pyamf,代码行数:7,代码来源:test_amf3.py


示例17: save

    def save(self, out, format):
        """
        """
        #
        # Serialize
        #
        if format == "WKT":
            if "wkt" in self.content["crs"]:
                out.write(self.content["crs"]["wkt"])
            else:
                out.write(_sref_4326().ExportToWkt())

            return

        if format in ("GeoJSON", "GeoBSON", "GeoAMF"):
            content = self.content

            if "wkt" in content["crs"]:
                content["crs"] = {"type": "link", "properties": {"href": "0.wkt", "type": "ogcwkt"}}
            else:
                del content["crs"]

        elif format in ("ArcJSON", "ArcBSON", "ArcAMF"):
            content = reserialize_to_arc(self.content, format == "ArcAMF")

        else:
            raise KnownUnknown(
                'Vector response only saves .geojson, .arcjson, .geobson, .arcbson, .geoamf, .arcamf and .wkt tiles, not "%s"'
                % format
            )

        #
        # Encode
        #
        if format in ("GeoJSON", "ArcJSON"):
            indent = self.verbose and 2 or None

            encoded = JSONEncoder(indent=indent).iterencode(content)
            float_pat = compile(r"^-?\d+\.\d+$")

            for atom in encoded:
                if float_pat.match(atom):
                    out.write("%.6f" % float(atom))
                else:
                    out.write(atom)

        elif format in ("GeoBSON", "ArcBSON"):
            import bson

            encoded = bson.dumps(content)
            out.write(encoded)

        elif format in ("GeoAMF", "ArcAMF"):
            import pyamf

            for class_name in pyamf_classes.items():
                pyamf.register_class(*class_name)

            encoded = pyamf.encode(content, 0).read()
            out.write(encoded)
开发者ID:netconstructor,项目名称:TileStache,代码行数:60,代码来源:__init__.py


示例18: tearDown

    def tearDown(self):
        import pyamf

        pyamf.unregister_class(status.Status)

        if self._old_alias:
            pyamf.register_class(self._old_alias)
开发者ID:Arlex,项目名称:rtmpy,代码行数:7,代码来源:test_status.py


示例19: __BuildBrightCoveAmfRequest

	def __BuildBrightCoveAmfRequest(self, playerKey, contentId, url, experienceId, seed, contentRefId):
		""" Builds a AMF request compatible with BrightCove

		Arguments:
		playerKey : string - Key identifying the current request
		contentId : int    - ID of the content to retrieve
		url       : string - Url of the page that calls the video SWF
		seed      : string - Constant which depends on the website

		Keyword Arguments:
		experienceId : id     - <unknown parameter>

		Returns a valid Brightcove request

		"""

		if self.logger:
			self.logger.Debug("Creating BrightCover request for ContentId=%s, Key=%s, ExperienceId=%s, url=%s", contentId, playerKey, experienceId, url)
		else:
			print "Creating BrightCover request for ContentId=%s, Key=%s, ExperienceId=%s, url=%s" % (contentId, playerKey, experienceId, url)

		# const = '686a10e2a34ec3ea6af8f2f1c41788804e0480cb'
		pyamf.register_class(ViewerExperienceRequest, 'com.brightcove.experience.ViewerExperienceRequest')
		pyamf.register_class(ContentOverride, 'com.brightcove.experience.ContentOverride')

		contentOverrides = [ContentOverride(int(contentId), contentRefId=contentRefId)]
		viewerExperienceRequest = ViewerExperienceRequest(url, contentOverrides, int(experienceId), playerKey)

		envelope = remoting.Envelope(amfVersion=self.amfVersion)
		remotingRequest = remoting.Request(target="com.brightcove.experience.ExperienceRuntimeFacade.getDataForExperience", body=[seed, viewerExperienceRequest], envelope=envelope)
		envelope.bodies.append(("/1", remotingRequest))

		return envelope
开发者ID:boggob,项目名称:bogs-xbmc-addons,代码行数:33,代码来源:brightcovehelper.py


示例20: test_deep

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

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

        class B(A):
            pass

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

        class C(B):
            pass

        alias = pyamf.register_class(C, 'C')
        alias.static_attrs = ['c']

        x = C()
        x.a = 'spam'
        x.b = 'eggs'
        x.c = 'foo'

        self.assertEncoded(x,
            '\n;\x03C\x03b\x03a\x03c\x06\teggs\x06\tspam\x06\x07foo\x01')
开发者ID:MyaThandarKyaw,项目名称:pyamf,代码行数:26,代码来源:test_amf3.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyamf.register_class_loader函数代码示例发布时间:2022-05-25
下一篇:
Python pyamf.register_alias_type函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap