本文整理汇总了Python中twisted.python.urlpath.URLPath类的典型用法代码示例。如果您正苦于以下问题:Python URLPath类的具体用法?Python URLPath怎么用?Python URLPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了URLPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: links
def links(self, request, tag):
ds = self.root.edits(self.ob)
therange = range(len(ds))
rev = therange[self.rev]
ul = tags.ul()
for i in therange:
li = tags.li()
if i:
u = URLPath.fromRequest(request)
u = u.sibling('diff')
u.query = urllib.urlencode({
'ob': self.ob.fullName(),
'revA': i-1,
'revB': i,
})
li(tags.a(href=str(u))("(diff)"))
else:
li("(diff)")
li(" - ")
if i == len(ds) - 1:
label = "Latest"
else:
label = str(i)
if i == rev:
li(label)
else:
u = URLPath.fromRequest(request)
u.query = urllib.urlencode({
'rev': str(i),
'ob': self.ob.fullName(),
})
li(tags.a(href=str(u))(label))
li(' - ' + ds[i].user + '/' + ds[i].time)
ul(li)
return tag(ul)
示例2: uri_for_service
def uri_for_service(self, region, service_id, base_uri):
"""
Generate a URI prefix for a given region and service ID.
Each plugin loaded into mimic generates a list of catalog entries; each
catalog entry has a list of endpoints. Each endpoint has a URI
associated with it, which we call a "URI prefix", because the endpoint
will have numerous other URIs beneath it in the hierarchy, generally
starting with a version number and tenant ID. The URI prefixes
generated for this function point to the top of the endpoint's
hierarchy, not including any tenant information.
:param unicode region: the name of the region that the service resource
exists within.
:param unicode service_id: the UUID for the service for the specified
region
:param str base_uri: the base uri to use instead of the default - most
likely comes from a request URI
:return: The full URI locating the service for that region
:rtype: ``str``
"""
if region:
return str(URLPath.fromString(base_uri)
.child("mimicking").child(service_id).child(region).child(""))
else:
return str(URLPath.fromString(base_uri)
.child("mimicking").child(service_id).child(""))
示例3: makeURLPath
def makeURLPath(s):
"""
Create a URLPath with the given text or bytes.
"""
if hasattr(URLPath, 'fromBytes') and isinstance(s, bytes):
return URLPath.fromBytes(s)
else:
return URLPath.fromString(s)
示例4: url
def url(self, suffix):
"""
Generate a URL to an object within the Heat URL hierarchy, given the
part of the URL that comes after.
"""
return str(URLPath.fromString(self.uri_prefix)
.child(suffix.encode("utf-8")))
示例5: initialize
def initialize(self):
self.clean()
def resolveCb(result):
self.mangle.createChain(chain="cattivo")
entry = self._createAuthenticatorEntry(result)
self.mangle.appendEntry(entry, chain="cattivo")
entry = self._createLocalTrafficEntry()
self.mangle.appendEntry(entry, chain="cattivo")
entry = self._createDefaultTproxyEntry()
self.mangle.appendEntry(entry, chain="cattivo")
self.mangle.commit()
entry = self._createJumpInCattivoEntry()
self.mangle.appendEntry(entry, chain="PREROUTING")
self.mangle.commit()
authenticator = cattivo.config.get("authenticator", "host")
url = URLPath.fromString(authenticator)
address = url.netloc
dfr = reactor.resolve(address)
dfr.addCallback(resolveCb)
return dfr
示例6: hist
def hist(self, data, request):
u = URLPath.fromRequest(request)
u = u.sibling('diff')
u.query = urllib.urlencode({
'ob': data.obj.fullName(),
'rev': data.rev,
})
return tags.a(href=str(u))("(hist)")
示例7: __init__
def __init__(self, mapsPath, fetchURL, deleteIfNotPresent, tfLevelSounds,
listURL, keyPrefix):
MapUpdater.__init__(self, mapsPath, fetchURL, deleteIfNotPresent,
tfLevelSounds)
assert isinstance(listURL, str) and len(listURL)
assert isinstance(keyPrefix, str) and len(keyPrefix)
self.listURL = URLPath.fromString(listURL)
self.keyPrefix = keyPrefix
示例8: request
def request(testCase, rootResource, method, uri, body=b"", baseURI="http://localhost:8900/"):
"""
Issue a request and return a synchronous response.
"""
# allow for relative or absolute URIs, since we're going to the same
# resource no matter what
return RequestTraversalAgent(testCase, rootResource).request(
method, str(URLPath.fromString(baseURI).click(uri)), bodyProducer=SynchronousProducer(body)
)
示例9: base_uri_from_request
def base_uri_from_request(request):
"""
Given a request, return the base URI of the request
:param request: a twisted HTTP request
:type request: :class:`twisted.web.http.Request`
:return: the base uri the request was trying to access
:rtype: ``str``
"""
return str(URLPath.fromRequest(request).click(b'/'))
示例10: _toUrl
def _toUrl(spec):
if not spec:
raise cli.UsageError("No Pub server")
from twisted.python.urlpath import URLPath
try:
url = URLPath.fromString(spec)
except:
raise cli.UsageError("Invalid URL: {0}".format(spec))
if not spec.startswith(url.scheme):
raise cli.UsageError("Invalid URL: {0}".format(spec))
return url
示例11: __init__
def __init__(self, uri, agent=None):
"""
@type uri: L{unicode}
@param uri: Entropy endpoint URI, for example:
C{http://example.com/entropy/}.
@type agent: L{twisted.web.iweb.IAgent}
@param agent: Twisted Web agent.
"""
self.uri = URLPath.fromString(uri)
if agent is None:
agent = Agent(reactor)
self._agent = agent
示例12: __init__
def __init__(self, uri, verify, timeout=600, reactor=reactor, clientCert=None):
Resource.__init__(self)
self._uri = URLPath.fromString(uri)
self._verify = verify
self._timeout = timeout
self._reactor = reactor
pool = HTTPConnectionPool(reactor)
if clientCert is not None:
clientCert = PrivateCertificate.loadPEM(
FilePath(clientCert).getContent())
self._agent = Agent(
reactor,
StupidPolicyForHTTPS(InsecureTLSOptions(clientCert)),
pool=pool)
示例13: uri_for_service
def uri_for_service(self, region, service_id, base_uri):
"""
Generate a URI prefix for a given region and service ID.
:param unicode region_name: the name of the region that the service
resource exists within.
:param unicode service_id: the UUID for the service for the
specified region
:param str base_uri: the base uri to use instead of the default -
most likely comes from a request URI
:return: The full URI locating the service for that region
"""
return str(URLPath.fromString(base_uri)
.child("service").child(region).child(service_id).child(""))
示例14: handleProcess
def handleProcess(self, request):
path = URLPath.fromBytes(getUrlForRequest(request))
args = {k: v[0] for k, v in request.args.iteritems()}
oidconsumer = self.getConsumer(request)
def _cb(info):
if info.status == consumer.FAILURE:
request.setResponseCode(http.UNAUTHORIZED)
return Data('Login failed', 'text/plain')
ident = info.getDisplayIdentifier()
return self.loginCallback(request, ident)
d = self.semaphore.run(oidconsumer.complete, args, str(path))
d.addCallback(_cb)
return DeferredResource(d)
示例15: absoluteURL
def absoluteURL(request, ob):
if ob.documentation_location == model.DocLocation.PARENT_PAGE:
p = ob.parent
if isinstance(p, model.Module) and p.name == '__init__':
p = p.parent
child = p.fullName() + '.html'
frag = ob.name
elif ob.documentation_location == model.DocLocation.OWN_PAGE:
child = ob.fullName() + '.html'
frag = None
else:
raise AssertionError("XXX")
u = URLPath.fromRequest(request)
u = u.sibling(child)
u.query = ''
u.fragment = frag
return str(u)