Remote Access

return host in self._allow:

class RpcGateway(netsvc.RpcGateway): def __init__(self,group,users=None):

netsvc.RpcGateway.__init__(self,group): self._allow = users

def authorise(self,login,password):

return self._allow == None or \ (self._allow.has_key(login) and \ self._allow[login] == password)

users = { "admin": "secret" }

port = 8000

group = "web-services" httpd = HttpDaemon(port) rpcgw = RpcGateway(group,users) httpd.attach("/service",rpcgw) httpd.start()

When user authentication is being used, the login and password of the user can be supplied as addi- tional arguments to the RemoteService class when it is created.

url = "http://localhost:8000/service/validator" service = netrpc.RemoteService(url,"admin","secret") print service.echo(1,1L,1.1,"1")

If a login and password aren’t supplied when required, or the details are wrong, the Authentica- tionFailure exception will be raised.

Duplicate Services

Because a URL identifies a unique resource, a conflict arises due to the fact that within the service agent framework it is possible to create multiple services with the same name. What happens in this circumstance is that the RPC gateway will remember which service agent was the first it saw in the required service group, having a particular service name. While that particular service agent exists, it will always use that service agent as the target of requests.

When there are multiple service agents with the same service name and the first one seen by the RPC gateway is destroyed, the RPC gateway will then fall back to using the second one it saw. That is, the RPC gateway will always use the service agent which it has known about the longest. In general, if you intend to make services accessible using the RPC gateway, it is recommended that you always use unique service names within the service group dictating which services are actually visible.

114

Page 114
Image 114
Python Python Manual, 7.0pl5 manual Duplicate Services