当前位置: 首页>>代码示例>>Python>>正文


Python URL.fromString方法代码示例

本文整理汇总了Python中nevow.url.URL.fromString方法的典型用法代码示例。如果您正苦于以下问题:Python URL.fromString方法的具体用法?Python URL.fromString怎么用?Python URL.fromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nevow.url.URL的用法示例。


在下文中一共展示了URL.fromString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_url

# 需要导入模块: from nevow.url import URL [as 别名]
# 或者: from nevow.url.URL import fromString [as 别名]
    def test_url(self):
        """
        An L{URL} object is flattened to the appropriate representation of
        itself, whether it is the child of a tag or the value of a tag
        attribute.
        """
        link = URL.fromString("http://foo/fu?bar=baz&bar=baz#quux%2f")
        self.assertStringEqual(
            self.flatten(link),
            "http://foo/fu?bar=baz&bar=baz#quux%2F")
        self.assertStringEqual(
            self.flatten(div[link]),
            '<div>http://foo/fu?bar=baz&amp;bar=baz#quux%2F</div>')
        self.assertStringEqual(
            self.flatten(div(foo=link)),
            '<div foo="http://foo/fu?bar=baz&amp;bar=baz#quux%2F"></div>')
        self.assertStringEqual(
            self.flatten(div[div(foo=link)]),
            '<div><div foo="http://foo/fu?bar=baz&amp;bar=baz#quux%2F"></div>'
            '</div>')

        link = URL.fromString("http://foo/fu?%2f=%7f")
        self.assertStringEqual(
            self.flatten(link),
            "http://foo/fu?%2F=%7F")
        self.assertStringEqual(
            self.flatten(div[link]),
            '<div>http://foo/fu?%2F=%7F</div>')
        self.assertStringEqual(
            self.flatten(div(foo=link)),
            '<div foo="http://foo/fu?%2F=%7F"></div>')
开发者ID:UstadMobile,项目名称:exelearning-ustadmobile-work,代码行数:33,代码来源:test_newflat.py

示例2: test_getSelectedTabExactMatch

# 需要导入模块: from nevow.url import URL [as 别名]
# 或者: from nevow.url.URL import fromString [as 别名]
    def test_getSelectedTabExactMatch(self):
        """
        Check that L{webnav.getSelectedTab} returns the tab whose C{linkURL}
        attribute exactly matches the path of the L{nevow.url.URL} it is passed
        """

        tabs = list(webnav.Tab(str(i), None, 0, linkURL="/" + str(i)) for i in xrange(5))

        for (i, tab) in enumerate(tabs):
            selected = webnav.getSelectedTab(tabs, URL.fromString(tab.linkURL))
            self.assertIdentical(selected, tab)

        selected = webnav.getSelectedTab(tabs, URL.fromString("/XYZ"))
        self.failIf(selected)
开发者ID:fusionapp,项目名称:mantissa,代码行数:16,代码来源:test_webnav.py

示例3: __init__

# 需要导入模块: from nevow.url import URL [as 别名]
# 或者: from nevow.url.URL import fromString [as 别名]
    def __init__(self, url, tries=10, timeout=defaultTimeout, *a, **kw):
        """
        Prepare the download information.

        Any additional positional or keyword arguments are passed on to
        C{twisted.web.client.HTTPPageGetter}.

        @type url: C{nevow.url.URL} or C{unicode} or C{str}
        @param url: The HTTP URL to attempt to download

        @type tries: C{int}
        @param tries: The maximum number of retry attempts before giving up

        @type timeout: C{float}
        @param timeout: Timeout value, in seconds, for the page fetch;
            defaults to L{defaultTimeout}
        """
        if isinstance(url, unicode):
            url = url.encode('utf-8')
        if isinstance(url, str):
            url = URL.fromString(url)

        self.url = url.anchor(None)
        self.args = a
        self.kwargs = kw
        self.delay = self.initialDelay
        self.tries = tries
        self.timeout = timeout
开发者ID:mithrandi,项目名称:eridanus,代码行数:30,代码来源:util.py

示例4: checkid_setup

