|
Apache/2.2.15 (CentOS) Linux obd60-6c49958d75-2q7cw 5.4.0-174-generic #193-Ubuntu SMP Thu Mar 7 14:29:28 UTC 2024 x86_64 uid=48(apache) gid=48(apache) groups=48(apache) server ip : 104.21.65.202 | your ip : 10.244.126.0 safemode OFF > / usr / lib64 / python2.6 / |
| Filename | /usr/lib64/python2.6/SimpleXMLRPCServer.pyo |
| Size | 19.17 kb |
| Permission | rw-r--r-- |
| Owner | apache |
| Create time | 23-Dec-2025 17:41 |
| Last modified | 20-Jun-2019 19:45 |
| Last accessed | 22-Apr-2026 05:23 |
| Actions | edit | rename | delete | download (gzip) |
| View | text | code | image |
Ñò
§ÚêLc @ s\ d Z d d k Z d d k l Z d d k Z d d k Z d d k Z d d k Z d d k Z y d d k Z Wn e j
o
e
Z n Xe d � Z d � Z
d � Z d f d � � YZ d e i f d
� � YZ d e i e f d � � YZ d
e f d � � YZ e d j oE d GHe d d f � Z e i e � e i d � d � e i � n d S( s9 Simple XML-RPC Server.
This module can be used to create simple XML-RPC servers
by creating a server and either installing functions, a
class instance, or by extending the SimpleXMLRPCServer
class.
It can also be used to handle XML-RPC requests in a CGI
environment using CGIXMLRPCRequestHandler.
A list of possible usage patterns follows:
1. Install functions:
server = SimpleXMLRPCServer(("localhost", 8000))
server.register_function(pow)
server.register_function(lambda x,y: x+y, 'add')
server.serve_forever()
2. Install an instance:
class MyFuncs:
def __init__(self):
# make all of the string functions available through
# string.func_name
import string
self.string = string
def _listMethods(self):
# implement this method so that system.listMethods
# knows to advertise the strings methods
return list_public_methods(self) + ['string.' + method for method in list_public_methods(self.string)]
def pow(self, x, y): return pow(x, y)
def add(self, x, y) : return x + y
server = SimpleXMLRPCServer(("localhost", 8000))
server.register_introspection_functions()
server.register_instance(MyFuncs())
server.serve_forever()
3. Install an instance with custom dispatch method:
class Math:
def _listMethods(self):
# this method must be present for system.listMethods
# to work
return ['add', 'pow']
def _methodHelp(self, method):
# this method must be present for system.methodHelp
# to work
if method == 'add':
return "add(2,3) => 5"
elif method == 'pow':
return "pow(x, y[, z]) => number"
else:
# By convention, return empty
# string if no help is available
return ""
def _dispatch(self, method, params):
if method == 'pow':
return pow(*params)
elif method == 'add':
return params[0] + params[1]
else:
raise 'bad method'
server = SimpleXMLRPCServer(("localhost", 8000))
server.register_introspection_functions()
server.register_instance(Math())
server.serve_forever()
4. Subclass SimpleXMLRPCServer:
class MathServer(SimpleXMLRPCServer):
def _dispatch(self, method, params):
try:
# We are forcing the 'export_' prefix on methods that are
# callable through XML-RPC to prevent potential security
# problems
func = getattr(self, 'export_' + method)
except AttributeError:
raise Exception('method "%s" is not supported' % method)
else:
return func(*params)
def export_add(self, x, y):
return x + y
server = MathServer(("localhost", 8000))
server.serve_forever()
5. CGI script:
server = CGIXMLRPCRequestHandler()
server.register_function(pow)
server.handle_request()
iÿÿÿÿN( t Faultc C sk | o | i d � } n
| g } xA | D]9 } | i d � o t d | � � q* t | | � } q* W| S( sG resolve_dotted_attribute(a, 'b.c.d') => a.b.c.d
Resolves a dotted attribute name to an object. Raises
an AttributeError if any attribute in the chain starts with a '_'.
If the optional allow_dotted_names argument is false, dots are not
supported and this function operates similar to getattr(obj, attr).
t .t _s( attempt to access private attribute "%s"( t splitt
startswitht AttributeErrort getattr( t objt attrt allow_dotted_namest attrst i( ( s* /usr/lib64/python2.6/SimpleXMLRPCServer.pyt resolve_dotted_attributer s
c C sS g } t | � D]; } | i d � o$ t t | | � d � o | | q q ~ S( sk Returns a list of attribute strings, found in the specified
object, which represent callable attributesR t __call__( t dirR t hasattrR ( R t _[1]t member( ( s* /usr/lib64/python2.6/SimpleXMLRPCServer.pyt list_public_methods� s c C s+ h } x | D] } d | | <q
W| i � S( sÌ
§ÚêLc @ s\ d Z d d k Z d d k l Z d d k Z d d k Z d d k Z d d k Z d d k Z y d d k Z Wn e j
o
e
Z n Xe d � Z d � Z
d � Z d f d � � YZ d e i f d
� � YZ d e i e f d � � YZ d
e f d � � YZ e d j oE d GHe d d f � Z e i e � e i d � d � e i � n d S( s9 Simple XML-RPC Server.
This module can be used to create simple XML-RPC servers
by creating a server and either installing functions, a
class instance, or by extending the SimpleXMLRPCServer
class.
It can also be used to handle XML-RPC requests in a CGI
environment using CGIXMLRPCRequestHandler.
A list of possible usage patterns follows:
1. Install functions:
server = SimpleXMLRPCServer(("localhost", 8000))
server.register_function(pow)
server.register_function(lambda x,y: x+y, 'add')
server.serve_forever()
2. Install an instance:
class MyFuncs:
def __init__(self):
# make all of the string functions available through
# string.func_name
import string
self.string = string
def _listMethods(self):
# implement this method so that system.listMethods
# knows to advertise the strings methods
return list_public_methods(self) + ['string.' + method for method in list_public_methods(self.string)]
def pow(self, x, y): return pow(x, y)
def add(self, x, y) : return x + y
server = SimpleXMLRPCServer(("localhost", 8000))
server.register_introspection_functions()
server.register_instance(MyFuncs())
server.serve_forever()
3. Install an instance with custom dispatch method:
class Math:
def _listMethods(self):
# this method must be present for system.listMethods
# to work
return ['add', 'pow']
def _methodHelp(self, method):
# this method must be present for system.methodHelp
# to work
if method == 'add':
return "add(2,3) => 5"
elif method == 'pow':
return "pow(x, y[, z]) => number"
else:
# By convention, return empty
# string if no help is available
return ""
def _dispatch(self, method, params):
if method == 'pow':
return pow(*params)
elif method == 'add':
return params[0] + params[1]
else:
raise 'bad method'
server = SimpleXMLRPCServer(("localhost", 8000))
server.register_introspection_functions()
server.register_instance(Math())
server.serve_forever()
4. Subclass SimpleXMLRPCServer:
class MathServer(SimpleXMLRPCServer):
def _dispatch(self, method, params):
try:
# We are forcing the 'export_' prefix on methods that are
# callable through XML-RPC to prevent potential security
# problems
func = getattr(self, 'export_' + method)
except AttributeError:
raise Exception('method "%s" is not supported' % method)
else:
return func(*params)
def export_add(self, x, y):
return x + y
server = MathServer(("localhost", 8000))
server.serve_forever()
5. CGI script:
server = CGIXMLRPCRequestHandler()
server.register_function(pow)
server.handle_request()
iÿÿÿÿN( t Faultc C sk | o | i d � } n
| g } xA | D]9 } | i d � o t d | � � q* t | | � } q* W| S( sG resolve_dotted_attribute(a, 'b.c.d') => a.b.c.d
Resolves a dotted attribute name to an object. Raises
an AttributeError if any attribute in the chain starts with a '_'.
If the optional allow_dotted_names argument is false, dots are not
supported and this function operates similar to getattr(obj, attr).
t .t _s( attempt to access private attribute "%s"( t splitt
startswitht AttributeErrort getattr( t objt attrt allow_dotted_namest attrst i( ( s* /usr/lib64/python2.6/SimpleXMLRPCServer.pyt resolve_dotted_attributer s
c C sS g } t | � D]; } | i d � o$ t t | | � d � o | | q q ~ S( sk Returns a list of attribute strings, found in the specified
object, which represent callable attributesR t __call__( t dirR t hasattrR ( R t _[1]t member( ( s* /usr/lib64/python2.6/SimpleXMLRPCServer.pyt list_public_methods� s c C s+ h } x | D] } d | | <q
W| i � S( sÌ