本文整理汇总了Python中twisted.web.static.File.getChild方法的典型用法代码示例。如果您正苦于以下问题:Python File.getChild方法的具体用法?Python File.getChild怎么用?Python File.getChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.static.File
的用法示例。
在下文中一共展示了File.getChild方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getChild
# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
def getChild(self, path, request):
resource = File.getChild(self, path, request)
for pat, repl in self._virtualLinks.iteritems():
newPath = pat.sub(repl, path)
if newPath != path:
resource = File.getChild(self, newPath, request)
break
return resource
示例2: SubdirectoryContexts
# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
class SubdirectoryContexts(Resource):
def __init__(self, dbrootdir="db", webdir="www/command", landingdir="www/landing"):
self.dbrootdir = dbrootdir
self.webdir = webdir
self.file_resource = File(landingdir)
Resource.__init__(self)
def getChild(self, name, request):
if request.method == "GET":
# Let's assume that all file are either empty (-> index.html) or have a period in them.
if len(name) == 0 or "." in name:
return self.file_resource.getChild(name, request)
else:
print 'making db', name
dbdir = os.path.join(self.dbrootdir, name)
subdir_resources = {}
dbfactory = CommandDatabase(dbdir, subdir_resources)
dbfactory.protocol = minidb.DBProtocol
dbws_resource = WebSocketResource(dbfactory)
subdir_resources['db'] = dbfactory
factory = AudioConferenceFactory(subdir_resources, dbdir, dbfactory)
factory.protocol = AudioConferenceProtocol
ws_resource = WebSocketResource(factory)
subdir_resources['factory'] = factory
attachdir = os.path.join(dbdir, "_attachments")
attach = TranscodingAttachFactory(factory, dbfactory, attachdir=attachdir)
attach.protocol = attachments.AttachProtocol
subdir_resources['attach'] = attach
attachhttp = File(attachdir)
attws_resource = WebSocketResource(attach)
zipper = DBZipper(dbfactory)
root = File(self.webdir)
dbhttp = File(dbdir)
root.putChild('_ws', ws_resource)
root.putChild('_db', dbws_resource)
root.putChild('_attach', attws_resource)
root.putChild('db', dbhttp)
root.putChild('attachments', attachhttp)
root.putChild('download.zip', zipper)
self.putChild(name, root)
return root
return Resource.getChild(self, name, request)
示例3: getChild
# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
def getChild(self, name, request):
versionString = 'phoenix/%s' % self.core.VERSION
request.setHeader('Server', versionString)
if request.method == 'POST' and request.path == '/':
return self
else:
docroot = os.path.join(self.core.basedir, 'www')
root = File(self.core.config.get('web', 'root', str, docroot))
root.processors = {'.rpy': script.ResourceScript}
return root.getChild(name, request)
示例4: PirateBelt
# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
class PirateBelt(Seatbelt):
# Piratepad-style Seatbelt variant
# make /links go to the _rewrite url of a database that's created
# & populated on-demand
def __init__(self, dbdir, landing_path, ddoc_path, otherddocs=None):
self.ddoc_path = ddoc_path
self.otherddocs = otherddocs or []
self.ddoc_name = "_design/%s" % (ddoc_path.split("/")[-1])
self.file_resource = File(landing_path)
Seatbelt.__init__(self, dbdir)
def _serve_db(self, dbname):
# Add the _rewrite root, instead of the db root
self.dbs[dbname] = PARTS_BIN["Database"](self, os.path.join(self.datadir, dbname))
# Link the ddocs
ddoc = linkddocs(self.dbs[dbname], self.ddoc_path)
self.putChild(dbname, ddoc.rewrite_resource)
for odd in self.otherddocs:
o_ddoc = linkddocs(self.dbs[dbname], odd)
ddoc.rewrite_resource.putChild(odd.split("/")[-1], o_ddoc.rewrite_resource)
def on_db_create(self, db):
pass
def getChild(self, name, request):
_cors(request)
if request.method == "GET":
# Let's assume that all file are either empty (-> index.html) or have a period in them.
if len(name) == 0 or "." in name:
return self.file_resource.getChild(name, request)
elif "_" in name:
# Why *not* allow some of the db tracking APIs...
return self
else:
# get_or_create db?
db = self.create_db(name)
self.on_db_create(db)
# Return new ddoc _rewrite
return db.docs[self.ddoc_name].rewrite_resource
else:
# Error?
return Resource.getChild(self, name, request)
示例5: getChild
# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
def getChild(self, name, request):
print(request.getClientIP() +" : in getChild : "+ str(name) +" : "+ str(request))
# print(dir(request))
print(str(request.getClientIP()) +" : "+ str(request.URLPath()))
if(re.search('^/REGISTER',request.uri)):
# p = multiprocessing.Process(target=self.saveUserDetails, args=(request,))
# p.start()
self.saveUserDetails(request)
return(Registered())
elif(re.search('^/PLAY',request.uri)):
if(str(request.getClientIP()) in clientsAllowed.values()):
self.savePlayDetails(request)
return(RegisterForPlay())
else:
return(NotRegisterForPlay())
elif(re.search('^/ALIVE',request.uri)):
return(iAmAlive())
else:
if(str(request.getClientIP()) in clientsAllowed.values()):
return(File.getChild(self,name,request))
else:
return(NotRegistered())
示例6: getChild
# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
def getChild(self, path, request):
child = File.getChild(self, path, request)
return EncodingResourceWrapper(child, [GzipEncoderFactory()])
示例7: getChild
# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
def getChild(self, name, request):
_cors(request)
return File.getChild(self, name, request)
示例8: unsubscribe
# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
def unsubscribe(self, p, channel):
if channel in self.channels:
self.channels[channel].remove(p)
if not self.channels[channel]:
del self.channels[channel]
def publish(self, channel, message, error=False):
if channel in self.channels:
for p in self.channels[channel]:
if error:
p.errorReceived(channel, message)
else:
p.messageReceived(channel, message)
# Start the party
shutil.rmtree("./tmp")
os.mkdir("./tmp")
index_page = File("index.html")
index_page.putChild("sockjs", SockJSResource(TumblrServer()))
index_page.putChild("archives", File("archives"))
from functools import partial
def bypass(self, path, request):
return self
index_page.getChild = partial(bypass, index_page)
def resource():
return index_page
示例9: RootPage
# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
class RootPage(Resource):
isLeaf = True
def __init__(self, validator):
Resource.__init__(self)
self.Ledger = validator.Ledger
self.Validator = validator
self.ps = PlatformStats()
self.GetPageMap = {
'block': self._handle_blk_request,
'statistics': self._handle_stat_request,
'store': self._handle_store_request,
'transaction': self._handle_txn_request,
'status': self._hdl_status_request,
}
self.PostPageMap = {
'default': self._msg_forward,
'forward': self._msg_forward,
'initiate': self._msg_initiate,
'command': self._do_command,
'echo': self._msg_echo
}
static_dir = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "static_content")
self.static_content = File(static_dir)
def error_response(self, request, response, *msgargs):
"""
Generate a common error response for broken requests
"""
request.setResponseCode(response)
msg = msgargs[0].format(*msgargs[1:])
if response > 400:
logger.warn(msg)
elif response > 300:
logger.debug(msg)
return "" if request.method == 'HEAD' else (msg + '\n')
def errback(self, failure, request):
failure.printTraceback()
request.processingFailed(failure)
return None
def do_get(self, request):
"""
Handle a GET request on the HTTP interface. Three paths are accepted:
/store[/<storename>[/<key>|*]]
/block[/<blockid>]
/transaction[/<txnid>]
"""
# pylint: disable=invalid-name
# split the request path removing leading duplicate slashes
components = request.path.split('/')
while components and components[0] == '':
components.pop(0)
prefix = components.pop(0) if components else 'error'
if prefix not in self.GetPageMap:
# attempt to serve static content if present.
resource = self.static_content.getChild(request.path[1:], request)
return resource.render(request)
test_only = (request.method == 'HEAD')
try:
response = self.GetPageMap[prefix](components, request.args,
test_only)
if test_only:
return ''
cbor = (request.getHeader('Accept') == 'application/cbor')
if cbor:
request.responseHeaders.addRawHeader(b"content-type",
b"application/cbor")
return dict2cbor(response)
request.responseHeaders.addRawHeader(b"content-type",
b"application/json")
pretty = 'p' in request.args
if pretty:
result = pretty_print_dict(response) + '\n'
else:
result = dict2json(response)
return result
except Error as e:
return self.error_response(
request, int(e.status),
'exception while processing http request {0}; {1}',
request.path, str(e))
#.........这里部分代码省略.........
示例10: getChild
# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
def getChild(self, path, request):
return File.getChild(self, path, request)