Exemplo n.º 1
0
 def execute(self, request):
     data = request.get_data().read_all()
     if not data:
         raise MpxException('XML-RPC request has no POST data.')
     ## process xmlrpc, getting the name of the method
     ## and parameters
     params, method = xmlrpclib.loads(data)
     if request.user_object() is None and len(params):
         session_id = params[0]
         user = self.session_manager.get_user_from_sid(session_id)
         request.user_object(user)
     ## get the name of the object
     ## and the name of method
     ## They are delimited by a colon.
     if '.' in method:
         tokens = string.split(method, '.')
     elif ':' in method:
         tokens = string.split(method, ':')
     else:
         raise MpxException('Invalid XMLRPC Request: %r' % data)
     object_alias = tokens[0]
     method_name = tokens[1]
     # Call the requested object
     # and return response
     self.debugout("Calling %s.%s" % (object_alias, method_name))
     return self.call(object_alias, method_name, params)
Exemplo n.º 2
0
 def invoke(self, request):
     data = self._get_data(request)
     results = []
     # process xmlrpc, getting the name of the method
     # and parameters
     r = xmlrpclib.loads(data)
     params = r[0]
     method = r[1]
     for param in params:
         # since we are spliting on ":" I put in a place holder
         # for the mpx:// before I do a split the put it back after
         # since mpx:// has a ":"
         param = param.replace("mpx://", '$$PLACE_HOLDER$$')
         p_s = param.split(':')
         service = p_s[0].replace('$$PLACE_HOLDER$$', 'mpx://')
         method = p_s[1]
         try:
             result = self._invoke(service, method)
             results.append(result)
         except Exception, e:
             if self.log_n_exceptions:
                 msglog.exception()
                 if self.log_n_exceptions > 0:
                     self.log_n_exceptions -= 1
             results.append(self._exception_string(e))
Exemplo n.º 3
0
    def handle_request(self, request):
        print 'handle_request'
        if not self.running:
            return request.error(503) #service unavailable
        try:
            self.data = data = request.get_data().read_all()
            if not data:
                raise EProtocol('could not get DATA parameter from posted data')
            ## process xmlrpc, getting the name of the method
            ## and parameters
            params, method = xmlrpclib.loads(data)
            return

            object_alias = ''
            method_name = ''
            ## get the name of the object
            ## and the name of method
            ## They are delimited by a colon.

        except:
            msglog.exception()
            raise MpxException('Error occurred while processing Brivo XMLRPC command')
        # XML-RPC Call was successful.
        # Send back the XML result to client
        reply = Response(request)
        reply.set_header('Content-Length', len(response))
        reply.set_header('Content-Type', 'text/xml')
        reply.send(response)
        return
Exemplo n.º 4
0
 def invoke(self,request):
     data =self._get_data(request)
     results = []
     # process xmlrpc, getting the name of the method
     # and parameters
     r = xmlrpclib.loads(data)
     params = r[0]
     method = r[1]
     for param in params:
         # since we are spliting on ":" I put in a place holder
         # for the mpx:// before I do a split the put it back after
         # since mpx:// has a ":"
         param = param.replace("mpx://",'$$PLACE_HOLDER$$')
         p_s = param.split(':')
         service = p_s[0].replace('$$PLACE_HOLDER$$','mpx://')
         method = p_s[1]
         try:
             result = self._invoke(service, method)
             results.append(result)
         except Exception, e:
             if self.log_n_exceptions:
                 msglog.exception()
                 if self.log_n_exceptions > 0:
                     self.log_n_exceptions -= 1
             results.append(self._exception_string(e))
Exemplo n.º 5
0
 def execute(self, request):
     data = request.get_data().read_all()
     if not data:
         raise MpxException('XML-RPC request has no POST data.')
     ## process xmlrpc, getting the name of the method
     ## and parameters
     params, method = xmlrpclib.loads(data)
     if request.user_object() is None and len(params):
             session_id = params[0]
             user = self.session_manager.get_user_from_sid(session_id)
             request.user_object(user)
     ## get the name of the object
     ## and the name of method
     ## They are delimited by a colon.
     if '.' in method:
         tokens = string.split(method, '.')
     elif ':' in method:
         tokens = string.split(method, ':')
     else:
         raise MpxException('Invalid XMLRPC Request: %r' % data)
     object_alias = tokens[0]
     method_name = tokens[1]
     # Call the requested object
     # and return response
     self.debugout("Calling %s.%s" % (object_alias, method_name))
     return self.call(object_alias, method_name, params)
Exemplo n.º 6
0
    def handle_request(self, request):
        print 'handle_request'
        if not self.running:
            return request.error(503)  #service unavailable
        try:
            self.data = data = request.get_data().read_all()
            if not data:
                raise EProtocol(
                    'could not get DATA parameter from posted data')
            ## process xmlrpc, getting the name of the method
            ## and parameters
            params, method = xmlrpclib.loads(data)
            return

            object_alias = ''
            method_name = ''
            ## get the name of the object
            ## and the name of method
            ## They are delimited by a colon.

        except:
            msglog.exception()
            raise MpxException(
                'Error occurred while processing Brivo XMLRPC command')
        # XML-RPC Call was successful.
        # Send back the XML result to client
        reply = Response(request)
        reply.set_header('Content-Length', len(response))
        reply.set_header('Content-Type', 'text/xml')
        reply.send(response)
        return
Exemplo n.º 7
0
 def read(self):
     # leading 4 bytes indicates length of xml-rpc response payload 
     read_len = struct.unpack('<I', self._s.recv(4, timeout=SOCK_OP_TIMEOUT))[0]
     # retreive and marshall the results.  If the xml-rpc packet represents a 
     # fault condition, loads() raises a Fault exception.  @fixme - need a 
     # better understanding of their normal result structure
     rslt = xmlrpclib.loads(self._s.recv(read_len, timeout=SOCK_OP_TIMEOUT))[0]
     return rslt
Exemplo n.º 8
0
 def read(self):
     # leading 4 bytes indicates length of xml-rpc response payload
     read_len = struct.unpack('<I',
                              self._s.recv(4, timeout=SOCK_OP_TIMEOUT))[0]
     # retreive and marshall the results.  If the xml-rpc packet represents a
     # fault condition, loads() raises a Fault exception.  @fixme - need a
     # better understanding of their normal result structure
     rslt = xmlrpclib.loads(self._s.recv(read_len,
                                         timeout=SOCK_OP_TIMEOUT))[0]
     return rslt
Exemplo n.º 9
0
    def handle_request(self, request):
        response = Response(request)
        response.set_header('Content-Type', 'text/xml')
        try:
            path = request.get_path().split('/')
            node_path = '/%s' % string.join(path[3:], '/')
            #
            #
            #
            # just for testing right now
            #
            #
            #
            if node_path == '' and len(path) < 4:
                results = self.invoke(request)
                xml = xmlrpclib.dumps((results, ), methodresponse=1)
                response.set_header('Content-Length', len(xml))
                response.set_header('Content-Type', 'text/xml')
                response.send(xml)
            else:
                node = self._as_node(node_path)
                data = self._get_data(request)
                # process xmlrpc, getting the name of the method
                # and parameters
                params, method = xmlrpclib.loads(data)
                method_name = ''
                # get the name of the object
                # and the name of method
                m = getattr(node, method)
                if params == '':
                    params = None
                result = (apply(m, params), )
                if hasattr(result[0], 'has_key'):
                    for k in result[0].keys():
                        if hasattr(result[0][k], 'has_key') \
                           and result[0][k].has_key('value') \
                           and isinstance(result[0][k]['value'],Exception):
                            result[0][k][
                                'value'] = 'error: %s' % result[0][k]['value']
                xml = xmlrpclib.dumps(result, methodresponse=1)
                # XML-RPC Call was successful.
                # Send back the XML result to client
                response = Response(request)
                response.set_header('Content-Length', len(xml))
                response.set_header('Content-Type', 'text/xml')
                response.send(xml)
        except Exception, err:
            if self.log_n_exceptions:
                msglog.exception()
                if self.log_n_exceptions > 0:
                    self.log_n_exceptions -= 1
            try:
                faultString = """<exception>
<module>%s</module>
<class>%s.%s</class>
<str>%r</str>
</exception>""" % (err.__class__.__module__, err.__class__.__module__,
                   err.__class__.__name__, str(err))
            except:
                msglog.exception()
                faultString = "%s" % err
            fault_xml = xmlrpclib.dumps(xmlrpclib.Fault(1, faultString))
            response.set_header('Content-Length', len(fault_xml))
            response.send(fault_xml)
Exemplo n.º 10
0
    def handle_request(self, request):
        response = Response(request)
        response.set_header('Content-Type', 'text/xml')
        try:
            path = request.get_path().split('/')
            node_path = '/%s' % string.join(path[3:],'/')
            #
            #
            #
            # just for testing right now
            #
            #
            #
            if node_path == '' and len(path) < 4:
                results = self.invoke(request)
                xml = xmlrpclib.dumps((results,),methodresponse=1)
                response.set_header('Content-Length', len(xml))
                response.set_header('Content-Type', 'text/xml')
                response.send(xml)
            else:
                node = self._as_node(node_path)
                data = self._get_data(request)
                # process xmlrpc, getting the name of the method
                # and parameters
                params, method = xmlrpclib.loads(data)
                method_name = ''
                # get the name of the object
                # and the name of method
                m = getattr(node, method)
                if params == '':
                    params = None
                result = (apply(m,params),)
                if hasattr(result[0],'has_key'):
                    for k in result[0].keys():
                        if hasattr(result[0][k], 'has_key') \
                           and result[0][k].has_key('value') \
                           and isinstance(result[0][k]['value'],Exception):
                            result[0][k]['value'] = 'error: %s' % result[0][k]['value']
                xml = xmlrpclib.dumps(result,methodresponse=1)
                # XML-RPC Call was successful.
                # Send back the XML result to client
                response = Response(request)
                response.set_header('Content-Length', len(xml))
                response.set_header('Content-Type', 'text/xml')
                response.send(xml)
        except Exception,err:
            if self.log_n_exceptions:
                msglog.exception()
                if self.log_n_exceptions > 0:
                    self.log_n_exceptions -= 1
            try:
                faultString = """<exception>
<module>%s</module>
<class>%s.%s</class>
<str>%r</str>
</exception>""" % (err.__class__.__module__,
                   err.__class__.__module__,
                   err.__class__.__name__,
                   str(err))                
            except:
                msglog.exception()
                faultString = "%s" % err
            fault_xml = xmlrpclib.dumps(
                    xmlrpclib.Fault(1, faultString)
                    )
            response.set_header('Content-Length', len(fault_xml))
            response.send(fault_xml)