Python 7.0pl5 User Manual

Browse online or download User Manual for Software Python 7.0pl5. Python 7.0pl5 User's Manual

  • Download
  • Add to my manuals
  • Print
  • Page
    / 124
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 0
Dumpleton
Software
Consulting
Pty Limited
OSE
Version 7.0pl5
19 January 2003
Copyright 2001-2003 Dumpleton Software Consulting Pty Limited
http://www.dscpl.com.au
Python Manual
Page view 0
1 2 3 4 5 6 ... 123 124

Summary of Contents

Page 1 - Pty Limited

DumpletonSoftwareConsultingPty LimitedOSEVersion 7.0pl519 January 2003Copyright  2001-2003 Dumpleton Software Consulting Pty Limitedhttp://www.dscpl.

Page 2

Python Modules10Module DescriptionsThe Python modules, their names and their purpose are described below.Installation and SetupThe "netsvc"

Page 3 - Table of Contents

Servlet Objects100def processContent(self,content):self._content.append(content)self._contentLength = self._contentLength + len(content)if self._conte

Page 4

Slow HTTP Clients101password = self.field("password")if self.authenticateUser(user,password):self.sendResponse(netsvc.REDIRECT_TEMPORARY)sel

Page 5

Servlet Objects102self._batch = Noneself._total = Noneself._count = 0self._job = netsvc.Job(self.generateContent)def destroyServlet(self):FormServlet.

Page 6

Slow HTTP Clients103Note that the Python wrapper around the C++ implementation of the HTTP servlet class performs buff-ering of content and will only

Page 7 - Manual Overview

Servlet Objects104

Page 8

105Servlet PluginsWhen using a file server object with the HTTP servlet framework, it is possible to associate a specialpurpose handler or plugin with

Page 9 - Python Modules

Servlet Plugins106The effect of this registration will be that whenever a file with extension ".py" is requested by a HTTPclient, the plugin

Page 10 - Installation and Setup

Module Caching107__servlet__ = ServletProxy()Note that an instance of the servlet is created for each request. That is, unlike other similar systemsav

Page 11

Servlet Plugins108Note that a module imported in this way can use the same mechanism to import further modules withthe dependence on those additional

Page 12

Plugin Aliasing109a servlet. In this later case, the name of the resource can remain the same, and no references to the re-source need to be changed.T

Page 13

Additional Information11An OSE installation supports libraries for different architectures. In order that the shared libraries foryour specific platfo

Page 15

111Remote AccessThe service agent and message exchange framework operate based on the concept of processes whichare a part of a distributed applicatio

Page 16

Remote Access112Even if a new protocol comes along, it is a relatively simple matter to incorporate yet another gateway,again without you having to ma

Page 17 - Exceptions in a Callback

The Client Application113In this example, any HTTP request made using a URL whose path falls under the base URL of "ht-tp://localhost:8000/servic

Page 18 - Logging Facility

