例子摘自官方文档:
这是服务端代码:Server.py
# Copyright (c) The PyAMF Project.
# See LICENSE.txt for details.
"""
Simple PyAMF server.
@see: U{Simple Example<http://pyamf.org/tutorials/actionscript/simple.html>} documentation.
@since: 0.5
"""
import logging
from wsgiref import simple_server
import pyamf
from pyamf import amf3
from pyamf.remoting.gateway.wsgi import WSGIGateway
#:路径名,用于flex接收Object时的类型转换 [RemoteClass] mapping
AMF_NAMESPACE = 'org.pyamf.examples.simple'
#: 提供服务的地址跟端口
host_info = ('localhost', 8000)
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)-5.5s [%(name)s] %(message)s')
def create_user(username, password, email):
"""
创建一个用户
"""
user = User(username, password, email)
return user
class User(object):
"""
Models information associated with a simple user object.
"""
# we need a default constructor (e.g. a paren-paren constructor)
def __init__(self, username=None, password=None, email=None):
"""
Create an instance of a user object.
"""
self.username = username
self.password = password
self.email = email
class UserService(object):
"""
提供服务
"""
def __init__(self, users):
"""
Create an instance of the user service.
"""
self.users = users
def get_user(self, username):
"""
Fetch a user object by C{username}.
"""
try:
return self.users[username]
except KeyError:
return "Username '%s' not found" % username
class EchoService(object):
"""
Provide a simple server for testing.
"""
def echo(self, data):
"""
Return data with chevrons surrounding it.
"""
return '<<%s>>' % data
def register_classes():
"""
Register domain objects with PyAMF.
"""
# set this so returned objects and arrays are bindab