3691.350.19
by James Henstridge
fixes from BjornT's review |
1 |
== Security Proxied URI Objects == |
2 |
||
3 |
URI objects can be compared for equality even in the presence of Zope |
|
4 |
security proxies. |
|
5 |
||
6 |
>>> from zope.security.proxy import ProxyFactory |
|
7864.2.1
by Leonard Richardson
Started using lazr.uri instead of the built-in uri library. |
7 |
>>> from lazr.uri import URI |
3691.350.19
by James Henstridge
fixes from BjornT's review |
8 |
|
9 |
>>> uri1 = URI('http://a/b/c/d;p?q') |
|
10 |
>>> uri2 = URI('http://a/b/c/d;p?q') |
|
11 |
>>> uri3 = URI('https://launchpad.net') |
|
12 |
>>> proxied_uri1 = ProxyFactory(uri1) |
|
13 |
>>> proxied_uri2 = ProxyFactory(uri2) |
|
14 |
>>> proxied_uri3 = ProxyFactory(uri3) |
|
15 |
||
16 |
We can access the various URI components: |
|
17 |
||
18 |
>>> print proxied_uri1.scheme |
|
19 |
http |
|
20 |
>>> print proxied_uri1.userinfo |
|
21 |
None |
|
22 |
>>> print proxied_uri1.host |
|
23 |
a |
|
24 |
>>> print proxied_uri1.port |
|
25 |
None |
|
26 |
>>> print proxied_uri1.path |
|
27 |
/b/c/d;p |
|
28 |
>>> print proxied_uri1.query |
|
29 |
q |
|
30 |
>>> print proxied_uri1.fragment |
|
31 |
None |
|
32 |
>>> print proxied_uri1.authority |
|
33 |
a |
|
34 |
>>> print proxied_uri1.hier_part |
|
35 |
//a/b/c/d;p |
|
36 |
||
37 |
We can test for equality: |
|
38 |
||
39 |
>>> uri1 == uri2 |
|
40 |
True |
|
41 |
>>> uri1 == proxied_uri2 |
|
42 |
True |
|
43 |
>>> proxied_uri1 == uri2 |
|
44 |
True |
|
45 |
>>> proxied_uri1 == proxied_uri2 |
|
46 |
True |
|
47 |
||
48 |
>>> proxied_uri1 == proxied_uri3 |
|
49 |
False |
|
50 |
||
51 |
Similarly, inequality can be checked: |
|
52 |
||
53 |
>>> proxied_uri1 != proxied_uri3 |
|
54 |
True |
|
55 |
||
56 |
We can get the string value and representation of a URI: |
|
57 |
||
58 |
>>> print str(proxied_uri1) |
|
59 |
http://a/b/c/d;p?q |
|
60 |
>>> print repr(proxied_uri1) |
|
61 |
URI('http://a/b/c/d;p?q') |
|
62 |
||
63 |
We can replace components: |
|
64 |
||
65 |
>>> print proxied_uri1.replace(scheme='https') |
|
66 |
https://a/b/c/d;p?q |
|
67 |
||
68 |
We can append a component: |
|
69 |
||
70 |
>>> print proxied_uri1.append('e/f') |
|
71 |
http://a/b/c/d;p/e/f |
|
72 |
||
73 |
We can check for containment: |
|
74 |
||
75 |
>>> proxied_uri1.contains(proxied_uri2) |
|
76 |
True |
|
77 |
>>> proxied_uri1.contains(proxied_uri3) |
|
78 |
False |
|
79 |
||
80 |
We can create a URI that ensures it has or does not have a trailing |
|
81 |
slash: |
|
82 |
||
83 |
>>> print proxied_uri1.ensureSlash() |
|
84 |
http://a/b/c/d;p/?q |
|
85 |
>>> print proxied_uri1.ensureNoSlash() |
|
86 |
http://a/b/c/d;p?q |