~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
== Security Proxied URI Objects ==

URI objects can be compared for equality even in the presence of Zope
security proxies.

  >>> from zope.security.proxy import ProxyFactory
  >>> from lazr.uri import URI

  >>> uri1 = URI('http://a/b/c/d;p?q')
  >>> uri2 = URI('http://a/b/c/d;p?q')
  >>> uri3 = URI('https://launchpad.net')
  >>> proxied_uri1 = ProxyFactory(uri1)
  >>> proxied_uri2 = ProxyFactory(uri2)
  >>> proxied_uri3 = ProxyFactory(uri3)

We can access the various URI components:

  >>> print proxied_uri1.scheme
  http
  >>> print proxied_uri1.userinfo
  None
  >>> print proxied_uri1.host
  a
  >>> print proxied_uri1.port
  None
  >>> print proxied_uri1.path
  /b/c/d;p
  >>> print proxied_uri1.query
  q
  >>> print proxied_uri1.fragment
  None
  >>> print proxied_uri1.authority
  a
  >>> print proxied_uri1.hier_part
  //a/b/c/d;p

We can test for equality:

  >>> uri1 == uri2
  True
  >>> uri1 == proxied_uri2
  True
  >>> proxied_uri1 == uri2
  True
  >>> proxied_uri1 == proxied_uri2
  True

  >>> proxied_uri1 == proxied_uri3
  False

Similarly, inequality can be checked:

  >>> proxied_uri1 != proxied_uri3
  True

We can get the string value and representation of a URI:

  >>> print str(proxied_uri1)
  http://a/b/c/d;p?q
  >>> print repr(proxied_uri1)
  URI('http://a/b/c/d;p?q')

We can replace components:

  >>> print proxied_uri1.replace(scheme='https')
  https://a/b/c/d;p?q

We can append a component:

  >>> print proxied_uri1.append('e/f')
  http://a/b/c/d;p/e/f

We can check for containment:

  >>> proxied_uri1.contains(proxied_uri2)
  True
  >>> proxied_uri1.contains(proxied_uri3)
  False

We can create a URI that ensures it has or does not have a trailing
slash:

  >>> print proxied_uri1.ensureSlash()
  http://a/b/c/d;p/?q
  >>> print proxied_uri1.ensureNoSlash()
  http://a/b/c/d;p?q