本文整理汇总了Python中dal.BaseAdapter.close_all_instances方法的典型用法代码示例。如果您正苦于以下问题:Python BaseAdapter.close_all_instances方法的具体用法?Python BaseAdapter.close_all_instances怎么用?Python BaseAdapter.close_all_instances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dal.BaseAdapter
的用法示例。
在下文中一共展示了BaseAdapter.close_all_instances方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wsgibase
# 需要导入模块: from dal import BaseAdapter [as 别名]
# 或者: from dal.BaseAdapter import close_all_instances [as 别名]
#.........这里部分代码省略.........
lambda *a: middleware_aux(request, response, *a)
# ##################################################
# load cookies
# ##################################################
if env.http_cookie:
try:
request.cookies.load(env.http_cookie)
except Cookie.CookieError, e:
pass # invalid cookies
# ##################################################
# try load session or create new session file
# ##################################################
if not env.web2py_disable_session:
session.connect(request, response)
# ##################################################
# run controller
# ##################################################
if global_settings.debugging and app != "admin":
import gluon.debug
# activate the debugger
gluon.debug.dbg.do_debug(mainpyfile=request.folder)
serve_controller(request, response, session)
except HTTP, http_response:
if static_file:
return http_response.to(responder, env=env)
if request.body:
request.body.close()
# ##################################################
# on success, try store session in database
# ##################################################
session._try_store_in_db(request, response)
# ##################################################
# on success, commit database
# ##################################################
if response.do_not_commit is True:
BaseAdapter.close_all_instances(None)
# elif response._custom_commit:
# response._custom_commit()
elif response.custom_commit:
BaseAdapter.close_all_instances(response.custom_commit)
else:
BaseAdapter.close_all_instances('commit')
# ##################################################
# if session not in db try store session on filesystem
# this must be done after trying to commit database!
# ##################################################
session._try_store_in_cookie_or_file(request, response)
if request.cid:
if response.flash:
http_response.headers['web2py-component-flash'] = urllib2.quote(xmlescape(response.flash).replace('\n', ''))
if response.js:
http_response.headers['web2py-component-command'] = response.js.replace('\n', '')
# ##################################################
# store cookies in headers
# ##################################################
rcookies = response.cookies
if session._forget and response.session_id_name in rcookies:
del rcookies[response.session_id_name]
elif session._secure:
rcookies[response.session_id_name]['secure'] = True
http_response.cookies2headers(rcookies)
ticket = None
except RestrictedError, e:
if request.body:
request.body.close()
# ##################################################
# on application error, rollback database
# ##################################################
ticket = e.log(request) or 'unknown'
if response._custom_rollback:
response._custom_rollback()
else:
BaseAdapter.close_all_instances('rollback')
http_response = \
HTTP(500, rwthread.routes.error_message_ticket %
dict(ticket=ticket),
web2py_error='ticket %s' % ticket)
示例2: run
# 需要导入模块: from dal import BaseAdapter [as 别名]
# 或者: from dal.BaseAdapter import close_all_instances [as 别名]
def run(
appname,
plain=False,
import_models=False,
startfile=None,
bpython=False,
python_code=False,
cronjob=False):
"""
Start interactive shell or run Python script (startfile) in web2py
controller environment. appname is formatted like:
a web2py application name
a/c exec the controller c into the application environment
"""
(a, c, f, args, vars) = parse_path_info(appname, av=True)
errmsg = 'invalid application name: %s' % appname
if not a:
die(errmsg)
adir = os.path.join('applications', a)
if not os.path.exists(adir):
if sys.stdin and not sys.stdin.name == '/dev/null':
confirm = raw_input(
'application %s does not exist, create (y/n)?' % a)
else:
logging.warn('application does not exist and will not be created')
return
if confirm.lower() in ['y', 'yes']:
os.mkdir(adir)
w2p_unpack('welcome.w2p', adir)
for subfolder in ['models', 'views', 'controllers', 'databases',
'modules', 'cron', 'errors', 'sessions',
'languages', 'static', 'private', 'uploads']:
subpath = os.path.join(adir, subfolder)
if not os.path.exists(subpath):
os.mkdir(subpath)
db = os.path.join(adir, 'models/db.py')
if os.path.exists(db):
data = fileutils.read_file(db)
data = data.replace(
'<your secret key>', 'sha512:' + web2py_uuid())
fileutils.write_file(db, data)
if c:
import_models = True
extra_request = {}
if args:
extra_request['args'] = args
if vars:
extra_request['vars'] = vars
_env = env(a, c=c, f=f, import_models=import_models, extra_request=extra_request)
if c:
pyfile = os.path.join('applications', a, 'controllers', c + '.py')
pycfile = os.path.join('applications', a, 'compiled',
"controllers_%s_%s.pyc" % (c, f))
if ((cronjob and os.path.isfile(pycfile))
or not os.path.isfile(pyfile)):
exec read_pyc(pycfile) in _env
elif os.path.isfile(pyfile):
execfile(pyfile, _env)
else:
die(errmsg)
if f:
exec ('print %s()' % f, _env)
return
_env.update(exec_pythonrc())
if startfile:
try:
ccode = None
if startfile.endswith('.pyc'):
ccode = read_pyc(startfile)
exec ccode in _env
else:
execfile(startfile, _env)
if import_models:
BaseAdapter.close_all_instances('commit')
except Exception, e:
print traceback.format_exc()
if import_models:
BaseAdapter.close_all_instances('rollback')
示例3: exec
# 需要导入模块: from dal import BaseAdapter [as 别名]
# 或者: from dal.BaseAdapter import close_all_instances [as 别名]
if f:
exec ('print %s()' % f, _env)
elif startfile:
exec_pythonrc()
try:
execfile(startfile, _env)
if import_models: BaseAdapter.close_all_instances('commit')
except Exception, e:
print traceback.format_exc()
if import_models: BaseAdapter.close_all_instances('rollback')
elif python_code:
exec_pythonrc()
try:
exec(python_code, _env)
if import_models: BaseAdapter.close_all_instances('commit')
except Exception, e:
print traceback.format_exc()
if import_models: BaseAdapter.close_all_instances('rollback')
else:
if not plain:
if bpython:
try:
import bpython
bpython.embed(locals_=_env)
return
except:
logger.warning(
'import bpython error; trying ipython...')
else:
try:
示例4: run
# 需要导入模块: from dal import BaseAdapter [as 别名]
# 或者: from dal.BaseAdapter import close_all_instances [as 别名]
def run(
appname,
plain=False,
import_models=False,
startfile=None,
bpython=False,
python_code=False
):
"""
Start interactive shell or run Python script (startfile) in web2py
controller environment. appname is formatted like:
a web2py application name
a/c exec the controller c into the application environment
"""
(a, c, f) = parse_path_info(appname)
errmsg = 'invalid application name: %s' % appname
if not a:
die(errmsg)
adir = os.path.join('applications', a)
if not os.path.exists(adir):
if raw_input('application %s does not exist, create (y/n)?'
% a).lower() in ['y', 'yes']:
os.mkdir(adir)
w2p_unpack('welcome.w2p', adir)
for subfolder in ['models','views','controllers', 'databases',
'modules','cron','errors','sessions',
'languages','static','private','uploads']:
subpath = os.path.join(adir,subfolder)
if not os.path.exists(subpath):
os.mkdir(subpath)
db = os.path.join(adir,'models/db.py')
if os.path.exists(db):
data = fileutils.read_file(db)
data = data.replace('<your secret key>','sha512:'+web2py_uuid())
fileutils.write_file(db, data)
if c:
import_models = True
_env = env(a, c=c, import_models=import_models)
if c:
cfile = os.path.join('applications', a, 'controllers', c + '.py')
if not os.path.isfile(cfile):
cfile = os.path.join('applications', a, 'compiled', "controllers_%s_%s.pyc" % (c,f))
if not os.path.isfile(cfile):
die(errmsg)
else:
exec read_pyc(cfile) in _env
else:
execfile(cfile, _env)
if f:
exec ('print %s()' % f, _env)
elif startfile:
exec_pythonrc()
try:
execfile(startfile, _env)
if import_models: BaseAdapter.close_all_instances('commit')
except Exception, e:
print traceback.format_exc()
if import_models: BaseAdapter.close_all_instances('rollback')
示例5: wsgibase
# 需要导入模块: from dal import BaseAdapter [as 别名]
# 或者: from dal.BaseAdapter import close_all_instances [as 别名]
#.........这里部分代码省略.........
# ##################################################
# load cookies
# ##################################################
if request.env.http_cookie:
try:
request.cookies.load(request.env.http_cookie)
except Cookie.CookieError, e:
pass # invalid cookies
# ##################################################
# try load session or create new session file
# ##################################################
session.connect(request, response)
# ##################################################
# set no-cache headers
# ##################################################
response.headers['Content-Type'] = contenttype('.'+request.extension)
response.headers['Cache-Control'] = \
'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
response.headers['Expires'] = \
time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime())
response.headers['Pragma'] = 'no-cache'
# ##################################################
# run controller
# ##################################################
serve_controller(request, response, session)
except HTTP, http_response:
if static_file:
return http_response.to(responder)
if request.body:
request.body.close()
# ##################################################
# on success, try store session in database
# ##################################################
session._try_store_in_db(request, response)
# ##################################################
# on success, commit database
# ##################################################
if response._custom_commit:
response._custom_commit()
else:
BaseAdapter.close_all_instances('commit')
# ##################################################
# if session not in db try store session on filesystem
# this must be done after trying to commit database!
# ##################################################
session._try_store_on_disk(request, response)
# ##################################################
# store cookies in headers
# ##################################################
if request.cid:
if response.flash and not 'web2py-component-flash' in http_response.headers:
http_response.headers['web2py-component-flash'] = \
str(response.flash).replace('\n','')
if response.js and not 'web2py-component-command' in http_response.headers:
http_response.headers['web2py-component-command'] = \
str(response.js).replace('\n','')
if session._forget:
del response.cookies[response.session_id_name]
elif session._secure:
response.cookies[response.session_id_name]['secure'] = True
if len(response.cookies)>0:
http_response.headers['Set-Cookie'] = \
[str(cookie)[11:] for cookie in response.cookies.values()]
ticket=None
except RestrictedError, e:
if request.body:
request.body.close()
# ##################################################
# on application error, rollback database
# ##################################################
ticket = e.log(request) or 'unknown'
if response._custom_rollback:
response._custom_rollback()
else:
BaseAdapter.close_all_instances('rollback')
http_response = \
HTTP(500,
rewrite.thread.routes.error_message_ticket % dict(ticket=ticket),
web2py_error='ticket %s' % ticket)
示例6: RestrictedError
# 需要导入模块: from dal import BaseAdapter [as 别名]
# 或者: from dal.BaseAdapter import close_all_instances [as 别名]
)
except:
if request.body:
request.body.close()
# ##################################################
# on application error, rollback database
# ##################################################
try:
if response._custom_rollback:
response._custom_rollback()
else:
BaseAdapter.close_all_instances("rollback")
except:
pass
e = RestrictedError("Framework", "", "", locals())
ticket = e.log(request) or "unrecoverable"
http_response = HTTP(
500, rwthread.routes.error_message_ticket % dict(ticket=ticket), web2py_error="ticket %s" % ticket
)
finally:
if response and hasattr(response, "session_file") and response.session_file:
response.session_file.close()
session._unlock(response)
http_response, new_environ = try_rewrite_on_error(http_response, request, environ, ticket)
if not http_response:
示例7: run
# 需要导入模块: from dal import BaseAdapter [as 别名]
# 或者: from dal.BaseAdapter import close_all_instances [as 别名]
def run(appname, plain=False, import_models=False, startfile=None, bpython=False, python_code=False):
"""
Start interactive shell or run Python script (startfile) in web2py
controller environment. appname is formatted like:
a web2py application name
a/c exec the controller c into the application environment
"""
(a, c, f) = parse_path_info(appname)
errmsg = "invalid application name: %s" % appname
if not a:
die(errmsg)
adir = os.path.join("applications", a)
if not os.path.exists(adir):
if raw_input("application %s does not exist, create (y/n)?" % a).lower() in ["y", "yes"]:
os.mkdir(adir)
w2p_unpack("welcome.w2p", adir)
for subfolder in [
"models",
"views",
"controllers",
"databases",
"modules",
"cron",
"errors",
"sessions",
"languages",
"static",
"private",
"uploads",
]:
subpath = os.path.join(adir, subfolder)
if not os.path.exists(subpath):
os.mkdir(subpath)
db = os.path.join(adir, "models/db.py")
if os.path.exists(db):
data = fileutils.read_file(db)
data = data.replace("<your secret key>", "sha512:" + web2py_uuid())
fileutils.write_file(db, data)
if c:
import_models = True
_env = env(a, c=c, f=f, import_models=import_models)
if c:
cfile = os.path.join("applications", a, "controllers", c + ".py")
if not os.path.isfile(cfile):
cfile = os.path.join("applications", a, "compiled", "controllers_%s_%s.pyc" % (c, f))
if not os.path.isfile(cfile):
die(errmsg)
else:
exec read_pyc(cfile) in _env
else:
execfile(cfile, _env)
if f:
exec ("print %s()" % f, _env)
return
# "woodoo magic" workaround: reinitialize main.py
g = {}
exec "import main" in g
del g
_env.update(exec_pythonrc())
if startfile:
try:
execfile(startfile, _env)
if import_models:
BaseAdapter.close_all_instances("commit")
except Exception, e:
print traceback.format_exc()
if import_models:
BaseAdapter.close_all_instances("rollback")
示例8: wsgibase
# 需要导入模块: from dal import BaseAdapter [as 别名]
# 或者: from dal.BaseAdapter import close_all_instances [as 别名]
#.........这里部分代码省略.........
# ##################################################
# load cookies
# ##################################################
if env.http_cookie:
try:
request.cookies.load(env.http_cookie)
except Cookie.CookieError, e:
pass # invalid cookies
# ##################################################
# try load session or create new session file
# ##################################################
if not env.web2py_disable_session:
session.connect(request, response)
# ##################################################
# run controller
# ##################################################
if global_settings.debugging and app != "admin":
import gluon.debug
# activate the debugger
gluon.debug.dbg.do_debug(mainpyfile=request.folder)
serve_controller(request, response, session)
except HTTP, http_response:
if static_file:
return http_response.to(responder, env=env)
if request.body:
request.body.close()
# ##################################################
# on success, try store session in database
# ##################################################
session._try_store_in_db(request, response)
# ##################################################
# on success, commit database
# ##################################################
if response.do_not_commit is True:
BaseAdapter.close_all_instances(None)
# elif response._custom_commit:
# response._custom_commit()
elif response.custom_commit:
BaseAdapter.close_all_instances(response.custom_commit)
else:
BaseAdapter.close_all_instances("commit")
# ##################################################
# if session not in db try store session on filesystem
# this must be done after trying to commit database!
# ##################################################
session._try_store_on_disk(request, response)
if request.cid:
if response.flash:
http_response.headers["web2py-component-flash"] = urllib2.quote(
xmlescape(response.flash).replace("\n", "")
)
if response.js:
http_response.headers["web2py-component-command"] = response.js.replace("\n", "")
# ##################################################
# store cookies in headers
# ##################################################
rcookies = response.cookies
if session._forget and response.session_id_name in rcookies:
del rcookies[response.session_id_name]
elif session._secure:
rcookies[response.session_id_name]["secure"] = True
http_response.cookies2headers(rcookies)
ticket = None
except RestrictedError, e:
if request.body:
request.body.close()
# ##################################################
# on application error, rollback database
# ##################################################
ticket = e.log(request) or "unknown"
if response._custom_rollback:
response._custom_rollback()
else:
BaseAdapter.close_all_instances("rollback")
http_response = HTTP(
500, rwthread.routes.error_message_ticket % dict(ticket=ticket), web2py_error="ticket %s" % ticket
)