Pyjo.URL- Uniform Resource Locator¶
import Pyjo.URL
# Parse
url = Pyjo.URL.new('http://sri:foobar@example.com:3000/foo/bar?foo=bar#23')
print(url.scheme)
print(url.userinfo)
print(url.host)
print(url.port)
print(url.path)
print(url.query)
print(url.fragment)
# Build
url = Pyjo.URL.new()
url.scheme = 'http'
url.userinfo = 'sri:foobar'
url.host = 'example.com'
url.port = 3000
url.path = '/foo/bar'
url.query.param('foo', 'bar')
url.fragment = 23
print(url)
Pyjo.URL
implements a subset of
RFC 3986,
RFC 3987 and the
URL Living Standard for Uniform Resource
Locators with support for IDNA and IRIs.
Classes¶
-
class
Pyjo.URL.
Pyjo_URL
(url=None, **kwargs)¶ Pyjo.URL
inherits all attributes and methods fromPyjo.Base
andPyjo.String.Mixin
and implements the following new ones.-
__bool__
()¶ boolean = bool(url)
Always true. (Python 3.x)
-
__init__
(url=None, **kwargs)¶ url = Pyjo.URL.new() url = Pyjo.URL.new('http://127.0.0.1:3000/foo?f=b&baz=2#foo')
Construct a new
Pyjo.URL
object andparse()
URL if necessary.
-
__nonzero__
()¶ boolean = bool(url)
Always true. (Python 2.x)
-
append
(**kwargs)¶ params = params.append(query={'foo': 'bar'}) # calls params.query.append(foo='bar')
Calls
append()
method on each attribute fromkwargs
.
authority = url.authority url.authority = 'root:%E2%99%A5@localhost:8080'
Authority part of this URL.
# "root:%E2%99%A5@xn--n3h.net:8080" Pyjo.URL.new(u'http://root:♥@☃.net:8080/test').authority # "root@example.com" Pyjo.URL.new('http://root@example.com/test').authority
-
clone
()¶ url2 = url.clone()
Clone this URL.
-
fragment
= None¶ fragment = url.fragment url.fragment = u'♥pyjo♥'
Fragment part of this URL.
-
host
= None¶ host = url.host url.host = '127.0.0.1'
Host part of this URL.
-
host_port
¶ host_port = url.host_port
Normalized version of
host
andport
.# "xn--n3h.net:8080" Pyjo.URL.new(u'http://☃.net:8080/test').host_port # "example.com" Pyjo.URL.new('http://example.com/test').host_port
-
ihost
¶ ihost = url.ihost url.ihost = 'xn--bcher-kva.ch'
Host part of this URL in punycode format.
# "xn--n3h.net" Pyjo.URL.new(u'http://☃.net').ihost # "example.com" Pyjo.URL.new('http://example.com').ihost
-
is_abs
¶ boolean = url.is_abs
Check if URL is absolute.
# True Pyjo.URL.new('http://example.com').is_abs Pyjo.URL.new('http://example.com/test/index.html').is_abs # False Pyjo.URL.new('test/index.html').is_abs Pyjo.URL.new('/test/index.html').is_abs Pyjo.URL.new('//example.com/test/index.html').is_abs
-
merge
(**kwargs)¶ params = params.merge(query={'foo': 'bar'}) # calls params.query.merge(foo='bar')
Calls
merge()
method on each attribute fromkwargs
.
-
parse
(url)¶ url = url.parse('http://127.0.0.1:3000/foo/bar?fo=o&baz=23#foo')
Parse relative or absolute URL.
# "/test/123" url.parse('/test/123?foo=bar').path # "example.com" url.parse('http://example.com/test/123?foo=bar').host # "sri@example.com" url.parse('mailto:sri@example.com').path
-
path
¶ path = url.path url.path = '/foo/bar' url.path = 'foo/bar' url.path = Pyjo.Path.new()
Path part of this URL, relative paths will be merged with the existing path, defaults to a
Mojo::Path
object.# "perldoc" Pyjo.URL.new('http://example.com/perldoc/Mojo').path.parts[0] # "http://example.com/DOM/HTML" Pyjo.URL.new('http://example.com/perldoc/Mojo').set(path='/DOM/HTML') # "http://example.com/perldoc/DOM/HTML" Pyjo.URL.new('http://example.com/perldoc/Mojo').set(path='DOM/HTML') # "http://example.com/perldoc/Mojo/DOM/HTML" Pyjo.URL.new('http://example.com/perldoc/Mojo/').set(path='DOM/HTML')
-
path_query
¶ path_query = url.path_query
Normalized version of
path
andquery
.# "/test?a=1&b=2" Pyjo.URL.new('http://example.com/test?a=1&b=2').path_query # "/" Pyjo.URL.new('http://example.com/').path_query
-
port
= None¶ port = url.port url.port = 8080
Port part of this URL.
-
protocol
¶ proto = url.protocol
Normalized version of
scheme
.# "http" Pyjo.URL.new('HtTp://example.com').protocol
-
query
¶ query = url.query url.query = ['param', 'value'] url.query = {'param': 'value'} url.query.append('append', 'to') url.query.merge('replace', 'with') url.query = Pyjo.Parameters.new()
Query part of this URL as
Pyjo.Parameters
object.# "2" Pyjo.URL.new('http://example.com?a=1&b=2').query.param('b') # "http://example.com?a=2&c=3" Pyjo.URL.new('http://example.com?a=1&b=2').set(query=['a', 2, 'c', 3]) # "http://example.com?a=2&a=3" Pyjo.URL.new('http://example.com?a=1&b=2').set(query={'a': [2, 3]}) # "http://example.com?a=2&b=2&c=3" Pyjo.URL.new('http://example.com?a=1&b=2').merge(query={'a': 2, 'c': 3}) # "http://example.com?b=2" Pyjo.URL.new('http://example.com?a=1&b=2').merge(query={'a': None}) # "http://example.com?a=1&b=2&a=2&c=3" Pyjo.URL.new('http://example.com?a=1&b=2').append(query=['a', 2, 'c', 3])
-
scheme
= None¶ scheme = url.scheme url.scheme = 'http'
Scheme part of this URL.
-
to_abs
(base=None)¶ absolute = url.to_abs() absolute = url.to_abs(Pyjo.URL.new('http://example.com/foo'))
Clone relative URL and turn it into an absolute one using
base
or provided base URL.# "http://example.com/foo/baz.xml?test=123" Pyjo.URL.new('baz.xml?test=123') \ .to_abs(Pyjo.URL.new('http://example.com/foo/bar.html')) # "http://example.com/baz.xml?test=123" Pyjo.URL.new('/baz.xml?test=123') \ .to_abs(Pyjo.URL.new('http://example.com/foo/bar.html')) # "http://example.com/foo/baz.xml?test=123" Pyjo.URL.new('//example.com/foo/baz.xml?test=123') \ .to_abs(Pyjo.URL.new('http://example.com/foo/bar.html'))
-
to_bytes
()¶ bstring = url.to_bytes()
Turn URL into a bytes string.
-
to_str
()¶ string = url.to_str()
Turn URL into a string.
-
userinfo
= None¶ info = url.userinfo url.userinfo = u'root:♥'
Userinfo part of this URL.
-