本文整理汇总了Python中shimehari.configuration.ConfigManager类的典型用法代码示例。如果您正苦于以下问题:Python ConfigManager类的具体用法?Python ConfigManager怎么用?Python ConfigManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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, {})
示例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)
示例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)
示例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>"')
示例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)
示例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/')
示例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')
示例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)
示例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'))
示例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
示例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)
示例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]
示例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'])
示例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)
示例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)