Пример #1
0
def test_group():
    assert list(utils.group([], 2)) == []
    assert list(utils.group([1, 2, 3, 4, 5, 6, 7, 8, 9], 3)) == [[1, 2, 3],
                                                                 [4, 5, 6],
                                                                 [7, 8, 9]]
    assert list(utils.group([1, 2, 3, 4, 5, 6, 7, 8, 9], 4)) == [[1, 2, 3, 4],
                                                                 [5, 6, 7, 8],
                                                                 [9]]
Пример #2
0
 def __mapping(self):
     from . import handlers
     url_captcha = self.config.url_captcha + '/?$'
     url_login = self.config.url_login + '/?$'
     url_logout = self.config.url_logout + '/?$'
     url_reset_token = self.config.url_reset_token + '/?$'
     url_reset_change = (self.config.url_reset_change +
                         '/(?P<uid>[0-9]+)\$(?P<token>[0-9a-z\$\.]+)/?$')
     urls_mapping = (url_login, handlers.Login, url_captcha,
                     handlers.Captcha, url_logout, handlers.Logout,
                     url_reset_token, handlers.ResetToken, url_reset_change,
                     handlers.ResetChange)
     self.app.mapping.extend(list(utils.group(urls_mapping, 2)))
     return
Пример #3
0
 def __mapping(self):
     from . import handlers
     url_captcha = self.config.url_captcha + '/?$'
     url_login = self.config.url_login + '/?$'
     url_logout = self.config.url_logout + '/?$'
     url_reset_token = self.config.url_reset_token + '/?$'
     url_reset_change = (self.config.url_reset_change +
                         '/(?P<uid>[0-9]+)\$(?P<token>[0-9a-z\$\.]+)/?$')
     urls_mapping = (
         url_login, handlers.Login,
         url_captcha, handlers.Captcha,
         url_logout, handlers.Logout,
         url_reset_token, handlers.ResetToken,
         url_reset_change, handlers.ResetChange
     )
     self.app.mapping.extend(list(utils.group(urls_mapping, 2)))
     return
Пример #4
0
 def GET(self, ctrl=None):
     data = web.input()
     if data.get('key') != 'hbible':
         raise web.seeother('/')
     
     apidoc = []
     controllers = []
     for f in os.listdir(os.path.split(__file__)[0]):
         module_name, ext = os.path.splitext(f)
         if not module_name.startswith('__') and ext == '.py':
             controllers.append(module_name)
     ctrl = 'controller.' + ctrl if ctrl in controllers else None
     
     for router in list(utils.group(urls.urls, 2)):
         url = router[0]
         controller = router[1]
         dot = controller.rfind('.')
         modulename = controller[:dot]
         name = controller[dot + 1:]
         
         if ctrl and ctrl != modulename:continue
         controlClass = base.importName(modulename, name)
         doc = controlClass.__doc__
         api = {
                'url':url,
                'controller':controller,
                'doc':''
                }
         if doc:
             docs = doc.split('\n')
             method = ''
             for d in docs:
                 d = d.strip()
                 if d.startswith('GET'):
                     method = 'get'
                     api['getargs'] = d[3:]
                     api['getdoc'] = ''
                 elif d.startswith('POST'):
                     method = 'post'
                     api['postargs'] = d[4:]
                     api['postdoc'] = ''
                 elif d != '':
                     api[method + 'doc'] += d + '<br/>'
         apidoc.append(api)
     return render.apidoc(apidoc=apidoc, controllers=controllers, ctrl=ctrl[ctrl.find('.') + 1:] if ctrl else None)
Пример #5
0
 def init_mapping(self, mapping):
     self.mapping = [(r"(/@[a-f0-9A-F_]*@)?" + a, b)
                     for a, b in utils.group(mapping, 2)]
Пример #6
0
def test_group():
    assert list(utils.group([], 2)) == []
    assert list(utils.group([1, 2, 3, 4, 5, 6, 7, 8, 9], 3)) == [[1, 2, 3], [4, 5, 6], [7, 8, 9]]    
    assert list(utils.group([1, 2, 3, 4, 5, 6, 7, 8, 9], 4)) == [[1, 2, 3, 4], [5, 6, 7, 8], [9]]