本文整理汇总了Python中pyasm.security.Site.get方法的典型用法代码示例。如果您正苦于以下问题:Python Site.get方法的具体用法?Python Site.get怎么用?Python Site.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyasm.security.Site
的用法示例。
在下文中一共展示了Site.get方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_site_root
# 需要导入模块: from pyasm.security import Site [as 别名]
# 或者: from pyasm.security.Site import get [as 别名]
def get_site_root(self):
from pyasm.security import Site
site = Site.get().get_site_root()
if site:
return site
return "tactic"
示例2: get_default_project
# 需要导入模块: from pyasm.security import Site [as 别名]
# 或者: from pyasm.security.Site import get [as 别名]
def get_default_project(cls):
from pyasm.security import Site
project = Site.get().get_default_project()
if project:
return project
project = Config.get_value("install", "default_project")
return project
示例3: get_asset_dir
# 需要导入模块: from pyasm.security import Site [as 别名]
# 或者: from pyasm.security.Site import get [as 别名]
def get_asset_dir(cls, file_object=None, alias=None):
'''get base asset directory'''
if file_object:
alias = file_object.get_value('base_dir_alias')
if not alias:
alias = "default"
from pyasm.security import Site
asset_dir = Site.get().get_asset_dir(file_object=file_object,alias=alias)
if asset_dir:
return asset_dir
alias_dict = cls.get_asset_dirs()
asset_dir = alias_dict.get(alias)
if not asset_dir:
data_dir = Environment.get_data_dir()
if data_dir:
asset_dir = "%s/assets" % data_dir
return asset_dir
示例4: execute
# 需要导入模块: from pyasm.security import Site [as 别名]
# 或者: from pyasm.security.Site import get [as 别名]
def execute(self):
if not self.login_name:
self.login_name = self.kwargs.get('login');
# invalidate the ticket
security = Environment.get_security()
ticket = security.get_ticket()
if ticket == None:
return
login_name = ticket.get_value("login")
print "Signing out: ", login_name
# expire the ticket
from pyasm.security import Site
site = Site.get()
if site:
Site.set_site("default")
try:
from pyasm.search import Sql, DbContainer
sql = DbContainer.get("sthpw")
ticket.set_value("expiry", sql.get_timestamp_now(), quoted=False)
ticket.commit()
except:
if site:
Site.pop_site()
示例5: get_display
# 需要导入模块: from pyasm.security import Site [as 别名]
# 或者: from pyasm.security.Site import get [as 别名]
def get_display(self):
web = WebContainer.get_web()
response = web.get_response()
# get info from url
site_obj = Site.get()
path = web.get_request_path()
path_info = site_obj.break_up_request_path(path)
site = path_info.get("site")
project_code = path_info.get("project_code")
# find the relative path
hash = self.kwargs.get("hash")
parts = hash[1:]
rel_path = "/".join(parts)
#rel_path = "asset/Fantasy/Castle/54d45150c61251f65687d716cc3951f1_v001.jpg"
# construct all of the paths
asset_dir = web.get_asset_dir()
base_dir = "%s/%s" % (asset_dir, project_code)
path = "%s/%s" % (base_dir, rel_path)
filename = os.path.basename(rel_path)
print "path: ", path
# determine the mimetype automatically
import mimetypes
base, ext = os.path.splitext(path)
ext = ext.lower()
mimetype = mimetypes.types_map[ext]
headers = response.headers
response.headers['Content-Type'] = mimetype
response.headers['Content-Disposition'] = 'inline; filename={0}'.format(filename)
use_xsendfile = True
if use_xsendfile:
response.headers['X-Sendfile'] = path
return Widget(path)
else:
response.headers['Content-Transfer-Encoding'] = 'BINARY'
widget = Widget()
f = open(path, 'rb')
data = f.read()
f.close()
widget.add(data)
return widget
示例6: error_page
# 需要导入模块: from pyasm.security import Site [as 别名]
# 或者: from pyasm.security.Site import get [as 别名]
def error_page(my, status, message, traceback, version):
# check if this project exists
response = cherrypy.response
request = cherrypy.request
path = request.path_info
parts = path.split("/")
if len(parts) < 3:
cherrypy.response.body = '<meta http-equiv="refresh" content="0;url=/tactic" />'
return
from pyasm.security import Site
site_obj = Site.get()
path_info = site_obj.break_up_request_path(path)
if path_info:
site = path_info['site']
project_code = path_info['project_code']
else:
project_code = parts[2]
site = ""
# sites is already mapped in config for cherrypy
if site == "plugins":
return
print "WARNING:"
print " status: ", status
print " message: ", message
print " site: ", site
print " project_code: ", project_code
# Dump out the error
has_site = False
try:
from pyasm.security import TacticInit
TacticInit()
Site.set_site(site)
if site:
eval("cherrypy.root.tactic.%s.%s" % (site, project_code))
else:
eval("cherrypy.root.tactic.%s" % project_code)
# if project_code is empty , it raises SyntaxError
except (AttributeError, SyntaxError), e:
print "WARNING: ", e
has_project = False
has_site = True
示例7: index
# 需要导入模块: from pyasm.security import Site [as 别名]
# 或者: from pyasm.security.Site import get [as 别名]
def index(my):
# check if this project exists
response = cherrypy.response
request = cherrypy.request
path = request.path_info
from pyasm.security import Site
default_project = Site.get().get_default_project()
if not default_project:
default_project = "admin"
path = path.rstrip("/")
path = "%s/%s" % (path, default_project)
return '''<META http-equiv="refresh" content="0;URL=%s">''' % path
示例8: get_context_name
# 需要导入模块: from pyasm.security import Site [as 别名]
# 或者: from pyasm.security.Site import get [as 别名]
def get_context_name(my):
'''this includes all of the subdirectories as well as the main
context'''
path = my.get_request_path()
p = re.compile( r"/(tactic|projects)/?(\w+)/")
m = p.search(path)
if not m:
return "default"
from pyasm.security import Site
site_obj = Site.get()
path_info = site_obj.break_up_request_path(path)
if path_info:
context = path_info.get("project_code")
else:
context = m.groups()[1]
return context
示例9: get_web_dir
# 需要导入模块: from pyasm.security import Site [as 别名]
# 或者: from pyasm.security.Site import get [as 别名]
def get_web_dir(cls, file_object=None, alias=None):
'''get base web directory'''
if file_object:
alias = file_object.get_value('base_dir_alias')
if not alias:
alias = "default"
from pyasm.security import Site
site = Site.get()
web_dir = site.get_web_dir(file_object=file_object,alias=alias)
if web_dir:
return web_dir
alias_dict = cls.get_web_dirs()
web_dir = alias_dict.get(alias)
if not web_dir:
web_dir = "/assets"
return web_dir
示例10: setup_sites
# 需要导入模块: from pyasm.security import Site [as 别名]
# 或者: from pyasm.security.Site import get [as 别名]
def setup_sites(my):
context_path = "%s/src/context" % my.install_dir
doc_dir = "%s/doc" % my.install_dir
plugin_dir = Environment.get_plugin_dir()
builtin_plugin_dir = Environment.get_builtin_plugin_dir()
dist_dir = Environment.get_dist_dir()
log_dir = "%s/log" % Environment.get_tmp_dir()
def CORS():
#cherrypy.response.headers["Access-Control-Allow-Origin"] = "http://192.168.0.15:8100"
cherrypy.response.headers["Access-Control-Allow-Origin"] = "*"
cherrypy.response.headers["Access-Control-Allow-Headers"] = "Origin, X-Requested-With, Content-Type, Accept"
cherrypy.tools.CORS = cherrypy.Tool('before_handler', CORS)
config = {
'global': {
'server.socket_host': '127.0.0.1',
'server.socket_port': 80,
'log.screen': False,
'request.show_tracebacks': True,
'tools.log_headers.on': True,
'server.log_file': "%s/tactic_log" % log_dir,
'server.max_request_body_size': 0,
#'server.socket_timeout': 60,
'response.timeout': 3600,
'tools.encode.on': True,
'tools.encode.encoding': 'utf-8',
'tools.decode.on': True,
'tools.decode.encoding': 'utf-8',
#'encoding_filter.on': True,
#'decoding_filter.on': True
'tools.CORS.on': True
},
'/context': {'tools.staticdir.on': True,
'tools.staticdir.dir': context_path,
# Need to do this because on windows servers, jar files
# are served as text/html
'tools.staticdir.content_types': {
'jar': 'application/java-archive'
}
},
'/assets': {'tools.staticdir.on': True,
'tools.staticdir.dir': Environment.get_asset_dir()
},
'/doc': {'tools.staticdir.on': True,
'tools.staticdir.dir': doc_dir,
'tools.staticdir.index': "index.html"
},
# NOTE: expose the entire plugins directory
'/tactic/plugins': {
'tools.staticdir.on': True,
'tools.staticdir.dir': plugin_dir,
},
'/tactic/builtin_plugins': {
'tools.staticdir.on': True,
'tools.staticdir.dir': builtin_plugin_dir,
},
'/tactic/dist': {
'tools.staticdir.on': True,
'tools.staticdir.dir': dist_dir,
},
'/plugins': {
'tools.staticdir.on': True,
'tools.staticdir.dir': plugin_dir,
},
'/builtin_plugins': {
'tools.staticdir.on': True,
'tools.staticdir.dir': builtin_plugin_dir,
},
'/dist': {
'tools.staticdir.on': True,
'tools.staticdir.dir': dist_dir,
},
}
# set up the root directory
cherrypy.root = Root()
cherrypy.tree.mount( cherrypy.root, config=config)
from pyasm.search import Search
search = Search("sthpw/project")
search.add_filter("type", "resource", op="!=")
projects = search.get_sobjects()
#.........这里部分代码省略.........
示例11: eval
# 需要导入模块: from pyasm.security import Site [as 别名]
# 或者: from pyasm.security.Site import get [as 别名]
# Dump out the error
print "WARNING: ", path, status, message
try:
eval("cherrypy.root.tactic.%s" % project_code)
# if project_code is empty , it raises SyntaxError
except (AttributeError, SyntaxError), e:
has_project = False
else:
has_project = True
# make sure the appropriate site is set (based on the ticket)
from pyasm.security import Site
cookie = cherrypy.request.cookie
if cookie.has_key("login_ticket"):
cookie = cookie["login_ticket"].value
site = Site.get().get_by_ticket(cookie)
else:
html_response = '''<html>
<head><meta http-equiv="Refresh" content="0; url=/"></head>
</html>'''
response.body = ''
return html_response
Site.set_site(site)
# if the url does not exist, but the project does, then check to
# to see if cherrypy knows about it
project = Project.get_by_code(project_code)
if not has_project and project and project.get_value("type") != 'resource':
示例12: get_default_project
# 需要导入模块: from pyasm.security import Site [as 别名]
# 或者: from pyasm.security.Site import get [as 别名]
def get_default_project(cls):
from pyasm.security import Site
project = Site.get().get_default_project()
return project