• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python urlpath.URLPath类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中twisted.python.urlpath.URLPath的典型用法代码示例。如果您正苦于以下问题:Python URLPath类的具体用法?Python URLPath怎么用?Python URLPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了URLPath类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:chevah,项目名称:pydoctor,代码行数:35,代码来源:server.py


示例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(""))
开发者ID:obulpathi,项目名称:mimic,代码行数:28,代码来源:core.py


示例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)
开发者ID:BenjamenMeyer,项目名称:mimic,代码行数:8,代码来源:helpers.py


示例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")))
开发者ID:derwolfe,项目名称:mimic,代码行数:7,代码来源:heat_api.py


示例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
开发者ID:alessandrod,项目名称:cattivo,代码行数:27,代码来源:base.py


示例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)")
开发者ID:chevah,项目名称:pydoctor,代码行数:8,代码来源:server.py


示例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
开发者ID:jsza,项目名称:tempus-map-updater,代码行数:8,代码来源:updater.py


示例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)
    )
开发者ID:kivattik,项目名称:mimic,代码行数:9,代码来源:helpers.py


示例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'/'))
开发者ID:pratikmallya,项目名称:mimic,代码行数:11,代码来源:identity_api.py


示例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
开发者ID:olix0r,项目名称:pub,代码行数:11,代码来源:cli.py


示例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
开发者ID:fusionapp,项目名称:entropy,代码行数:13,代码来源:client.py


示例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)
开发者ID:fusionapp,项目名称:soapproxy,代码行数:14,代码来源:proxy.py


示例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(""))
开发者ID:jirwin,项目名称:mimic,代码行数:15,代码来源:core.py


示例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)
开发者ID:jsza,项目名称:jump-map-list,代码行数:16,代码来源:guard.py


示例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)
开发者ID:chevah,项目名称:pydoctor,代码行数:17,代码来源:server.py


示例16: getSteamIDFromURL

def getSteamIDFromURL(url, steamAPI):
    path = URLPath.fromString(url)
    steamID = None
    if path.netloc.lower() == 'steamcommunity.com':
        if path.path.startswith('/id/'):
            vanityURL = path.path[4:].rstrip('/')
            response = yield deferToThread(
                steamAPI['ISteamUser'].ResolveVanityURL,
                vanityurl=vanityURL)
            try:
                steamID = int(response['response']['steamid'])
            except (KeyError, ValueError):
                pass
        elif path.path.startswith('/profiles/'):
            try:
                steamID = int(path.path[10:].rstrip('/'))
            except ValueError:
                pass
    returnValue(steamID)
开发者ID:jsza,项目名称:jump-map-list,代码行数:19,代码来源:util.py


示例17: handleLogin

    def handleLogin(self, request):
        path = URLPath.fromBytes(getUrlForRequest(request))

        def _tx():
            oidconsumer = self.getConsumer(request)
            oidrequest = oidconsumer.begin(self.providerURL)
            return oidrequest.redirectURL(str(path.parent()),
                                          str(path.sibling('process')),
                                          immediate=False)

        def _eb(failure):
            failure.trap(DiscoveryFailure)
            request.setResponseCode(http.SEVICE_UNAVAILABLE)
            return Data('Steam login service unavailable.', 'text/plain')

        d = self.semaphore.run(deferToThread, _tx)
        d.addCallback(Redirect)
        d.addErrback(_eb)
        return DeferredResource(d)
开发者ID:jsza,项目名称:jump-map-list,代码行数:19,代码来源:guard.py


示例18: start

    def start(self):
        if self.interrupted:
            self.failed(Failure(Exception('Interrupted')))
            return

        self.current_attempt += 1

        if self.current_attempt > self.attempts:
            if len(self.servers) < 1:
                self.failed(Failure(Exception(
                    'No more signing servers to try.')))
            else:
                self.current_attempt = 1

        if self.current_attempt == 1:
            uri, self.username, self.password, _ = self.servers.pop()
            self.uri = 'https://%s/token' % uri

        slaveName = self.getSlaveName()
        slaveIP = self.buildslave.slave.broker.transport.getPeer().host

        if not self.stdio_log:
            self.stdio_log = self.addLog('output')
            self.stdio_log.addHeader("Slave: %s\n" % slaveName)
            self.stdio_log.addHeader("IP: %s\n" % slaveIP)
            self.stdio_log.addHeader("Duration: %s\n" % self.duration)
        self.stdio_log.addStdout("URI: %s\n" % self.uri)

        method = 'POST'
        postdata = {
            'slave_ip': slaveIP,
            'duration': self.duration,
        }
        headers = self.generateHeaders(
            method=method,
            credentials=(self.username, self.password))
        # send the HTTPSVerifyingContextFactory the hostname of the signing
        # server + the cert
        contextFactory = HTTPSVerifyingContextFactory(
            URLPath.fromString(self.uri).netloc.split(':')[0], self.server_cert)
        d = getPage(self.uri, method=method, headers=headers,
                    postdata=urlencode(postdata), contextFactory=contextFactory)
        d.addCallbacks(self.downloadSignature, self.requestFailed)