Remote Access114return host in self._allow:class RpcGateway(netsvc.RpcGateway):def __init__(self,group,users=None):netsvc.RpcGateway.__init__(self,gro

Page 19

User Defined Types115User Defined TypesThe NET-RPC protocol supports all the types supported by the service agent framework, as well as theconcept of

Page 20 - Configuration File

Remote Access116Managing User SessionsA common practice with web based services is to have a request initiate a unique session for a user.Having opene

Page 21 - Environment Variables

Managing User Sessions117plicitly close off the session, it would be automatically closed after a period of 60 seconds of inactivity,or whatever perio

Page 22 - Unique Identifiers

Remote Access118self.cancelTimer("idle")self.destroyReferences()return 0Using the "netrpc" module to access the service, a client

Page 23 - Process Identity

The XML-RPC Gateway119port = 8000group = "web-services"httpd = netsvc.HttpDaemon(port)rpcgw = netsvc.xmlrpc.RpcGateway(group)httpd.attach(&q

Page 24 - Program Setup

Python Modules12

Page 25

Remote Access120# Explicitly specify use of Python implementation.rpcgw3 = netsvc.xmlrpc.RpcGateway(group,variant="python")Both these Python

Page 26 - Event Framework

The SOAP Gateway121The SOAP GatewayYet another alternative to XML-RPC is the SOAP protocol. A starting point for SOAP is the site "http://www.dev

Page 27

Remote Access122port = 8000group = "web-services"httpd = netsvc.HttpDaemon(port)rpcgw = netsvc.soap.RpcGateway(group)httpd.attach("/ser

Page 28 - Real Time Events

Using Multiple Gateways123called "ServiceFailure". All elements will be qualified in the OSE namespace. Inadequate priorart has been found a

Page 29 - Alarms and Timers

Remote Access124of also pushing a lot of the security issues onto the main web server where they are more often thannot easier to manage and deal with

Page 30 - Recurring Actions

13Logging FacilityThe logging facility provides you with a mechanism for generating and capturing messages generatedby your application. These can be

Page 31 - Socket Events

Logging Facility14To log a message, a handle to an instance of the Logger class is acquired and the "notify()"mem-ber function is called.imp

Page 32 - Program Signals

Specifying a Log File15The string used to specify the name of a log file may incorporate the following special tags.When the tags corresponding to dat

Page 33 - Program Shutdown

Logging Facility16Specifying a Log ChannelWhen logging a message, a log channel may also be specified. If the name of a log channel starts witha chara

Page 34

Exceptions in a Callback17try:function()except SystemExit:raiseexcept:netsvc.logException()sys.exit()The details of the exception are logged with leve

Page 35

Logging Facility18

Page 36

19Program SetupAs Python is an interpreted language, configuration of an application can be carried out by editing theactual scripts. In some circumst

Page 38 - Service Naming

Program Setup20import netsvcimport osnetsvc.loadConfig("database.cfg")netsvc.mergeConfig("PWD",os.getcwd())print netsvc.lookupConf

Page 39 - Anonymous Service

Naming Hierarchies21file = "database.cfg"errors = netsvc.loadConfig(file,None)if errors:errors = "Error reading %s\n%s" % (‘file‘,

Page 40

Program Setup22To lookup the value of an environment variable the function "lookupEnviron()"isused.Ifanewenvironment variable needs to be se

Page 41 - Service Registry

Process Identity23id1 = netsvc.uniqueId(netsvc.ID_SHORT_FORMAT,"$SID?")The short format identifier is suitable for use within the context of

Page 42

Program Setup24

Page 43 - Service Announcements

25Event FrameworkThe main support for concurrency in the OSE C++ class libraries comes in the form of a mechanismfor building event driven systems. Th

Page 44 - Service Lookup

Event Framework26jobs will be reclassified as standard jobs and subsequently executed. When scheduling a job, if jobs ofthe same type already exist, t

Page 45

Scheduling a Job27All that is occuring here is that when the "cancel()" member function is called, a flag is set. Whenthe job is executed it

Page 46

Event Framework28cute()" member function, these will override any which may have been supplied when that instanceof the Job class was created.Rea

Page 47 - Service Reports

Destroying Agents29using the same identifier will first be cancelled. If you want to cancel all jobs scheduled using the"scheduleAction()" m

Page 48 - Monitoring Reports

3Table of ContentsTable of Contents...3Manual Overview ...7Python Modules ...

Page 49

Event Framework30The member function for setting an alarm is "setAlarm()" and that for starting a timer is "start-Timer()". The fi

Page 50 - Lifetime of Reports

Socket Events31class Object(netsvc.Agent):def __init__(self):self.scheduleAction(self.daily,"00***","daily")self.scheduleAction(se

Page 51

Event Framework32Other possible values for the third argument are SOCKET_POLLOUT and SOCKET_POLLPRI.Thevalue SOCKET_POLLPRI is similar to SOCKET_POLLI

Page 52

Program Shutdown33ating system is being shutdown. Other uses for program signals are to force an application to reread aconfiguration file.These three

Page 53 - Identity of Subscribers

Event Framework34should call this member function. This member function can also be called when an external signalintended to shutdown the program is

Page 54

Program Shutdown35itly provide the time delay as an argument. If this is done, the argument should express the number offull or partial seconds as a f

Page 55 - Existence of Publishers

Event Framework36Note that whatever mechanism is used to initiate program shutdown using these features, messageswill be displayed via the logger indi

Page 56

37Service AgentsThe service agent framework in OSE provides request/reply and publish/subscribe features similar tothat found in message oriented midd

Page 57 - Service Requests

Service Agents38The major classes in the OSE C++ class library involved in providing this functionality are theOTC_SVBroker, OTC_SVRegistry and OTC_EV

Page 58

Service Audience39Service AudienceWhen you create a service, the existance of that service will be broadcast to all connected processes.If you wish to

Page 59

Table of Contents4Service Lookup ...44Service Reports...47Publishing Reports ...

Page 60

Service Agents40Service GroupsWhen a service agent is created, the name of the service is notionally listed in a global group. In respectof this globa

Page 61 - Detecting a Failure

Service Registry41Any service agent may make queries against its local service registry and get back an immediate resultwhich reflects the current sta

Page 62

Service Agents42Member functions of a service binding object which may prove useful include "serviceName()","agentIdentity()", &qu

Page 63

Service Announcements43Service AnnouncementsIf a service agent subscribes to the registry using a specific service name, the service agent will be no-

Page 64 - Servicing a Request

Service Agents44Group AnnouncementsIf a service agent subscribes to the service registry using a specific service group, it will be notifiedwhen any s

Page 65 - Generating a Failure

Service Lookup45class PollingService(netsvc.Service):def __init__(self,name,period=60):netsvc.Service.__init__(self)self._name = nameself._period = pe

Page 67

47Service ReportsWhen using the service agent framework, in addition to being able to subscribe to the service registryin order to receive announcemen

Page 68

Service Reports48Publishing ReportsIf a service agent needs to publish a report, the member function "publishReport()"isused.Inpublishing a

Page 69 - Local Service Requests

Monitoring Reports49a subscription of "system.*" will match "system.time" and "system.statistics.us-ers", but not "

Page 70

5Managing User Sessions ...116The XML-RPC Gateway...118The SOAP Gateway...121Using Multiple Gateways...

Page 71

Service Reports50class Subscriber(netsvc.Service):def __init__(self):netsvc.Service.__init__(self)# subscribe to the service group "publishers&qu

Page 72 - Service Availability

Lifetime of Reports51For such cases, it is possible to supply an optional lifetime for a report. That is, a time in seconds forwhich the report should

Page 73

Service Reports52Although "purgeReports()" exists specifically to deal with potential performance issues in a verylimited number of cases, t

Page 74

Identity of Subscribers53A further use of the mechanism for identifying a subscribers identity, is so that subscriptions can betracked and for process

Page 75 - Distributed Exchange Server

Service Reports54subject corresponding to a log channel, the log messages on that log channel will be intercepted andpublished. This can be useful as

Page 76 - Multiple Exchange Groups

Existence of Publishers55essary to track the lifetime of each. It is also useful where it might be necessary to immediately sendoff a request to each

Page 77

Service Reports56

Page 78

57Service RequestsThe ability within the service agent framework to find out what services exist and the ability of a serv-ice agent to publish report

Page 79 - Message Encoding

Service Requests58When invoking "serviceEndPoint()", the member function needs to be supplied with either aservice binding object for the pa

Page 80

Handling a Response59for binding in bindings:service = self.serviceEndPoint(binding)if service:service.reset()Handling a ResponseWhen you send a servi

Page 82

Service Requests60Identifying a ResponseIf a callback is being registered to handle the response from multiple service requests, you will mostlikely n

Page 83

Detecting a Failure61id = service.reset()self.processResponse(self.resetResponse,id)print "request",binding.agentIdentity(),iddef resetRespo

Page 84

Service Requests62if failure.origin() == "netsvc" and \failure.error() == netsvc.SERVER_METHOD_UNAVAILABLE:# method didn’t existAs an altern

Page 85

Lack of Response63Lack of ResponseWhen you send a request, there is no gaurantee that the remote service agent hasn’t been destroyedeven before it rec

Page 86

Service Requests64self.processFailure(self.uptimeFailure,id,60)def uptimeResponse(self,result):print resultdef uptimeFailure(self,id,error,description

Page 87

Generating a Failure65The reason for requiring that methods be explicitly exported is that it would usually be quite dangerousto allow open access to

Page 88 - The HTTP Daemon

Service Requests66raised, you should avoid an except clause which catches all exceptions in any code which enclosescode which might call "abortRe

Page 89 - The File Server

Delaying a Response67When the member function "suspendResponse()" is called, a callback function should be sup-plied as argument which final

Page 90 - Client Authorisation

Service Requests68Note that "suspendResponse()" and "resumeResponse()" were only added in OSE 7.0pl5and are a layer on top of the

Page 91 - HTTP Server Objects

Invalid Request Method69client = self.currentRequest().sender()self._count = self._count + 1name "%s/%d" % (self.serviceName(),self._count)s

Page 92 - The Error Servlet

7Manual OverviewThis manual covers the Python wrappers around the OSE C++ class library. The wrappers make avail-able functionality related to the log

Page 93 - The File Servlet

Service Requests70that the result is returned immediately. Note that since the response is immediate, you can’t call a meth-od which itself would try

Page 94 - Logging of Requests

71Message ExchangeThe features of the service agent framework may be used standalone within a single process or acrossa set of connected processes. Th

Page 95

Message Exchange72Exchange InitialisationTo create a message exchange endpoint in a process, the Exchange class is used. When creating aninstance of t

Page 96 - Persistent Connections

Service Availability73er endpoint and a new client connects, a subscriber to that service in the client will be notified that theservice is available.

Page 97

Message Exchange74print "%s originally started at %s" % (publisher,str(content))elif subject == "system.time":print "%s was s

Page 98 - Destruction of Servlets

Authorisation of Clients75Overriding this method can be useful purely for logging purposes, but might also be used in a clientprocess to trigger an an

Page 99 - Processing Content

Message Exchange76When an application is distributed across multiple machines, it is often the case that even if one ma-chine were to be shutdown, the

Page 100 - The Form Servlet

Multiple Exchange Groups77With respect to service visibility, a message exchange endpoint will only pass information about serv-ices if the service au

Page 101 - Slow HTTP Clients

Message Exchange78tached to the default exchange group. Back end services will still be able to see any services on thedefault exchange group which ha

Page 102 - Servlet Objects

79Message EncodingAs the service agent framework is designed as a distributed system covering multiple programminglanguages, it is necessary that any

Page 103

Manual Overview8Service Agents Describes how to create service agents, add themto groups, subscribe to announcements regardingspecific services or mem

Page 104

Message Encoding80Supported Data TypesCommunication between services is mediated through a layer of code which is written in C++. Theonly exception to

Page 105

Mapping of Scalar Types81For the date and time types, the current Python implementation does not do any checking to determineif the supplied values ar

Page 106 - Servlet Plugins

Message Encoding82If a service is implemented using the OSE C++ class library directly, different size versions of the in-teger and floating point typ

Page 107

User Defined Types83"xsd:hexBinary" will also be added at some point in the future as well. If you wish to send a Uni-code string, you shoul

Page 108 - Plugin Aliasing

Message Encoding84To add a new mapping at global scope the functions "encoder()" and "decoder()" should beused to register functio

Page 109

Handling Structured Types85ues of the correct type before hand. A service may also override the default decoders for extended typessuch as the date an

Page 110

Message Encoding86

Page 111

87Servlet FrameworkThe HTTP servlet framework can be used to provide a window into your application. A number of pre-defined servlets are provided or

Page 112 - The RPC Gateway

Servlet Framework88to provide a servlet to handle the actual request. If no server object is found corresponding to that por-tion of the URL namespace

Page 113 - Restricting Client Access

The File Server89daemon.start()dispatcher.run()When a HTTP server object is registered, the first argument to the "attach()" member function

Page 114 - Duplicate Services

9Python ModulesOSE includes a number of Python modules. The main module is a wrapper around functionality pro-vided in the OSE C++ class library. Thos

Page 115 - User Defined Types

Servlet Framework90When an instance of the FileServer class is created, it must be supplied with the filesystem direc-tory from which files are to be

Page 116 - Managing User Sessions

User Authorisation91If access to a particular client is disallowed, the connection will be dropped immediately. The clientwill not receive any form of

Page 117

Servlet Framework92return netsvc.ErrorServlet(404)daemon = netsvc.HttpDaemon(8000)server = HttpServer()daemon.attach("/test",server)daemon.s

Page 118

The Redirect Servlet93The Redirect ServletThe redirect servlet as implemented by the RedirectServlet class would be used when it is nec-essary to redi

Page 119 - The XML-RPC Gateway

Servlet Framework94becomes congested. Although the servlet may be forced to wait before it can send more data, any otherjobs in the event system will

Page 120 - Remote Access

95Servlet ObjectsTo make the most of the HTTP servlet framework it will be necessary to create your own servlets forinteracting with your application.

Page 121

Servlet Objects96if self.requestMethod() != "GET":self.sendError(400)else:self.sendResponse(200)self.sendHeader("Content-Type",&qu

Page 122

Delaying a Response97connection. Negotiation of persistent connections between the HTTP client and server is managed byusing special HTTP request and

Page 123

Servlet Objects98Destruction of ServletsThe destruction of a servlet can come about as a result of two situations. The first situation is where aservl

Page 124

Processing Content99been derived from the Agent class, this would include calling the "destroyReferences()"member function.Processing Conten

Comments to this Manuals

No comments