# 需要导入模块: from nevow.url import URL [as 别名]
# 或者: from nevow.url.URL import fromString [as 别名]
def checkid_setup(registry, requestData, user=None):
	"""
	This method will validate and redirect a successful request to its
	return_to param. If the user isn't logged in, or doesn't have an account,
	we'll redirect to an internal page.
	
	@param registry: the current OpenID registry
	@type registry: L{OpenIDRegistry}
	
	@param requestData: the current request data
	@type requestData: L{OpenIDRequest}
	
	@param user: the current user
	@type user: L{txopenid.user.User}
	
	@return: association response
	@rtype: L{nevow.url.URL}
	"""
	if(user is not None):
		def _identity_state():
			return user.hasIdentity(requestData['openid.identity'])
		
		def _trust_state():
			 return user.trustsRoot(requestData['openid.trust_root'])
		
		if not(yield maybeDeferred(_identity_state)):
			return_to = util.appendQuery(OPENID_IDENTITY_URL, requestData)
		elif not(yield maybeDeferred(_trust_state)):
			return_to = util.appendQuery(OPENID_TRUST_URL, requestData)
		else:
			return_to = get_login_response(registry, requestData)
	else:
		return_to = util.appendQuery(OPENID_LOGIN_URL, requestData)
	
	returnValue(URL.fromString(return_to))
开发者ID:iffy,项目名称:txOpenID,代码行数:37,代码来源:protocol.py

示例5: test_finish

# 需要导入模块: from nevow.url import URL [as 别名]
# 或者: from nevow.url.URL import fromString [as 别名]
    def test_finish(self):
        """
        L{StylesheetRewritingRequestWrapper.finish} causes all written bytes to
        be translated with C{_replace} written to the wrapped request.
        """
        stylesheetFormat = """
            .foo {
                background-image: url(%s)
            }
        """
        originalStylesheet = stylesheetFormat % ("/Foo/bar",)
        expectedStylesheet = stylesheetFormat % ("/bar/Foo/bar",)

        request = FakeRequest()
        roots = {request: URL.fromString('/bar/')}
        wrapper = website.StylesheetRewritingRequestWrapper(
            request, [], roots.get)
        wrapper.write(originalStylesheet)
        wrapper.finish()
        # Parse and serialize both versions to normalize whitespace so we can
        # make a comparison.
        parser = CSSParser()
        self.assertEqual(
            parser.parseString(request.accumulator).cssText,
            parser.parseString(expectedStylesheet).cssText)
开发者ID:twisted,项目名称:mantissa,代码行数:27,代码来源:test_website.py

示例6: rendered

# 需要导入模块: from nevow.url import URL [as 别名]
# 或者: from nevow.url.URL import fromString [as 别名]
    def rendered(request):
        if request.redirected_to is None:
            result.callback(request)
        else:
            visited.append(request.redirected_to)

            if visited.index(request.redirected_to) != len(visited) - 1:
                visited.append(request.redirected_to)
                result.errback(Exception("Redirect loop: %r" % (visited,)))
            elif len(visited) > redirectLimit:
                result.errback(Exception("Too many redirects: %r" % (visited,)))
            else:
                newHeaders = headers.copy()

                # Respect redirects
                location = URL.fromString(request.redirected_to)
                newHeaders['host'] = location.netloc

                # Respect cookies
                cookies.update(request.cookies)

                # str(URL) shouldn't really do what it does.
                page = getResource(
                    site, str(location), newHeaders, cookies)
                page.addCallbacks(rendered, result.errback)
开发者ID:fusionapp,项目名称:mantissa,代码行数:27,代码来源:test_web.py

示例7: test_parseURLs

# 需要导入模块: from nevow.url import URL [as 别名]
# 或者: from nevow.url.URL import fromString [as 别名]
 def test_parseURLs(self):
     """
     L{eridanus.iriparse.parseURL} extracts and parses (as a
     L{nevow.url.URL}) all URIs in a string.
     """
     self.assertEquals(
         list(iriparse.parseURLs(u'http://google.com/')),
         [URL.fromString(u'http://google.com/')])
开发者ID:mithrandi,项目名称:eridanus,代码行数:10,代码来源:test_iriparse.py

示例8: test_parseURL

# 需要导入模块: from nevow.url import URL [as 别名]
# 或者: from nevow.url.URL import fromString [as 别名]
 def test_parseURL(self):
     """
     L{eridanus.iriparse.parseURL} extracts and parses (as a
     L{nevow.url.URL}) the first URI in a string.
     """
     self.assertEquals(
         iriparse.parseURL(
             u'http://google.com/ http://foo.bar/ world'),
         URL.fromString(u'http://google.com/'))
开发者ID:mithrandi,项目名称:eridanus,代码行数:11,代码来源:test_iriparse.py

示例9: evaluate

# 需要导入模块: from nevow.url import URL [as 别名]
# 或者: from nevow.url.URL import fromString [as 别名]
 def evaluate(self, expn):
     """
     Evaluate an expression.
     """
     url = URL.fromString('http://www.google.com/search?')
     url = url.add('q', expn + '=')
     url = url.add('num', '1')
     d = self._fetch(url)
     d.addCallback(self._extractResult, expn)
     return d
