### Advanced installation options Source: https://github.com/stdcarrot/py3amf/blob/master/doc/install.rst Commands for viewing help or installing to a custom directory. ```bash easy_install --help ``` ```bash easy_install --prefix=/path/to/installdir ``` -------------------------------- ### Install Py3AMF from source Source: https://github.com/stdcarrot/py3amf/blob/master/README.md Clone the repository and install using setup.py for development purposes. ```bash git clone git@github.com:StdCarrot/Py3AMF.git cd Py3AMF # python3 setup.py test python3 setup.py install ``` -------------------------------- ### Clone the Swing example repository Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/jython/swing.rst Use git to download the example source code from the repository. ```bash git clone git://github.com/hydralabs/pyamf.git cd pyamf/doc/tutorials/examples/jython/swing ``` -------------------------------- ### Install PyAMF from source Source: https://github.com/stdcarrot/py3amf/blob/master/doc/install.rst Commands to unpack the source archive and perform a standard installation. ```bash tar zxfv PyAMF-.tar.gz cd PyAMF- ``` ```bash python setup.py install ``` ```bash python setup.py install --disable-ext ``` -------------------------------- ### Start the Gateway Server Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/recordset.rst Launch the development server to handle remoting requests. ```bash python gateway.py ``` -------------------------------- ### Create and install Pyramid project Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/pylons.rst Commands to scaffold a new Pyramid project and install it in development mode. ```bash $ bin/paster create -t pyramid_starter pyamf_tutorial ``` ```bash $ cd pyamf_tutorial $ ../bin/python setup.py develop ``` -------------------------------- ### Launch the development server Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/geoip.rst Starts the remoting gateway on port 8000. ```bash python server.py ``` -------------------------------- ### Start the development server Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/shell.rst Launch the Django development server to host the remoting gateway. ```bash python manage.py runserver ``` -------------------------------- ### Client output example Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/jython/swing.rst Expected output when running the client. ```python Hello World! ``` -------------------------------- ### Twisted Server Log Output Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/socket.rst Example log output when the Twisted socket server starts successfully. ```bash 2008-01-07 06:03:09+0100 [-] Log opened. 2008-01-07 06:03:09+0100 [-] twistd 2.5.0 (../Python 2.5.1) starting up 2008-01-07 06:03:09+0100 [-] reactor class: 2008-01-07 06:03:09+0100 [-] server.TimerFactory starting on 8000 2008-01-07 06:03:09+0100 [-] Starting factory ``` -------------------------------- ### Expose Single Method with Stackless Python and Twisted Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/stackless.rst This example shows how to expose a single method using Stackless Python and Twisted. Ensure Stackless Python is installed and configured. ```python from twisted.internet.defer import inlineCallbacks from twisted.internet.task import LoopingCall from twisted.python import log from py3amf.gateway import Gateway from py3amf.remoting import Request, Response class TwistedGateway(Gateway): """A Twisted-compatible AMF Gateway. This gateway is designed to be used with Twisted's :class:`~twisted.web.resource.Resource`. """ def __init__(self, *args, **kwargs): Gateway.__init__(self, *args, **kwargs) self.request_queue = [] self.response_queue = [] self.looping_call = LoopingCall(self.process_queue) def process_queue(self): """Process the request queue. """ if self.request_queue: request = self.request_queue.pop(0) response = self.handle(request) self.response_queue.append(response) @inlineCallbacks def handle_request(self, request): """Handle an incoming AMF request. """ log.msg('Handling request: %s' % request) self.request_queue.append(request) while request not in self.response_queue: yield None response = self.response_queue.pop(self.response_queue.index(request)) log.msg('Returning response: %s' % response) return response def makeGatewayService(config={}): """Create a Twisted Gateway service. """ gateway = TwistedGateway(config=config) gateway.looping_call.start(0.1) return gateway ``` -------------------------------- ### Start Twisted Socket Server Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/socket.rst Starts the Twisted socket server for Adobe Flash Player and Python AMF clients. Ensure Twisted is installed. ```bash twistd -noy timer.tac ``` -------------------------------- ### Python Client Output Example Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/socket.rst Example output from the Python client connecting to the socket server and sending messages. ```bash Connecting to socket server on localhost:8000 Connected to server. send request: start 2009-07-02 23:06:31.684023 2009-07-02 23:06:32.684465 2009-07-02 23:06:33.684923 2009-07-02 23:06:34.685351 2009-07-02 23:06:35.685828 2009-07-02 23:06:36.686253 send request: stop ``` -------------------------------- ### Start Tomcat server Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/jython/modjy.rst Execute the startup script to launch the Apache Tomcat server. ```bash bin/startup.sh ``` -------------------------------- ### Python AMF Client Example Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/appengine.rst Python script to test the PyAMF gateway on Google App Engine. Requires PyAMF to be installed. ```python from pyamf.remoting import gateway from pyamf.flex.messaging import # This is a sample client, not a full example. # See the PyAMF documentation for more details. print "Hello, world!" ``` -------------------------------- ### Guestbook Gateway Server Output Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/guestbook.rst This is an example of the expected output when the Twisted guestbook gateway server starts successfully. It indicates the log opening and the server listening on port 8080. ```bash 2008-04-12 15:12:14+0200 [-] Log opened. 2008-04-12 15:12:14+0200 [-] twistd 8.0.1+r23300 (/usr/local/bin/python2.5 2.5.2) starting up 2008-04-12 15:12:14+0200 [-] reactor class: 2008-04-12 15:12:14+0200 [-] twisted.web.server.Site starting on 8080 2008-04-12 15:12:14+0200 [-] Starting factory ``` -------------------------------- ### Python AMF Client Output Example Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/addressbook.rst Example output from the Python AMF client after adding and loading users. ```text Added user: Bill Lumbergh Load users: 1. Bill (2009-12-26 19:45:22.522754) ``` -------------------------------- ### Start GAE Development Server Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/appengine.rst Command to launch the Google App Engine development server for testing. Use --debug for detailed output. ```bash /usr/local/google_appengine/dev_appserver.py --debug --address=localhost --port=8080 . ``` -------------------------------- ### Install PyAMF via pip Source: https://github.com/stdcarrot/py3amf/blob/master/doc/install.rst Standard command to install the PyAMF package. ```bash pip install pyamf ``` -------------------------------- ### Install PyAMF Development Version Source: https://github.com/stdcarrot/py3amf/blob/master/doc/community/download.rst After cloning the repository, navigate to the directory and use this command to install the development version of PyAMF in 'develop' mode. ```bash cd pyamf python setup.py develop ``` -------------------------------- ### Custom Adapter Implementation Source: https://github.com/stdcarrot/py3amf/blob/master/doc/architecture/adapters.rst Example files for creating a custom adapter, consisting of the target module and the corresponding glue code. ```python class MyObject(object): def __init__(self, name): self.name = name ``` ```python import pyamf import mymodule def my_adapter(mod): print "Adapter loaded for %s" % mod.__name__ pyamf.register_adapter(mymodule, my_adapter) ``` -------------------------------- ### Clone PyAMF Repository Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/udp.rst Clone the PyAMF repository to access the example applications. Navigate to the UDP example directory within the cloned repository. ```bash git clone git://github.com/hydralabs/pyamf.git pyamf cd doc/tutorials/examples/actionscript/udp-example ``` -------------------------------- ### Install PyAMF on Debian Source: https://github.com/stdcarrot/py3amf/blob/master/doc/install.rst Use the system package manager to install PyAMF on Debian-based systems. ```bash apt-get install python-pyamf ``` -------------------------------- ### Clone the PyAMF repository Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/bytearray.rst Commands to download the example source code from the repository. ```bash git clone git://github.com/hydralabs/pyamf.git pyamf cd doc/tutorials/examples/actionscript/bytearray/python ``` -------------------------------- ### Run Pyramid server Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/pylons.rst Commands to start the development server and verify the running process. ```bash $ ../bin/paster serve development.ini ``` ```bash Starting server in PID 16601. serving on 0.0.0.0:6543 view at http://127.0.0.1:6543 ``` -------------------------------- ### Install Py3AMF via pip Source: https://github.com/stdcarrot/py3amf/blob/master/README.md Use pip3 to install the Py3AMF package in your environment. ```bash pip3 install Py3AMF ``` -------------------------------- ### Run the Django development server Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/bytearray.rst Commands to start the development server for the remoting gateway. ```bash python manage.py runserver ``` ```bash python manage.py runserver 192.168.1.100:8080 ``` -------------------------------- ### Create PyAMF application Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/jython/modjy.rst Example content for the demo_app.py file to define the WSGI application. ```python import pyamf from pyamf.remoting.gateway.wsgi import WSGIGateway def echo(data): return data services = { 'echo': echo } application = WSGIGateway(services) ``` -------------------------------- ### Clone PyAMF Repository Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/addressbook.rst Clone the PyAMF repository to access the example code. Navigate to the python directory within the addressbook example. ```bash git clone git://github.com/hydralabs/pyamf.git pyamf cd doc/tutorials/examples/actionscript/addressbook-example/python ``` -------------------------------- ### Install jython.jar for modjy Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/jython/modjy.rst Place the jython.jar file into the WEB-INF/lib directory of the web application. ```bash cp -R /path/to/jython2.5.0/jython.jar webapps/pyamf/WEB-INF/lib ``` -------------------------------- ### Run the Python AMF client Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/jython/swing.rst Start the client application from the jython folder. ```bash jython client.py ``` -------------------------------- ### Implement PyAMF Gateway Source: https://github.com/stdcarrot/py3amf/blob/master/doc/architecture/attributecontrol.rst Example of a service gateway using the User model. ```python from pyamf.remoting.gateway.wsgi import WSGIGateway class UserService(object): def getUsers(self): return User.all().fetch(10) def saveUser(self, user): user.put() services = {'user.getUsers': UserService().getUsers, 'user.saveUser': UserService().saveUser} gateway = WSGIGateway(services) ``` -------------------------------- ### Initialize Pyramid environment Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/pylons.rst Commands to create a virtual environment and install necessary dependencies for AMF support. ```bash $ virtualenv --no-site-packages pyramid_amf_env ``` ```bash $ cd pyramid_amf_env $ bin/easy_install pyramid pyramid_rpc pyamf ``` -------------------------------- ### PyAMF Server Help Options Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/ohloh.rst Display available options for the PyAMF example server when running `python server.py --help`. This shows configurable parameters like port, host, and API key. ```bash Usage: server.py [options] Options: -h, --help show this help message and exit -p PORT, --port=PORT port number [default: 8000] --host=HOST host address [default: localhost] --api-key=API_KEY Ohloh API key [default: 123456789] ``` -------------------------------- ### Install Adobe Flash Player Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/examples/actionscript/bytearray/flex/deploy/index.html Users need Adobe Flash Player to view the ByteArray demonstration SWF. Click the image to download and install the latest version. ```html Get Adobe Flash player ``` -------------------------------- ### Twisted AMF Client Example Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/twisted.rst This Python client example demonstrates how to test the Twisted AMF gateway. It sends AMF requests to a running Twisted server and processes the responses. ```python import pyamf from pyamf import remoting from pyamf.client import TwistedTransport # Define the target URL for the AMF service url = 'http://localhost:8000/myamf' # Create a PyAMF client client = remoting.Client(url, transport=TwistedTransport()) # Call a remote method (e.g., 'add' from MyService) # The result is a Deferred, which will be called back when the response is received d = client.callAsync('add', 5, 3) def on_success(result): print("Result of add(5, 3): %s" % result) # Call another method d2 = client.callAsync('subtract', 10, 4) d2.addCallbacks(on_success_subtract, on_error) def on_success_subtract(result): print("Result of subtract(10, 4): %s" % result) # Close the client connection client.close() def on_error(failure): print("An error occurred: %s" % failure) client.close() # Add callbacks to the Deferred d.addCallbacks(on_success, on_error) # Start the Twisted reactor to process the network request from twisted.internet import reactor reactor.run() ``` -------------------------------- ### Start Guestbook Gateway Server Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/guestbook.rst Launch the Twisted development server for the guestbook application using this command. Ensure the guestbook.tac file is in the current directory. ```bash twistd -noy guestbook.tac ``` -------------------------------- ### Install PyAMF source Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/jython/modjy.rst Copy the PyAMF source folder into the lib-python directory of the web application. ```bash cp -R /path/to/pyamf-0.5.1/pyamf webapps/pyamf/WEB-INF/lib-python ``` -------------------------------- ### GAE Development Server Info Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/appengine.rst Example output indicating the GAE development server is running and accessible. ```text INFO 2010-03-10 00:06:22,840 dev_appserver_main.py:399] Running application new-project-template on port 8080: http://localhost:8080 ``` -------------------------------- ### Run Pylons server Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/pylons.rst Commands to start the Pylons development server with auto-reload. ```bash $ paster serve --reload development.ini ``` ```bash Starting subprocess with file monitor Starting server in PID 4247. serving on 0.0.0.0:5000 view at http://127.0.0.1:5000 ``` -------------------------------- ### Clone PyAMF Repository Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/ohloh.rst Clone the PyAMF repository to access the Ohloh API examples. Navigate to the specific example directory after cloning. ```bash git clone git://github.com/hydralabs/pyamf.git pyamf cd doc/tutorials/examples/actionscript/ohloh ``` -------------------------------- ### Django server output Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/bytearray.rst Expected output when starting the Django development server. ```bash Validating models... 0 errors found Django version 1.1.1, using settings 'python.settings' Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C. ``` -------------------------------- ### Preferred Twisted Service with twistd Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/twisted.rst This example shows the preferred method for setting up a Twisted service designed to be run with 'twistd'. It simplifies boilerplate code and integrates with Twisted's management tools. ```python from pyamf.remoting import gateway # Define a simple service class class MyService: def add(self, x, y): return x + y def subtract(self, x, y): return x - y # Create a PyAMF gateway instance # The gateway will expose functions from MyService service_gateway = gateway.TwistedGateway(MyService()) # This function is called by twistd to get the application def makeService(): from twisted.web.server import Site from twisted.web.resource import Resource # Create a Twisted Resource that will handle AMF requests class AMFResource(Resource): isLeaf = True def render_POST(self, request): # The gateway handles the request and returns the AMF response return service_gateway.handle(request) # Create a Twisted Web Site root = Resource() root.putChild(b'myamf', AMFResource()) return Site(root) ``` -------------------------------- ### Python AMF Gateway Server Log Example Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/addressbook.rst Example log output from the Python AMF gateway server during client interaction, showing request and response details. ```text 2009-12-26 20:45:22,470 DEBUG [root] remoting.decode start 2009-12-26 20:45:22,471 DEBUG [root] Remoting target: u'ExampleService.insertDefaultData' 2009-12-26 20:45:22,471 DEBUG [root] remoting.decode end 2009-12-26 20:45:22,472 DEBUG [root] AMF Request: (u'/1', []) 2009-12-26 20:45:22,536 DEBUG [root] AMF Response: (u'/1', u'Added user: Bill Lumbergh') localhost - - [26/Dec/2009 20:45:22] "POST / HTTP/1.1" 200 57 2009-12-26 20:45:22,541 DEBUG [root] remoting.decode start 2009-12-26 20:45:22,541 DEBUG [root] Remoting target: u'ExampleService.loadAll' 2009-12-26 20:45:22,541 DEBUG [root] remoting.decode end 2009-12-26 20:45:22,541 DEBUG [root] AMF Request: (u'/2', [u'org.pyamf.examples.addressbook.models.User']) 2009-12-26 20:45:22,545 DEBUG [root] AMF Response: (u'/2', []) localhost - - [26/Dec/2009 20:45:22] "POST / HTTP/1.1" 200 865 ``` -------------------------------- ### Clone the PyAMF repository Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/geoip.rst Commands to download the source code and navigate to the GeoIP example directory. ```bash git clone git://github.com/hydralabs/pyamf.git pyamf cd doc/tutorials/examples/actionscript/geoip/python ``` -------------------------------- ### Client Script Output Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/jython/ant.rst Example output from running the 'client.py' script, showing connection to the AMF gateway and a successful 'Hello world!' message. ```bash 2009-07-20 00:00:32,669 INFO [root] Connecting to http://localhost:8000 2009-07-20 00:00:32,783 INFO [root] Hello world! ``` -------------------------------- ### Run the Swing application Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/jython/swing.rst Execute the gui.py script using Jython to start the AMF client and server. ```bash jython gui.py ``` -------------------------------- ### Verify modjy installation Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/jython/modjy.rst Output displayed when browsing to the application URL to confirm successful startup. ```text Modjy servlet running correctly: jython 2.5.0 (Release_2_5_0:6476, Jun 16 2009, 13:33:26) [Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_13 ``` -------------------------------- ### Check Ant Version Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/jython/ant.rst Verify that Apache Ant is installed and accessible from your command line. ```bash ant -version ``` -------------------------------- ### Clone PyAMF Repository Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/guestbook.rst Use this bash command to clone the PyAMF repository and navigate to the guestbook example directory. ```bash git clone git://github.com/hydralabs/pyamf.git pyamf cd doc/tutorials/examples/actionscript/guestbook ``` -------------------------------- ### Configure web.xml for modjy Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/jython/modjy.rst Update the web.xml file to configure the modjy servlet. Ensure python.home is set to the local Jython installation path. ```xml modjy com.xhaus.modjy.ModjyJServlet python.home /usr/local/jython2.5.0 wsgi.application demo_app.application 1 modjy /* ``` -------------------------------- ### Python AMF client session output Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/shell.rst Example output showing the initial connection and interactive shell prompt. ```python Connecting to http://localhost:8000/gateway/shell/ Welcome to the PyAMF 0.5.1 Shell Demo! Python 2.6.4 (r264:75706, Dec 22 2009, 21:55:52) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> ``` -------------------------------- ### HTML Response Example Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/appengine.rst Expected HTML output when accessing the application's root URL for non-AMF requests. ```html Hello, webapp World! ``` -------------------------------- ### Start PyAMF Development Server Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/ohloh.rst Launch the WSGI development server for Adobe Flash Player and Python AMF clients. Ensure you replace the placeholder API key with a valid one obtained from the Ohloh website. ```bash python server.py --api-key=123456789 ``` -------------------------------- ### Run Python AMF Client Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/guestbook.rst Execute the Python client script to interact with the guestbook application. This script is located in the 'python' folder of the example. ```bash python client.py ``` -------------------------------- ### Embed SWF with ByteArray Example Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/examples/actionscript/bytearray/flex/deploy/index.html Use this JavaScript function to embed a SWF file that demonstrates ByteArray functionality. Ensure you have the correct paths for the SWF and express install files. ```javascript swfobject.embedSWF("assets/bytearray.swf", "myContent", "450", "560", "10.0.0", "assets/expressInstall.swf"); ``` -------------------------------- ### Classic Twisted Web Service with PyAMF Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/twisted.rst This is a complete standalone twisted.web server that exposes functions via PyAMF. It requires manual import and starting of the reactor. ```python from twisted.internet import reactor from twisted.web.server import Site from twisted.web.resource import Resource from pyamf.remoting import gateway # Define a simple service class class MyService: def add(self, x, y): return x + y def subtract(self, x, y): return x - y # Create a PyAMF gateway instance # The gateway will expose functions from MyService service_gateway = gateway.TwistedGateway(MyService()) # Create a Twisted Resource that will handle AMF requests class AMFResource(Resource): isLeaf = True def render_POST(self, request): # The gateway handles the request and returns the AMF response return service_gateway.handle(request) # Create a Twisted Web Site root = Resource() root.putChild(b'myamf', AMFResource()) factory = Site(root) # Start the Twisted reactor reactor.listenTCP(8000, factory) reactor.run() ``` -------------------------------- ### Twisted WSGI Gateway with PyAMF Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/twisted.rst This example demonstrates using Twisted's WSGI support in combination with PyAMF's WSGIGateway. It allows running AMF services within a WSGI-compliant Twisted application. ```python from pyamf.remoting import gateway # Define a simple service class class MyService: def add(self, x, y): return x + y def subtract(self, x, y): return x - y # Create a PyAMF WSGI gateway instance # The gateway will expose functions from MyService service_gateway = gateway.WSGIGateway(MyService()) # This function is called by twistd to get the application def makeService(): from twisted.web.wsgi import WSGIResource from twisted.web.server import Site # Create a WSGIResource from the PyAMF WSGIGateway wsgi_resource = WSGIResource(reactor, reactor.getThreadPool(), service_gateway) # Return a Site object with the WSGI resource return Site(wsgi_resource) ``` -------------------------------- ### Initialize the database Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/shell.rst Run this command to set up the SQLite database required for session support. ```bash python manage.py syncdb ``` -------------------------------- ### Flash ActionScript Client Example Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/appengine.rst ActionScript code for a Flash application to interact with the PyAMF gateway on Google App Engine. Assumes a TextField instance named 'output' on the stage. ```actionscript var connection:AMFConnection = new AMFConnection(); connection.addEventListener(NetEvent.CONNECT, onConnect); connection.addEventListener(NetEvent.CLOSE, onClose); connection.addEventListener(NetStatusEvent.SECURITY_ERROR, onSecurityError); connection.addEventListener(NetStatusEvent.DATA_ERROR, onDataError); connection.connect("http://localhost:8080"); function onConnect(event:NetEvent):Void { trace("Connected to AMF Gateway"); var message:FlexMessage = new FlexMessage(); message.body = "Hello from Flash!"; connection.send("my_method", message); } function onClose(event:NetEvent):Void { trace("Connection Closed"); } function onSecurityError(event:NetStatusEvent):Void { trace("Security Error: " + event.info.code); } function onDataError(event:NetStatusEvent):Void { trace("Data Error: " + event.info.code); } // Example of receiving a response (assuming a method called 'my_method' on the server) connection.addEventListener(NetResponder.ON_RESULT, onResult); function onResult(event:NetResponder):Void { trace("Received Response: " + event.result); output.text = "Response: " + event.result; } ``` -------------------------------- ### Server help options Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/geoip.rst Displays available command-line arguments for the server. ```bash Usage: server.py [options] Options: -h, --help show this help message and exit -p PORT, --port=PORT port number [default: 8000] --host=HOST host address [default: localhost] ``` -------------------------------- ### View client help options Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/jython/swing.rst Display available command-line arguments for the client script. ```bash jython client.py --help ``` ```bash Usage: client.py [options] Options: -h, --help show this help message and exit -p PORT, --port=PORT port number [default: 8000] --host=HOST host address [default: localhost] ``` -------------------------------- ### Client help options Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/bytearray.rst Display available command-line options for the client script. ```bash Usage: client.py [options] Options: -h, --help show this help message and exit -p PORT, --port=PORT port number [default: 8000] --host=HOST host address [default: 127.0.0.1] ``` -------------------------------- ### Create New GAE Project Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/appengine.rst Commands to set up a new Google App Engine project with PyAMF. Ensure PyAMF is copied to the project root. ```bash cp -R /usr/local/google_appengine/new_project_template MyProject cp -R PyAMF-0.5.1/pyamf MyProject cd MyProject ls -l ``` -------------------------------- ### Initialize the Database Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/recordset.rst Run the initialization script to create the required SQLite database file. ```bash python init.py ``` -------------------------------- ### Initialize Pylons project Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/pylons.rst Commands to scaffold a legacy Pylons project and create a controller. ```bash $ paster create -t pylons testproject ``` ```bash $ cd testproject $ paster controller gateway ``` -------------------------------- ### Define WSGI startup file Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/apache/mod_wsgi.rst The WSGI entry point script for the application. ```python import sys import logging from logging.handlers import RotatingFileHandler sys.path.append('/var/www/myApp') from application import application # Setup logging handler = RotatingFileHandler('/var/log/apache2/myApp.log', maxBytes=10000, backupCount=1) handler.setLevel(logging.INFO) logger = logging.getLogger('myApp') logger.addHandler(handler) # Wrap the application to log errors def application_wrapper(environ, start_response): try: return application(environ, start_response) except Exception, e: logger.exception('Uncaught exception') raise e ``` -------------------------------- ### Build documentation Source: https://github.com/stdcarrot/py3amf/blob/master/doc/install.rst Commands to generate HTML documentation using Sphinx or Epydoc. ```bash make html ``` ```bash make.bat ``` ```bash sphinx-build -b html . build ``` ```bash epydoc --config=setup.cfg ``` -------------------------------- ### Python Client Help Options Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/guestbook.rst Display the available command-line options for the Python guestbook client by running it with the --help flag. This shows configurable parameters like port and host. ```bash Usage: client.py [options] Options: -h, --help show this help message and exit -p PORT, --port=PORT port number [default: 8000] --host=HOST host address [default: localhost] ``` -------------------------------- ### Run PyAMF unit tests Source: https://github.com/stdcarrot/py3amf/blob/master/doc/install.rst Execute the test suite using setuptools. ```bash python setup.py test ``` -------------------------------- ### Create WSGI directory Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/apache/mod_wsgi.rst Command to create the directory for the WSGI startup file. ```bash mkdir /var/www/wsgi ``` -------------------------------- ### Create Project Directory Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/jython/ant.rst Set up a new directory for your Jython-Ant project and navigate into it. ```bash mkdir jython-ant cd jython-ant ``` -------------------------------- ### Python Classes for Class Mapping Source: https://github.com/stdcarrot/py3amf/blob/master/doc/architecture/classmapping.rst These are the Python classes used in the class mapping examples. ```python class User: def __init__(self, name="", email=""): self.name = name self.email = email class Permission: def __init__(self, name="", level=0): self.name = name self.level = level ``` -------------------------------- ### Server output Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/werkzeug.rst Expected console output upon successful server startup. ```bash * Running on http://localhost:8000/ * Restarting with reloader... ``` -------------------------------- ### Gateway Server Options Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/recordset.rst Display available command-line options for the gateway server. ```bash python gateway.py --help ``` -------------------------------- ### Database initialization output Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/shell.rst Expected output after running the database synchronization command. ```bash Creating table django_content_type Creating table django_session ``` -------------------------------- ### Python Client Options Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/actionscript/recordset.rst Display available command-line options for the client script. ```bash python client.py --help ``` -------------------------------- ### Embed SWF for Authentication Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/examples/general/authentication/flash/flex/deploy/index.html Use swfobject to embed a Flash SWF file for authentication. Ensure Flash Player is installed. ```javascript swfobject.embedSWF("assets/authentication.swf", "myContent", "350", "300", "9.0.0", "assets/expressInstall.swf"); ``` -------------------------------- ### Server Debug Output Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/jython/ant.rst Example debug information displayed on the server side when the Ant application is running and handling an AMF request. ```bash [java] 2009-07-19 23:48:59,756 DEBUG [root] remoting.decode start [java] 2009-07-19 23:49:00,190 DEBUG [root] Remoting target: u'echo.echo' [java] 2009-07-19 23:49:00,223 DEBUG [root] remoting.decode end [java] 2009-07-19 23:49:00,232 INFO [root] AMF Request: [java] (u'/1', [u'Hello world!']) [java] [java] 2009-07-19 23:49:00,323 INFO [root] AMF Response: [java] (u'/1', u'Hello world!') [java] [java] 127.0.0.1 - - [19/Jul/2009 23:49:00] "POST / HTTP/1.1" 200 44 ``` -------------------------------- ### Get Registered Class Alias Source: https://github.com/stdcarrot/py3amf/blob/master/doc/architecture/classmapping.rst Use `pyamf.get_class_alias` to retrieve the Actionscript alias registered for a given Python class. This is useful for verification. ```python print pyamf.get_class_alias(User) ``` -------------------------------- ### Embed SWF with swfobject (AS1) Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/examples/general/helloworld/flash/as1/deploy/index.html Use swfobject to embed a SWF file into an HTML element. Ensure Adobe Flash Player is installed. ```javascript swfobject.embedSWF("assets/helloworld.swf", "myContent", "550", "400", "7.0.0", "assets/expressInstall.swf"); ``` -------------------------------- ### Embed GeoIP SWF with swfobject Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/examples/actionscript/geoip/flex/deploy/index.html Use swfobject to embed the geoip.swf file into the 'myContent' div. Ensure Flash Player 9.0.0 or later is installed. ```javascript swfobject.embedSWF("assets/geoip.swf", "myContent", "350", "150", "9.0.0", "assets/expressInstall.swf"); ``` -------------------------------- ### Example Service Method Raising TypeError Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/general/client.rst A sample Python service method that intentionally raises a TypeError. This is used to demonstrate exception handling in the client. ```python # service method def type_error(): raise TypeError('some useful message here') ``` -------------------------------- ### AMF Gateway Method Not Allowed Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/gateways/appengine.rst Expected browser response when attempting to access the AMF gateway using a GET request. AMF requires POST. ```html 405 Method Not Allowed To access this PyAMF gateway you must use POST requests (GET received) ``` -------------------------------- ### Embed Flash Socket SWF Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/examples/actionscript/socket/flex/deploy/index.html This snippet embeds a Flash SWF file that utilizes PyAMF for socket communication. Ensure Adobe Flash Player is installed. ```javascript swfobject.embedSWF("assets/socket.swf", "myContent", "450", "430", "9.0.0", "assets/expressInstall.swf"); ``` -------------------------------- ### Embed Ohloh API Flash Object Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/examples/actionscript/ohloh/flex/deploy/index.html Use this JavaScript to embed the Ohloh API Flash object. Ensure Flash Player 10.0.0 or later is installed. ```javascript swfobject.embedSWF("assets/OhlohApi.swf", "myContent", "100%", "100%", "10.0.0", "assets/expressInstall.swf"); ``` -------------------------------- ### PyAMF Application Startup File Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/apache/mod_python.rst This Python script serves as the startup file for your PyAMF application. Ensure the Apache user has read access to this file. ```python from pyamf.remoting.gateway import WSIGateway from pyamf.flex.messaging.messages import CommandMessage, RemotingMessage # Define your services here class MyServices: def greet(self, name): return "Hello, %s!" % name # Create a gateway instance gateway = WSIGateway(services=MyServices()) # This is the WSGI application callable def application(environ, start_response): return gateway(environ, start_response) ``` -------------------------------- ### Apache Virtual Host Configuration Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/apache/mod_python.rst Configure an Apache virtual host to serve your PyAMF application via mod_python. This setup directs requests to the WSGI gateway. ```apache ServerName 192.168.1.100 DocumentRoot /var/www/myApp AllowOverride None Options None Order allow,deny Allow from all # WSGI configuration WSGIScriptAlias /flashservices/gateway /var/www/myApp/wsgi.py # Optional: If you want to serve static files from your app directory # Alias /flashservices/static /var/www/myApp/static # # AllowOverride None # Options None # Order allow,deny # Allow from all # ErrorLog /var/log/apache2/myApp-error.log CustomLog /var/log/apache2/myApp-access.log combined ``` -------------------------------- ### Embed Guestbook SWF with swfobject Source: https://github.com/stdcarrot/py3amf/blob/master/doc/tutorials/examples/actionscript/guestbook/flex/deploy/index.html Use the swfobject library to embed the guestbook.swf file into the HTML page. Ensure Flash Player version 9.0.0 or higher is installed. ```javascript swfobject.embedSWF("assets/guestbook.swf", "myContent", "600", "500", "9.0.0", "assets/expressInstall.swf"); ```