本文整理汇总了Python中shimehari.configuration.ConfigManager.getConfig方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigManager.getConfig方法的具体用法?Python ConfigManager.getConfig怎么用?Python ConfigManager.getConfig使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shimehari.configuration.ConfigManager
的用法示例。
在下文中一共展示了ConfigManager.getConfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: csrfProtect
# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import getConfig [as 别名]
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)
示例2: get
# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import getConfig [as 别名]
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)
示例3: handle
# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import getConfig [as 别名]
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)
示例4: run
# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import getConfig [as 别名]
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
示例5: __init__
# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import getConfig [as 别名]
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)
示例6: _importCacheStore
# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import getConfig [as 别名]
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()
示例7: generateCSRFToken
# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import getConfig [as 别名]
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()
示例8: handle
# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import getConfig [as 别名]
def handle(self, *args, **options):
try:
importFromString('config')
except ImportError:
sys.path.append(os.getcwd())
try:
importFromString('config')
except ImportError:
raise CommandError(u'コンフィグファイルが見当たりません')
env = options.get('env')
if env is None:
env = 'development'
sys.stdout.write('\nYour Shimehari App Current Config.\n\n')
sys.stdout.write('-------------------------------------------------\n')
sys.stdout.write(ConfigManager.getConfig(env).dump())
sys.stdout.write('\n')
示例9: __init__
# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import getConfig [as 别名]
def __init__(self, importName, appFolder='app',
controllerFolder='controllers', viewFolder=None):
self.importName = importName
self.currentEnv = getEnviron()
self.rootPath = getRootPath(self.importName)
from shimehari.configuration import ConfigManager
config = ConfigManager.getConfig(self.currentEnv)
if config and self.rootPath == os.getcwd() + '/' + config['APP_DIRECTORY']:
self.rootPath = os.getcwd()
self.appFolder = config['APP_DIRECTORY'] if config and config['APP_DIRECTORY'] else appFolder
self.controllerFolder = config['CONTROLLER_DIRECTORY'] if config and \
config['CONTROLLER_DIRECTORY'] else controllerFolder
self.viewFolder = config['VIEW_DIRECTORY'] if config and config['VIEW_DIRECTORY'] else viewFolder
self._staticFolders = {}
if config and config['ASSETS_DIRECTORY']:
assetsDir = config['ASSETS_DIRECTORY']
if type(assetsDir) is list:
[self._staticFolders.setdefault(x, x) for x in assetsDir]
else:
self._staticFolders = {assetsDir: assetsDir}
if config and config['STATIC_DIRECTORY']:
staticDir = config['STATIC_DIRECTORY']
if isinstance(staticDir, (list, tuple)):
[self._staticFolders.setdefault(x, x) for x in staticDir]
elif isinstance(staticDir, dict):
self._staticFolders.update(staticDir)
else:
self._staticFolders.setdefault(staticDir, staticDir)
self._staticURLDict = {}
def _assetsURL(self):
if config['ASSETS_DIRECTORY'] in self._staticFolders:
return self.getStaticURL(config['ASSETS_DIRECTORY'])
else:
return None
self.assetsURL = property(_assetsURL)
del _assetsURL
示例10: __init__
# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import getConfig [as 别名]
def __init__(self, importName, appFolder='app',
controllerFolder='controllers', viewFolder=None):
self.importName = importName
self.currentEnv = getEnviron()
self.rootPath = getRootPath(self.importName)
from shimehari.configuration import ConfigManager
config = ConfigManager.getConfig(self.currentEnv)
if config and self.rootPath == os.getcwd() + '/' + config['APP_DIRECTORY']:
self.rootPath = os.getcwd()
self.appFolder = config['APP_DIRECTORY'] if config and config['APP_DIRECTORY'] else appFolder
self.controllerFolder = config['CONTROLLER_DIRECTORY'] if config and \
config['CONTROLLER_DIRECTORY'] else controllerFolder
self.viewFolder = config['VIEW_DIRECTORY'] if config and config['VIEW_DIRECTORY'] else viewFolder
self._staticFolder = config['ASSETS_DIRECTORY'] if config and config['ASSETS_DIRECTORY'] else None
self._staticURL = None
示例11: createLogger
# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import getConfig [as 别名]
def createLogger(loggerName='shimehariLoagger'):
Logger = getLoggerClass()
class DebugLogger(Logger):
def getEffectiveLevel(x):
if x.level == 0 and config['DEBUG']:
return DEBUG
return Logger.getEffectiveLevel(x)
class DebugHandler(StreamHandler):
def emit(x, record):
StreamHandler.emit(x, record) if config['DEBUG'] else None
config = ConfigManager.getConfig(getEnviron())
if config['LOG_FILE_OUTPUT']:
fn = os.path.join(config['LOG_FILE_DIRECTORY'], getEnviron()) + '.log'
if config['LOG_FILE_ROTATE']:
from logging import RotateFileHandler
handler = RotateFileHandler(fn, 'a', config['LOG_ROTATE_MAX_BITE'], config['LOG_ROTATE_COUNT'])
else:
from logging import FileHandler
handler = FileHandler(fn, 'a')
handler.setFormatter(Formatter(config['LOG_OUTPUT_FORMAT']))
logger = getLogger()
else:
handler = DebugHandler()
handler.setFormatter(Formatter(config['LOG_DEBUG_FORMAT']))
logger = getLogger(loggerName)
logger.setLevel(DEBUG)
del logger.handlers[:]
logger.__class__ = DebugLogger
logger.addHandler(handler)
return logger
示例12: new
# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import getConfig [as 别名]
def new(self):
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)
示例13: getCookieExpire
# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import getConfig [as 别名]
def getCookieExpire(self, session):
if session.permanent:
return datetime.utcnow() + ConfigManager.getConfig()['PERMANENT_SESSION_LIFETIME']
示例14: getCookieSecure
# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import getConfig [as 别名]
def getCookieSecure(self):
return ConfigManager.getConfig()['SESSION_COOKIE_SECURE']
示例15: getCookieHttpOnly
# 需要导入模块: from shimehari.configuration import ConfigManager [as 别名]
# 或者: from shimehari.configuration.ConfigManager import getConfig [as 别名]
def getCookieHttpOnly(self):
return ConfigManager.getConfig()['SESSION_COOKIE_HTTPONLY']