开发者ID:lundjordan,项目名称:build-buildbotcustom,代码行数:43,代码来源:signing.py


示例19: request

def request(testCase, rootResource, method, uri, body=b"",
            baseURI='http://localhost:8900/',
            headers=None):
    """
    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
    if headers is not None:
        headers_object = Headers()
        for key, value in headers.items():
            headers_object.setRawHeaders(key, value)
    else:
        headers_object = None
    return (
        RequestTraversalAgent(testCase, rootResource)
        .request(method, str(URLPath.fromString(baseURI).click(uri)),
                 bodyProducer=SynchronousProducer(body),
                 headers=headers_object)
    )
开发者ID:isaacm,项目名称:mimic,代码行数:20,代码来源:helpers.py


示例20: request

    def request(self, method, uri, headers=None, bodyProducer=None):
        """
        Implement IAgent.request.
        """
        # We want to use Agent to parse the HTTP response, so let's ask it to
        # make a request against our in-memory reactor.
        response = self._realAgent.request(method, uri, headers, bodyProducer)

        # If the request has already finished, just propagate the result.  In
        # reality this would only happen in failure, but if the agent ever adds
        # a local cache this might be a success.
        already_called = []

        def check_already_called(r):
            already_called.append(r)
            return r
        response.addBoth(check_already_called)
        if already_called:
            return response

        # That will try to establish an HTTP connection with the reactor's
        # connectTCP method, and MemoryReactor will place Agent's factory into
        # the tcpClients list.  Alternately, it will try to establish an HTTPS
        # connection with the reactor's connectSSL method, and MemoryReactor
        # will place it into the sslClients list.  We'll extract that.
        scheme = URLPath.fromString(uri).scheme
        if scheme == "https":
            host, port, factory, context_factory, timeout, bindAddress = (
                self._memoryReactor.sslClients[-1])
        else:
            host, port, factory, timeout, bindAddress = (
                self._memoryReactor.tcpClients[-1])

        # Then we need to convince that factory it's connected to something and
        # it will give us a protocol for that connection.
        protocol = factory.buildProtocol(None)

        # We want to capture the output of that connection so we'll make an
        # in-memory transport.
        clientTransport = AbortableStringTransport()
        if scheme == "https":
            directlyProvides(clientTransport, ISSLTransport)

        # When the protocol is connected to a transport, it ought to send the
        # whole request because callers of this should not use an asynchronous
        # bodyProducer.
        protocol.makeConnection(clientTransport)

        # Get the data from the request.
        requestData = clientTransport.io.getvalue()

        # Now time for the server to do its job.  Ask it to build an HTTP
        # channel.
        channel = Site(self._rootResource).buildProtocol(None)

        # Connect the channel to another in-memory transport so we can collect
        # the response.
        serverTransport = AbortableStringTransport()
        if scheme == "https":
            directlyProvides(serverTransport, ISSLTransport)
        serverTransport.hostAddr = IPv4Address('TCP', '127.0.0.1', port)
        channel.makeConnection(serverTransport)

        # Feed it the data that the Agent synthesized.
        channel.dataReceived(requestData)

        # Now we have the response data, let's give it back to the Agent.
        protocol.dataReceived(serverTransport.io.getvalue())

        def finish(r):
            # By now the Agent should have all it needs to parse a response.
            protocol.connectionLost(Failure(ConnectionDone()))
            # Tell it that the connection is now complete so it can clean up.
            channel.connectionLost(Failure(ConnectionDone()))
            # Propogate the response.
            return r

        # Return the response in the accepted format (Deferred firing
        # IResponse).  This should be synchronously fired, and if not, it's the
        # system under test's problem.
        return response.addBoth(finish)
开发者ID:salmonx,项目名称:treq,代码行数:81,代码来源:testing.py



注:本文中的twisted.python.urlpath.URLPath类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python urllib.error函数代码示例发布时间:2022-05-27
下一篇:
Python reflect.requireModule函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap