• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python configuration.ConfigManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中shimehari.configuration.ConfigManager的典型用法代码示例。如果您正苦于以下问题:Python ConfigManager类的具体用法?Python ConfigManager怎么用?Python ConfigManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ConfigManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: testSetControllerFromRouter

 def testSetControllerFromRouter(self):
     ConfigManager.addConfig(testConfig)
     app = shimehari.Shimehari(__name__)
     self.assertEqual(app.controllers, {})
     router = Router([Resource(TestController, root=True)])
     app.setControllerFromRouter(router)
     self.assertNotEqual(app.controllers, {})
开发者ID:Epictetus,项目名称:Shimehari,代码行数:7,代码来源:test_app.py


示例2: testJsoniFy

    def testJsoniFy(self):
        d = dict(a=23, b=42, c=[1, 2, 3])
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)

        #hum
        def returnKwargs():
            return shimehari.jsonify(**d)

        def returnDict():
            return shimehari.jsonify(d)

        app.router = shimehari.Router([
            Rule('/kw', endpoint='returnKwargs', methods=['GET']),
            Rule('/dict', endpoint='returnDict', methods=['GET'])
        ])
        app.controllers['returnKwargs'] = returnKwargs
        app.controllers['returnDict'] = returnDict

        c = app.testClient()
        for url in '/kw', '/dict':
            rv = c.get(url)
            print rv.mimetype
            self.assertEqual(rv.mimetype, 'application/json')
            self.assertEqual(shimehari.json.loads(rv.data), d)
开发者ID:Epictetus,项目名称:Shimehari,代码行数:25,代码来源:test_helpers.py


示例3: testStaticFile

    def testStaticFile(self):
        ConfigManager.removeConfig('development')
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)
        app.setStaticFolder('static')
        with app.testRequestContext():
            rv = app.sendStaticFile('index.html')
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assertEqual(cc.max_age, 12 * 60 * 60)
            rv = shimehari.sendFile(os.path.join(app.rootPath, 'static/index.html'))
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assertEqual(cc.max_age, 12 * 60 * 60)
        app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600
        with app.testRequestContext():
            rv = app.sendStaticFile('index.html')
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assertEqual(cc.max_age, 3600)
            rv = shimehari.sendFile(os.path.join(app.rootPath, 'static/index.html'))
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assertEqual(cc.max_age, 3600)

        class StaticFileApp(shimehari.Shimehari):
            def getSendFileMaxAge(self, filename):
                return 10
        app = StaticFileApp(__name__)
        app.setStaticFolder('static')
        with app.testRequestContext():
            rv = app.sendStaticFile('index.html')
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assertEqual(cc.max_age, 10)
            rv = shimehari.sendFile(os.path.join(app.rootPath, 'static/index.html'))
            cc = parse_cache_control_header(rv.headers['Cache-Control'])
            self.assertEqual(cc.max_age, 10)
开发者ID:glassesfactory,项目名称:Shimehari,代码行数:33,代码来源:test_helpers.py


示例4: testTemplateEscaping

 def testTemplateEscaping(self):
     ConfigManager.addConfig(testConfig)
     app = shimehari.Shimehari(__name__)
     app.setupTemplater()
     render = shimehari.renderTemplateString
     with app.testRequestContext():
         rv = render('{{"</script>"|tojson|safe }}')
         self.assertEqual(rv, '"</script>"')
         rv = render('{{"<\0/script>"|tojson|safe }}')
         self.assertEqual(rv, '"<\\u0000/script>"')
开发者ID:glassesfactory,项目名称:Shimehari,代码行数:10,代码来源:test_helpers.py


示例5: testJSONBadRequests

    def testJSONBadRequests(self):
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)

        def returnJSON(*args, **kwargs):
            return unicode(shimehari.request.json)
        app.router = shimehari.Router([Rule('/json', endpoint='returnJSON', methods=['POST'])])
        app.controllers['returnJSON'] = returnJSON
        c = app.testClient()
        rv = c.post('/json', data='malformed', content_type='application/json')
        self.assertEqual(rv.status_code, 400)
开发者ID:Epictetus,项目名称:Shimehari,代码行数:11,代码来源:test_helpers.py


示例6: testGenerateURL

    def testGenerateURL(self):
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)

        def index(*args, **kwargs):
            return 'index'
        app.router = shimehari.Router([Rule('/', endpoint='index', methods=['GET'])])

        with app.appContext():
            rv = shimehari.urlFor('index')
            self.assertEqual(rv, 'https://localhost/')
开发者ID:Epictetus,项目名称:Shimehari,代码行数:11,代码来源:test_context.py


示例7: testJSONAttr

    def testJSONAttr(self):
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)

        def returnJSON(*args, **kwargs):
            return unicode(shimehari.request.json['a'] + shimehari.request.json['b'])
        app.router = shimehari.Router([Rule('/add', endpoint='returnJSON', methods=['POST'])])
        app.controllers['returnJSON'] = returnJSON

        c = app.testClient()
        rv = c.post('/add', data=shimehari.json.dumps({'a': 1, 'b': 2}), content_type='application/json')
        self.assertEqual(rv.data, '3')
开发者ID:Epictetus,项目名称:Shimehari,代码行数:12,代码来源:test_helpers.py


示例8: testGotFirstRequest

    def testGotFirstRequest(self):
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)
        self.assertEqual(app.gotFirstRequest, False)

        def returnHello(*args, **kwargs):
            return 'Hello'
        app.router = shimehari.Router([Rule('/hell', endpoint='returnHello', methods=['POST'])])
        app.controllers['returnHello'] = returnHello
        c = app.testClient()
        c.get('/hell', content_type='text/planetext')
        self.assert_(app.gotFirstRequest)
开发者ID:Epictetus,项目名称:Shimehari,代码行数:12,代码来源:test_app.py


示例9: jsonBodyEncoding

    def jsonBodyEncoding(self):
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)

        app.testing = True

        def returnJSON(*args, **kwargs):
            return shimehari.request.json
        app.router = shimehari.Router([Rule('/json', endpoint='returnJSON', methods=['GET'])])
        app.controllers['returnJSON'] = returnJSON
        c = app.testClient()
        resp = c.get('/', data=u"はひ".encode('iso-8859-15'), content_type='application/json; charset=iso-8859-15')
        self.assertEqual(resp.data, u'はひ'.encode('utf-8'))
开发者ID:glassesfactory,项目名称:Shimehari,代码行数:13,代码来源:test_helpers.py


示例10: testSetup

 def testSetup(self):
     # ConfigManager.addConfig(testConfig)
     ConfigManager.removeConfig('development')
     ConfigManager.addConfig(Config('development', {'AUTO_SETUP': False, 'SERVER_NAME': 'localhost', 'PREFERRED_URL_SCHEME': 'https'}))
     app = shimehari.Shimehari(__name__)
     app.appPath = os.path.join(app.rootPath, 'testApp')
     app.appFolder = 'shimehari.testsuite.testApp'
     app.setupTemplater()
     app.setupBindController()
     app.setupBindRouter()
     self.assertNotEqual(app.controllers, {})
     self.assertNotEqual(app.router._rules, {})
     pass
开发者ID:Epictetus,项目名称:Shimehari,代码行数:13,代码来源:test_app.py


示例11: testAddRoute

    def testAddRoute(self):
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)
        self.assertEqual(app.controllers, {})
        self.assertEqual(app.router._rules, [])

        def index(*args, **kwargs):
            return 'Sake nomitai.'
        app.addRoute('/', index)
        c = app.testClient()
        rv = c.get('/', content_type='text/html')
        self.assertEqual(rv.status_code, 200)
        self.assert_('Sake nomitai.' in rv.data)
开发者ID:Epictetus,项目名称:Shimehari,代码行数:13,代码来源:test_app.py


示例12: getConfig

 def getConfig(self):
     u"""現在アプリケーションに適用されているコンフィグを返します。"""
     configs = ConfigManager.getConfigs()
     try:
         # from .config import config
         configs = ConfigManager.getConfigs()
     except ImportError:
         pass
     if not configs:
         cfg = Config(self.currentEnv, self.defaultConfig)
         ConfigManager.addConfig(cfg)
         return cfg
     else:
         return configs[self.currentEnv]
开发者ID:Epictetus,项目名称:Shimehari,代码行数:14,代码来源:app.py


示例13: testJSONBadRequestsContentType

    def testJSONBadRequestsContentType(self):
        ConfigManager.addConfig(testConfig)
        app = shimehari.Shimehari(__name__)

        @csrfExempt
        def returnJSON(*args, **kwargs):
            return unicode(shimehari.request.json)
        app.router = shimehari.Router([Rule('/json', endpoint='returnJSON', methods=['POST'])])
        app.controllers['returnJSON'] = returnJSON
        c = app.testClient()
        rv = c.post('/json', data='malformed', content_type='application/json')
        self.assertEqual(rv.status_code, 400)
        self.assertEqual(rv.mimetype, 'application/json')
        self.assert_('description' in shimehari.json.loads(rv.data))
        self.assert_('<p>' not in shimehari.json.loads(rv.data)['description'])
开发者ID:glassesfactory,项目名称:Shimehari,代码行数:15,代码来源:test_helpers.py


