Exemplo n.º 1
0
Arquivo: app.py Projeto: comger/kpages
    def _get_webapp(self):
        settings = {"debug": __conf__.DEBUG,
                    "static_path": app_path(__conf__.STATIC_DIR_NAME),
                    "template_path": app_path(__conf__.TEMPLATE_DIR_NAME),
                    "gzip": __conf__.GZIP,
                    "cookie_secret": __conf__.COOKIE_SECRET,
                    "ui_modules":self.uimodules,
                    "ui_methods":self.uimethods,
                    "xsrf_cookies": __conf__.XSRF_COOKIES}

        return tornado.web.Application(self._handlers, **settings)
Exemplo n.º 2
0
    def _get_webapp(self):
        settings = {
            "debug": __conf__.DEBUG,
            "static_path": app_path(__conf__.STATIC_DIR_NAME),
            "template_path": app_path(__conf__.TEMPLATE_DIR_NAME),
            "gzip": __conf__.GZIP,
            "cookie_secret": __conf__.COOKIE_SECRET,
            "ui_modules": self.uimodules,
            "ui_methods": self.uimethods,
            "xsrf_cookies": __conf__.XSRF_COOKIES
        }

        return tornado.web.Application(self._handlers, **settings)
Exemplo n.º 3
0
Arquivo: app.py Projeto: zhangxj/web
    def _get_webapp(self):
        """
            创建 tornado.web.Application
        """
        settings = {
            "static_path"   : app_path(__conf__.STATIC_DIR_NAME),
            "template_path" : app_path(__conf__.TEMPLATE_DIR_NAME),
            "debug"         : __conf__.DEBUG,
            "gzip"          : __conf__.GZIP,
            "login_url"     : __conf__.LOGIN_URL,
            "cookie_secret" : __conf__.COOKIE_SECRET,
            "xsrf_cookies"  : __conf__.XSRF_COOKIES,
        }

        return WebApplication(self._handlers, **settings)
Exemplo n.º 4
0
def _load_handlers(handler_dir='action', member_filter=None):
    '''
        Load handler_dir's Handler
        Demo:
        handlers = load_handlers():
        app = tornado.web.Application(handlers)
    '''
    #path = os.path.join(os.getcwd(), handler_dir)
    path = app_path(handler_dir)
    sys.path.append(os.getcwd())
    py_filter = lambda f: fnmatch(f, '*.py') and not f.startswith('__')

    if not member_filter:
        member_filter = lambda m: isinstance(
            m, type) and hasattr(m, '__urls__') and m.__urls__

    names = [os.path.splitext(n)[0] for n in os.listdir(path) if py_filter(n)]
    modules = [__import__(
        "{0}.{1}".format(handler_dir, n)).__dict__[n] for n in names]

    ret = {}
    for m in modules:
        members = dict(("{0}.{1}".format(
            v.__module__, k), v) for k, v in getmembers(m, member_filter))
        ret.update(members)
    return _sorted_hanlders(ret.values())
Exemplo n.º 5
0
def _load_handlers(handler_dir='action', member_filter=None):
    '''
        Load handler_dir's Handler
        Demo:
        handlers = load_handlers():
        app = tornado.web.Application(handlers)
    '''
    #path = os.path.join(os.getcwd(), handler_dir)
    path = app_path(handler_dir)
    sys.path.append(os.getcwd())
    py_filter = lambda f: fnmatch(f, '*.py') and not f.startswith('__')

    if not member_filter:
        member_filter = lambda m: isinstance(m, type) and hasattr(
            m, '__urls__') and m.__urls__

    names = [os.path.splitext(n)[0] for n in os.listdir(path) if py_filter(n)]
    modules = [
        __import__("{0}.{1}".format(handler_dir, n)).__dict__[n] for n in names
    ]

    ret = {}
    for m in modules:
        members = dict(("{0}.{1}".format(v.__module__, k), v)
                       for k, v in getmembers(m, member_filter))
        ret.update(members)
    return _sorted_hanlders(ret.values())
Exemplo n.º 6
0
def api2markdown(rets):
    ''' api to markdown '''
    header = """
## {0}
模块说明 {1}
### 接口清单
"""

    api_format = """
{0}. [{1}] {2}
```
{3}
```
    """

    doc = ''
    num = 1
    for _doc in rets:
        _header = header.format(_doc['module'].__name__, str(_doc['module'].__doc__).replace('\t',''))
        for api in _doc['apis']:
            pre_url = [ url[0] for url in api['url']]
            _header = _header+api_format.format(num,api['method'].upper(), ','.join(pre_url), str(api['doc']).replace('\t',''))
            num = num +1
        
        doc = doc + _header
    
    
    f = open(app_path('apis.md'),'w')
    f.write(doc)
    f.close()
Exemplo n.º 7
0
    def get_error_html(self, status_code, **kwargs):
        # 
        # 查找错误页面: <status_code>.html,或者返回 error.html。
        # 页面模板可以获取 status_code 值。
        # 
        from os.path import exists
        from utility import app_path

        for name in (status_code, "error"):
            filename = app_path("{0}/{1}.html".format(settings.TEMPLATE, name))
            if exists(filename): return self.render_string(filename, status_code = status_code)

        return "Template file not found! {0}/{1}.html\n".format(settings.TEMPLATE, status_code)
Exemplo n.º 8
0
def _load_api(handler_dir='action', member_filter=None):
    '''
    Load handler's url api 
    '''
    path = app_path(handler_dir)
    sys.path.append(os.getcwd())
    py_filter = lambda f: fnmatch(f, '*.py') and not f.startswith('__')

    if not member_filter:
        member_filter = lambda m: isinstance(
            m, type) and hasattr(m, '__urls__') and m.__urls__

    names = [os.path.splitext(n)[0] for n in os.listdir(path) if py_filter(n)]
    modules = [__import__(
        "{0}.{1}".format(handler_dir, n)).__dict__[n] for n in names]

    mts = ('get','post','put','patch','delete')

    rets = []
    for m in modules:        
        apis = []
        doc = {'module': m, 'apis':apis}

        for k, v in getmembers(m, member_filter):
            
            print(k, v, v.__module__)
            for _method in mts:
                _mt = getattr(v, _method)
                #import pdb;pdb.set_trace()
                #todo if method in private for subclass 
                if _mt and _mt.__doc__:
                    mt_doc = dict(method=_method, url=v.__urls__, doc=_mt.__doc__, func=_mt)
                    apis.append(mt_doc)

        rets.append(doc)
    return rets