def test_strict(self): self.module.Spam = Spam Spam.__module__ = self.spam_module r = pyamf.register_package(self.module, 'com.example', strict=True) self.check_module(r, 'com.example.')
def test_all(self): self.module.Spam = Spam self.module.__all__ = ['Classic', 'New'] r = pyamf.register_package(self.module, 'com.example') self.check_module(r, 'com.example.')
def test_name(self): self.module.__name__ = 'spam.eggs' self.ClassicType.__module__ = 'spam.eggs' self.NewType.__module__ = 'spam.eggs' r = pyamf.register_package(self.module) self.check_module(r, 'spam.eggs.')
def test_all(self): self.module.Spam = Spam self.module.__all__ = ["Classic", "New"] r = pyamf.register_package(self.module, "com.example") self.check_module(r, "com.example.")
def getLogin_amf(database, username, password, validdata=False): validator = npi.getLogin(database, username, password) pyamf.register_package(nerva2py.models, 'models') if validator["valid"] == True: validator["engine"] = ns.engine validator["employee"] = ns.employee.as_dict(datetime_to_str=False) validator["audit"] = ArrayCollection( ns.db(ns.db.ui_audit.usergroup == ns.employee.usergroup).select(). as_list(datetime_to_str=False)) transfilter = ns.db( (ns.db.link.ref_id_1 == ns.employee.usergroup) & (ns.db.link.nervatype_2 == ns.db( (ns.db.groups.groupname == "nervatype") & (ns.db.groups.groupvalue == "groups")).select()[0].id) & (ns.db.link.ref_id_2.belongs( ns.db(ns.db.groups.groupname == "nervatype")._select( ns.db.groups.id)))).select() if len(transfilter) > 0: validator["transfilter"] = transfilter[0].ref_id_2 else: validator["transfilter"] = None validator["groups"] = ArrayCollection( ns.db( ns.db.groups.groupname.belongs( ('usergroup', 'nervatype', 'transtype', 'inputfilter', 'transfilter', 'department', 'logstate', 'fieldtype'))).select().as_list(datetime_to_str=False)) validator["menucmd"] = ArrayCollection(ns.db().select( ns.db.ui_menu.ALL).as_list(datetime_to_str=False)) validator["menufields"] = ArrayCollection(ns.db().select( ns.db.ui_menufields.ALL, orderby=ns.db.ui_menufields.menu_id | ns.db.ui_menufields.orderby).as_list(datetime_to_str=False)) userlogin = ns.db( ns.db.fieldvalue.fieldname == "log_userlogin").select() if len(userlogin) > 0: validator["userlogin"] = userlogin[0].value else: validator["userlogin"] = "******" return validator
def getLogin_amf(database, username, password, validdata=False): validator = npi.getLogin(database, username, password) pyamf.register_package(nerva2py.models, 'models') if validator["valid"]==True: validator["engine"] = ns.engine validator["employee"] = ns.employee.as_dict(datetime_to_str=False) validator["audit"] = ArrayCollection(ns.db(ns.db.ui_audit.usergroup==ns.employee.usergroup).select().as_list(datetime_to_str=False)) transfilter = ns.db((ns.db.link.ref_id_1==ns.employee.usergroup) &(ns.db.link.nervatype_2==ns.db((ns.db.groups.groupname=="nervatype")&(ns.db.groups.groupvalue=="groups")).select()[0].id) &(ns.db.link.ref_id_2.belongs(ns.db(ns.db.groups.groupname=="nervatype")._select(ns.db.groups.id)))).select() if len(transfilter)>0: validator["transfilter"] = transfilter[0].ref_id_2 else: validator["transfilter"] = None validator["groups"] = ArrayCollection(ns.db(ns.db.groups.groupname.belongs(('usergroup', 'nervatype', 'transtype', 'inputfilter', 'transfilter', 'department', 'logstate', 'fieldtype'))).select().as_list(datetime_to_str=False)) validator["menucmd"] = ArrayCollection(ns.db().select(ns.db.ui_menu.ALL).as_list(datetime_to_str=False)) validator["menufields"] = ArrayCollection(ns.db().select(ns.db.ui_menufields.ALL, orderby=ns.db.ui_menufields.menu_id|ns.db.ui_menufields.orderby).as_list(datetime_to_str=False)) userlogin = ns.db(ns.db.fieldvalue.fieldname=="log_userlogin").select() if len(userlogin)>0: validator["userlogin"] = userlogin[0].value else: validator["userlogin"] = "******" return validator
def test_not_strict(self): self.module.Spam = Spam Spam.__module__ = self.spam_module r = pyamf.register_package(self.module, 'com.example', strict=False) self.assertEqual(len(r), 3) for c in [self.NewType, self.ClassicType, Spam]: alias = r[c] self.assertTrue(isinstance(alias, pyamf.ClassAlias)) self.assertEqual(alias.klass, c) self.assertEqual(alias.alias, 'com.example.' + c.__name__)
def test_dict(self): """ @see: #585 """ d = dict() d['Spam'] = Spam r = pyamf.register_package(d, 'com.example', strict=False) self.assertEqual(len(r), 1) alias = r[Spam] self.assertTrue(isinstance(alias, pyamf.ClassAlias)) self.assertEqual(alias.klass, Spam) self.assertEqual(alias.alias, 'com.example.Spam')
def test_list(self): class Foo: pass class Bar: pass ret = pyamf.register_package([Foo, Bar], 'spam.eggs') self.assertEqual(len(ret), 2) for c in [Foo, Bar]: alias = ret[c] self.assertTrue(isinstance(alias, pyamf.ClassAlias)) self.assertEqual(alias.klass, c) self.assertEqual(alias.alias, 'spam.eggs.' + c.__name__)
port = 8000 host = 'localhost' # Setup database schema = persistent.Schema() schema.createSchema() schema.createMappers() # Set this to True so that returned objects and arrays are bindable amf3.use_proxies_default = True # Map class aliases # These same aliases must be registered in the Flash Player client # with the registerClassAlias function. namespace = 'org.pyamf.examples.addressbook.models' pyamf.register_package(models, namespace) # Map controller methods sa_obj = controller.SAObject() mapped_services = {'ExampleService': sa_obj} if __name__ == '__main__': import optparse import logging import os, sys from wsgiref import simple_server from pyamf.remoting.gateway.wsgi import WSGIGateway usage = """usage: %s [options]""" % os.path.basename(sys.argv[0]) parser = optparse.OptionParser(usage=usage)
def test_separator(self): r = pyamf.register_package(self.module, 'com.example', separator='/') self.ClassicType.__module__ = 'com.example' self.NewType.__module__ = 'com.example' self.check_module(r, 'com.example/')
def test_ignore(self): self.module.Spam = Spam r = pyamf.register_package(self.module, 'com.example', ignore=['Spam']) self.check_module(r, 'com.example.')
@type obj: L{ExternalizableClass} @param obj: The object in question. @param input: The output stream to write to. @type input L{DataOutput<pyamf.amf3.DataOutput>} """ output.writeBoolean(True) output.writeBoolean(False) output.writeByte(0) output.writeByte(-1) output.writeByte(1) output.writeByte(127) output.writeByte(-127) output.writeDouble(1.0) output.writeFloat(2.0) output.writeInt(0) output.writeInt(-1) output.writeInt(1) output.writeMultiByte(u"\xe4\xf6\xfc\xc4\xd6\xdc\xdf", "iso-8859-1") output.writeMultiByte(u"\xe4\xf6\xfc\xc4\xd6\xdc\xdf", "utf8") output.writeObject([1, "one", 1]) output.writeShort(0) output.writeShort(-1) output.writeShort(1) output.writeUnsignedInt(0) output.writeUnsignedInt(1) output.writeUTF("Hello world!") output.writeUTFBytes("Hello world!") register_package(sys.modules[__name__], NAMESPACE)
self.pageCount = None #: Provides access to the index of the current page in a sequence. self.pageIndex = None class DataErrorMessage(ErrorMessage): """ Special cases of ErrorMessage will be sent when a data conflict occurs. This message provides the conflict information in addition to the L{ErrorMessage<pyamf.flex.messaging.ErrorMessage>} information. @see: U{DataErrorMessage on Livedocs<http:// livedocs.adobe.com/flex/201/langref/mx/data/messages/DataErrorMessage.html>} """ def __init__(self): ErrorMessage.__init__(self) #: The client oringinated message which caused the conflict. self.cause = None #: An array of properties that were found to be conflicting #: between the client and server objects. self.propertyNames = None #: The value that the server had for the object with the #: conflicting properties. self.serverObject = None pyamf.register_package(globals(), NAMESPACE)
self.pageCount = None #: Provides access to the index of the current page in a sequence. self.pageIndex = None class DataErrorMessage(ErrorMessage): """ Special cases of ErrorMessage will be sent when a data conflict occurs. This message provides the conflict information in addition to the L{ErrorMessage<pyamf.flex.messaging.ErrorMessage>} information. @see: U{DataErrorMessage on Livedocs<http:// help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/data/ messages/DataErrorMessage.html>} """ def __init__(self): ErrorMessage.__init__(self) #: The client oringinated message which caused the conflict. self.cause = None #: An array of properties that were found to be conflicting #: between the client and server objects. self.propertyNames = None #: The value that the server had for the object with the #: conflicting properties. self.serverObject = None pyamf.register_package(globals(), NAMESPACE)
def test_module(self): r = pyamf.register_package(self.module, "com.example") self.check_module(r, "com.example.")
def test_separator(self): r = pyamf.register_package(self.module, "com.example", separator="/") self.ClassicType.__module__ = "com.example" self.NewType.__module__ = "com.example" self.check_module(r, "com.example/")
if isinstance(obj, ArrayCollection): return list(obj) elif isinstance(obj, ObjectProxy): return obj._amf_object return obj def proxy_object(obj): """ Returns a proxied representation of C{obj} Conversion ========== - C{list}: L{ArrayCollection} - C{dict}: L{ObjectProxy} - Everything else: C{obj} @since: 0.6 """ if type(obj) in (list, tuple): return ArrayCollection(obj) if isinstance(obj, dict): return ObjectProxy(obj) return obj pyamf.register_package(globals(), package='flex.messaging.io')
def test_module(self): r = pyamf.register_package(self.module, 'com.example') self.check_module(r, 'com.example.')
class DataErrorMessage(messages.ErrorMessage): """ Special cases of ErrorMessage will be sent when a data conflict occurs. This message provides the conflict information in addition to the :class:`~plasma.flex.messaging.ErrorMessage` information. :ivar cause: The client originated message which caused the conflict. :ivar propertyNames: A list of properties that were found to be conflicting between the client and server objects. :ivar serverObject: The value that the server had for the object with the conflicting properties. .. seealso:: `DataErrorMessage on Livedocs http://livedocs.adobe.com/flex/201/langref/mx/data/messages/DataErrorMessage.html>`_ """ def __init__(self, **kwargs): ErrorMessage.__init__(self, **kwargs) self.cause = kwargs.pop('cause', None) self.propertyNames = kwargs.pop('propertyNames', None) self.serverObject = kwargs.pop('serverObject', None) pyamf.register_package(globals(), package='flex.data.messages')
def test_ignore(self): self.module.Spam = Spam r = pyamf.register_package(self.module, "com.example", ignore=["Spam"]) self.check_module(r, "com.example.")
class ImageSnapshot(object): """ This class corresponds to `mx.graphics.ImageSnapshot` on the client. Clients may choose to capture images and send them to the server via a RemoteObject call. :ivar contentType: The content type for the image encoding format that was used to capture this snapshot. :type contentType: `str` :ivar width: The image width in pixels. :type width: `int` :ivar height: The image height in pixels. :type height: `int` :ivar properties: Additional properties of the image. :type properties: `dict` :ivar data: The encoded data representing the image snapshot. :type data: `file` object """ def __init__(self, **kwargs): self.contentType = kwargs.pop('contentType', None) self.properties = kwargs.pop('properties', {}) self.width = kwargs.pop('width', 0) self.height = kwargs.pop('height', 0) self.data = kwargs.pop('data', None) pyamf.register_package(globals(), 'flex.graphics')
port = 8000 host = 'localhost' # Setup database schema = persistent.Schema() schema.createSchema() schema.createMappers() # Set this to True so that returned objects and arrays are bindable amf3.use_proxies_default = True # Map class aliases # These same aliases must be registered in the Flash Player client # with the registerClassAlias function. namespace = 'org.pyamf.examples.addressbook.models' pyamf.register_package(models, namespace) # Map controller methods sa_obj = controller.SAObject() mapped_services = { 'ExampleService': sa_obj } if __name__ == '__main__': import optparse import logging import os, sys from wsgiref import simple_server from pyamf.remoting.gateway.wsgi import WSGIGateway
def unproxy_object(obj): """ Returns the unproxied version of the object. """ if isinstance(obj, ArrayCollection): return list(obj) elif isinstance(obj, ObjectProxy): return obj._amf_object return obj def proxy_object(obj): """ Returns a proxied representation of C{obj} Conversion ========== - C{list}: L{ArrayCollection} - C{mixed}: L{ObjectProxy} @since: 0.6 """ if type(obj) in (list, tuple): return ArrayCollection(obj) return ObjectProxy(obj) pyamf.register_package(globals(), package='flex.messaging.io')
self.pageIndex = None class DataErrorMessage(ErrorMessage): """ Special cases of ErrorMessage will be sent when a data conflict occurs. This message provides the conflict information in addition to the L{ErrorMessage<pyamf.flex.messaging.ErrorMessage>} information. @see: U{DataErrorMessage on Livedocs (external) <http://livedocs.adobe.com/flex/201/langref/mx/data/messages/DataErrorMessage.html>} """ def __init__(self): ErrorMessage.__init__(self) #: The client oringinated message which caused the conflict. self.cause = None #: An array of properties that were found to be conflicting #: between the client and server objects. self.propertyNames = None #: The value that the server had for the object with the #: conflicting properties. self.serverObject = None #: Namespace for C{flex.data} messages. MESSAGES_NS = 'flex.data.messages' pyamf.register_package(globals(), MESSAGES_NS)
session = self.session( self, protocol ) self.sessions[ session.session_id ] = session session.open() return session def closeSession( self, session ): """ A session is closing, clean up after it """ if ( session.session_id in self.sessions ): del( self.sessions[ session.session_id ] ) if ( session.protocol.transport is not None ): # Could be none in the case of tests session.protocol.transport.loseConnection() pass def fireEvent( self, event, session ): """ Fire the event """ try: #print event return event.fire( self, session ) except Exception as e: traceback.print_exc(file=sys.stdout) # Send back an error message to the client reply = event.reply( ErrorEvent, e ) session.sendEvent( reply ) def sendGlobalEvent( self, event ): """ Send an event to all active sessions """ pass pyamf.register_package( swfconduit.event, 'swfconduit.event' );