开发者ID:mithrandi,项目名称:eridanus,代码行数:12,代码来源:google.py

示例10: test_replaceMantissa

# 需要导入模块: from nevow.url import URL [as 别名]
# 或者: from nevow.url.URL import fromString [as 别名]
 def test_replaceMantissa(self):
     """
     L{StylesheetRewritingRequestWrapper._replace} changes URLs of the form
     I{/Mantissa/foo} to I{<rootURL>/static/mantissa-base/foo}.
     """
     request = object()
     roots = {request: URL.fromString('/bar/')}
     wrapper = website.StylesheetRewritingRequestWrapper(request, [], roots.get)
     self.assertEqual(
         wrapper._replace('/Mantissa/foo.png'),
         '/bar/static/mantissa-base/foo.png')
开发者ID:twisted,项目名称:mantissa,代码行数:13,代码来源:test_website.py

示例11: rootChild_resetPassword

# 需要导入模块: from nevow.url import URL [as 别名]
# 或者: from nevow.url.URL import fromString [as 别名]
    def rootChild_resetPassword(self, req, webViewer):
        """
        Redirect authenticated users to their settings page (hopefully they
        have one) when they try to reset their password.

        This is the wrong way for this functionality to be implemented.  See
        #2524.
        """
        from xmantissa.ixmantissa import IWebTranslator, IPreferenceAggregator
        return URL.fromString(
            IWebTranslator(self.store).linkTo(
                IPreferenceAggregator(self.store).storeID))
开发者ID:rcarmo,项目名称:divmod.org,代码行数:14,代码来源:website.py

示例12: test_replaceOtherOffering

# 需要导入模块: from nevow.url import URL [as 别名]
# 或者: from nevow.url.URL import fromString [as 别名]
 def test_replaceOtherOffering(self):
     """
     L{StylesheetRewritingRequestWrapper._replace} changes URLs of the form
     I{/Something/foo} to I{<rootURL>/static/Something/foo} if C{Something}
     gives the name of an installed offering with a static content path.
     """
     request = object()
     roots = {request: URL.fromString('/bar/')}
     wrapper = website.StylesheetRewritingRequestWrapper(request, ['OfferingName'], roots.get)
     self.assertEqual(
         wrapper._replace('/OfferingName/foo.png'),
         '/bar/static/OfferingName/foo.png')
开发者ID:twisted,项目名称:mantissa,代码行数:14,代码来源:test_website.py

示例13: renderHTTP

# 需要导入模块: from nevow.url import URL [as 别名]
# 或者: from nevow.url.URL import fromString [as 别名]
    def renderHTTP(self, ctx):
        req = inevow.IRequest(ctx)
        password = req.args.get('password', [None])[0]

        if password is None:
            return Page.renderHTTP(self, ctx)

        self.original.store.transact(self.original.setPassword,
                                     unicode(password)) # XXX TODO: select
                                                        # proper decoding
                                                        # strategy.
        return URL.fromString('/')
开发者ID:fusionapp,项目名称:mantissa,代码行数:14,代码来源:signup.py

示例14: test_shortURL

# 需要导入模块: from nevow.url import URL [as 别名]
# 或者: from nevow.url.URL import fromString [as 别名]
 def test_shortURL(self):
     """
     L{StylesheetRewritingRequestWrapper._replace} changes URLs with only
     one segment so they are beneath the root URL.
     """
     request = object()
     roots = {request: URL.fromString('/bar/')}
     wrapper = website.StylesheetRewritingRequestWrapper(
         request, [], roots.get)
     self.assertEqual(
         wrapper._replace('/'),
         '/bar/')
开发者ID:twisted,项目名称:mantissa,代码行数:14,代码来源:test_website.py

示例15: test_nonOfferingOnlyGivenPrefix

# 需要导入模块: from nevow.url import URL [as 别名]
# 或者: from nevow.url.URL import fromString [as 别名]
 def test_nonOfferingOnlyGivenPrefix(self):
     """
     L{StylesheetRewritingRequestWrapper._replace} only changes URLs of the
     form I{/Something/foo} so they are beneath the root URL if C{Something}
     does not give the name of an installed offering.
     """
     request = object()
     roots = {request: URL.fromString('/bar/')}
     wrapper = website.StylesheetRewritingRequestWrapper(
         request, ['Foo'], roots.get)
     self.assertEqual(
         wrapper._replace('/OfferingName/foo.png'),
         '/bar/OfferingName/foo.png')
开发者ID:twisted,项目名称:mantissa,代码行数:15,代码来源:test_website.py


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