예제 #1
0
파일: views.py 프로젝트: 08haozi/uliweb
 def soap(self):
     from pysimplesoap.server import SoapDispatcher
     import uliweb.contrib.soap as soap
     from uliweb.utils.common import import_attr
     from uliweb import application as app, response, url_for
     from functools import partial
     
     global __soap_dispatcher__
     
     if not __soap_dispatcher__:
         location = "%s://%s%s" % (
             request.environ['wsgi.url_scheme'],
             request.environ['HTTP_HOST'],
             request.path)
         namespace = functions.get_var(self.config).get('namespace') or location
         documentation = functions.get_var(self.config).get('documentation')
         dispatcher = SoapDispatcher(
             name = functions.get_var(self.config).get('name'),
             location = location,
             action = '', # SOAPAction
             namespace = namespace,
             prefix=functions.get_var(self.config).get('prefix'),
             documentation = documentation,
             exception_handler = partial(exception_handler, response=response),
             ns = True)
         for name, (func, returns, args, doc) in soap.__soap_functions__.get(self.config, {}).items():
             if isinstance(func, (str, unicode)):
                 func = import_attr(func)
             dispatcher.register_function(name, func, returns, args, doc)
     else:
         dispatcher = __soap_dispatcher__
         
     if 'wsdl' in request.GET:
         # Return Web Service Description
         response.headers['Content-Type'] = 'text/xml'
         response.write(dispatcher.wsdl())
         return response
     elif request.method == 'POST':
         def _call(func, args):
             rule = SimpleRule()
             rule.endpoint = func
             mod, handler_cls, handler = app.prepare_request(request, rule)
             result = app.call_view(mod, handler_cls, handler, request, response, _wrap_result, kwargs=args)
             r = _fix_soap_datatype(result)
             return r
         # Process normal Soap Operation
         response.headers['Content-Type'] = 'text/xml'
         log.debug("---request message---")
         log.debug(request.data)
         result = dispatcher.dispatch(request.data, call_function=_call)
         log.debug("---response message---")
         log.debug(result)
         response.write(result)
         return response
예제 #2
0
파일: views.py 프로젝트: kadefor/testdoc
def _show(filename,render=True):
    from uliweb.utils.rst import to_html
    from uliweb.core.template import template
    if not filename.endswith('.rst'):
        filename += '.rst'
    _f = application.get_file(filename, dir='files')
    if _f:
        def f():
            content = file(_f).read()
            if render:
                content = to_html(template(content, env=application.get_view_env()))
            else:
                content = to_html(content)
            return application.template('show_document.html', locals())
        response.write(f())
        #title = open(_f).read(100).strip('=').strip()
        return response
    else:
        error("Can't find the file %s" % filename)
예제 #3
0
    def soap(self):
        from pysimplesoap.server import SoapDispatcher
        import uliweb.contrib.soap as soap
        from uliweb.utils.common import import_attr
        from uliweb import application as app, response, url_for
        from functools import partial

        global __soap_dispatcher__

        if not __soap_dispatcher__:
            location = "%s://%s%s" % (request.environ['wsgi.url_scheme'],
                                      request.environ['HTTP_HOST'],
                                      request.path)
            namespace = functions.get_var(
                self.config).get('namespace') or location
            documentation = functions.get_var(self.config).get('documentation')
            dispatcher = SoapDispatcher(
                name=functions.get_var(self.config).get('name'),
                location=location,
                action='',  # SOAPAction
                namespace=namespace,
                prefix=functions.get_var(self.config).get('prefix'),
                documentation=documentation,
                exception_handler=partial(exception_handler,
                                          response=response),
                ns=True)
            for name, (func, returns, args,
                       doc) in soap.__soap_functions__.get(self.config,
                                                           {}).items():
                if isinstance(func, (str, unicode)):
                    func = import_attr(func)
                dispatcher.register_function(name, func, returns, args, doc)
        else:
            dispatcher = __soap_dispatcher__

        if 'wsdl' in request.GET:
            # Return Web Service Description
            response.headers['Content-Type'] = 'text/xml'
            response.write(dispatcher.wsdl())
            return response
        elif request.method == 'POST':

            def _call(func, args):
                rule = SimpleRule()
                rule.endpoint = func
                mod, handler_cls, handler = app.prepare_request(request, rule)
                result = app.call_view(mod,
                                       handler_cls,
                                       handler,
                                       request,
                                       response,
                                       _wrap_result,
                                       kwargs=args)
                r = _fix_soap_datatype(result)
                return r

            # Process normal Soap Operation
            response.headers['Content-Type'] = 'text/xml'
            log.debug("---request message---")
            log.debug(request.data)
            result = dispatcher.dispatch(request.data, call_function=_call)
            log.debug("---response message---")
            log.debug(result)
            response.write(result)
            return response