示例14: csrfProtect

    def csrfProtect(self, requestToken=None):
        if shared._csrfExempt:
            return

        if not request.method in ['POST', 'PUT', 'PATCH', 'DELETE']:
            return

        sessionToken = session.get('_csrfToken', None)
        if not sessionToken:
            # CSRF token missing
            abort(403)

        config = ConfigManager.getConfig()
        secretKey = config['SECRET_KEY']

        hmacCompare = hmac.new(secretKey, str(sessionToken).encode('utf-8'), digestmod=sha1)
        token = requestToken if requestToken is not None else request.form.get('_csrfToken')

        if hmacCompare.hexdigest() != token:
            # invalid CSRF token
            if self.csrfHandler:
                self.csrfHandler(*self.app.matchRequest())
            else:
                abort(403)

        if not self.checkCSRFExpire(token):
            # CSRF token expired
            abort(403)
开发者ID:glassesfactory,项目名称:Shimehari,代码行数:28,代码来源:crypt.py


示例15: handle

    def handle(self, moduleType, name, *args, **options):
        if not moduleType == 'controller':
            raise CommandError('ない')

        path = options.get('path')
        if path is None:
            currentPath = os.getcwd()
            try:
                importFromString('config')
            except:
                sys.path.append(os.getcwd())
                try:
                    importFromString('config')
                except ImportError:
                    raise CommandError('config file is not found...')
            config = ConfigManager.getConfig(getEnviron())
            path = os.path.join(currentPath, config['APP_DIRECTORY'], config['CONTROLLER_DIRECTORY'])

        if not os.path.isdir(path):
            raise CommandError('Given path is invalid')

        ctrlTemplate = os.path.join(shimehari.__path__[0], 'core', 'conf', 'controller_template.org.py')

        name, filename = self.filenameValidation(path, name)
        newPath = os.path.join(path, filename)

        self.readAndCreateFileWithRename(ctrlTemplate, newPath, name)
开发者ID:Epictetus,项目名称:Shimehari,代码行数:27,代码来源:generate.py


示例16: run

    def run(self, *args, **options):
        import config

        # try:
        #     #humu-
        #     import config
        # except ImportError, e:
        #     sys.path.append(os.getcwd())
        #     try:
        #         import config
        #     except ImportError, e:
        #         t = sys.exc_info()[2]
        #         raise DrinkError(u'ちょっと頑張ったけどやっぱりコンフィグが見当たりません。\n%s' % e), None, traceback.print_exc(t)

        try:
            currentEnv = options.get('SHIMEHARI_ENV')
            currentConfig = ConfigManager.getConfig(currentEnv or 'development')
            app = importFromString( currentConfig['MAIN_SCRIPT'] + '.' + currentConfig['APP_INSTANCE_NAME'])

            if options.get('browser'):
                timer = threading.Timer(0.5, self.openBrowser, args=[self.host, self.port])
                timer.start()

            app.run(host=self.host, port=int(self.port), debug=True)

        except:
            raise
开发者ID:matsumos,项目名称:toodooo,代码行数:27,代码来源:ds.py


示例17: get

 def get(self, sid):
     if not self.is_valid_key(sid):
         return self.new()
     config = ConfigManager.getConfig()
     secretKey = config['SECRET_KEY']
     if secretKey is not None:
         return self.session_class.load_cookie(request, key=self.key, secret_key=secretKey, sid=sid)
开发者ID:glassesfactory,项目名称:Shimehari,代码行数:7,代码来源:session.py


示例18: __init__

    def __init__(self, storetype=None):
        config = ConfigManager.getConfig(getEnviron())

        if config['CACHE_STORE'] is not None:
            store = config['CACHE_STORE']
        else:
            store = storetype

        self.store = self._importCacheStore(store)
开发者ID:Epictetus,项目名称:Shimehari,代码行数:9,代码来源:cache.py


示例19: _importCacheStore

 def _importCacheStore(self, storetype):
     if storetype == 'simple':
         return SimpleCacheStore()
     if storetype == 'memcache':
         return MemcachedCacheStore()
     if storetype == 'file':
         config = ConfigManager.getConfig(getEnviron())
         return FileSystemCacheStore(cacheDir=config['CACHE_DIR'])
     if storetype == 'redis':
         return RedisCacheStore()
     return NullCacheStore()
开发者ID:Epictetus,项目名称:Shimehari,代码行数:11,代码来源:cache.py


示例20: generateCSRFToken

def generateCSRFToken():
    if not '_csrfToken' in session:
        session['_csrfToken'] = genereateToken()

    now = datetime.datetime.now() + datetime.timedelta()
    session['_csrfTokenAdded'] = time.mktime(now.timetuple())

    config = ConfigManager.getConfig()
    secretKey = config['SECRET_KEY']

    hmacCsrf = hmac.new(secretKey, str(session['_csrfToken']).encode('utf-8'), digestmod=sha1)
    return hmacCsrf.hexdigest()
开发者ID:glassesfactory,项目名称:Shimehari,代码行数:12,代码来源:crypt.py



注:本文中的shimehari.configuration.ConfigManager类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python action.Action类代码示例发布时间:2022-05-27
下一篇:
Python testutil.DummyRequest类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap