cherrypy-foundation 1.0.0a4__py3-none-any.whl → 1.0.0a5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,11 +3,12 @@
3
3
  <title>test-url</title>
4
4
  </head>
5
5
  <body>
6
- Empty: {{ url_for(".", **kwargs) }}<br/>
6
+ Empty: {{ url_for("", **kwargs) }}<br/>
7
7
  Dot: {{ url_for(".", **kwargs) }}<br/>
8
+ Dot page: {{ url_for(".", "my-page", **kwargs) }}<br/>
8
9
  Slash: {{ url_for("/", **kwargs) }}<br/>
9
10
  Page: {{ url_for("my-page", **kwargs) }}<br/>
10
- Absolute page: {{ url_for("/my-page", **kwargs) }}<br/>
11
+ Slash page: {{ url_for("/my-page", **kwargs) }}<br/>
11
12
  Query: {{ url_for("my-page", foo='1', bar='test with space', **kwargs) }}<br/>
12
13
  </body>
13
14
  </html>
@@ -34,7 +34,8 @@ class SubPage:
34
34
  @cherrypy.expose
35
35
  @cherrypy.tools.jinja2(template='test_url.html')
36
36
  def index(self, **kwargs):
37
- return {'kwargs': kwargs}
37
+ _relative = cherrypy.request.headers.get('-Relative')
38
+ return {'kwargs': {'_relative': _relative or None}}
38
39
 
39
40
 
40
41
  @cherrypy.tools.proxy(base='https://www.example.com')
@@ -43,7 +44,8 @@ class ProxiedPage:
43
44
  @cherrypy.expose
44
45
  @cherrypy.tools.jinja2(template='test_url.html')
45
46
  def index(self, **kwargs):
46
- return {'kwargs': kwargs}
47
+ _relative = cherrypy.request.headers.get('-Relative')
48
+ return {'kwargs': {'_relative': _relative or None}}
47
49
 
48
50
 
49
51
  @cherrypy.tools.jinja2(env=env)
@@ -54,7 +56,8 @@ class Root:
54
56
  @cherrypy.expose
55
57
  @cherrypy.tools.jinja2(template='test_url.html')
56
58
  def index(self, **kwargs):
57
- return {'kwargs': kwargs}
59
+ _relative = cherrypy.request.headers.get('-Relative')
60
+ return {'kwargs': {'_relative': _relative or None}}
58
61
 
59
62
 
60
63
  class UrlTest(helper.CPWebCase):
@@ -87,15 +90,16 @@ class UrlTest(helper.CPWebCase):
87
90
  # 2. Check user field
88
91
  self.assertInBody(f'Empty: http://{self.HOST}:{self.PORT}/')
89
92
  self.assertInBody(f'Dot: http://{self.HOST}:{self.PORT}/')
93
+ self.assertInBody(f'Dot page: http://{self.HOST}:{self.PORT}/my-page')
90
94
  self.assertInBody(f'Slash: http://{self.HOST}:{self.PORT}/')
91
95
  self.assertInBody(f'Page: http://{self.HOST}:{self.PORT}/my-page')
92
- self.assertInBody(f'Absolute page: http://{self.HOST}:{self.PORT}/my-page')
96
+ self.assertInBody(f'Slash page: http://{self.HOST}:{self.PORT}/my-page')
93
97
  self.assertInBody(f'Query: http://{self.HOST}:{self.PORT}/my-page?bar=test+with+space&amp;foo=1')
94
98
 
95
99
  def test_get_page_relative_true(self):
96
100
  # Given a form
97
101
  # When querying the page that include this form
98
- self.getPage("/?_relative=1")
102
+ self.getPage("/", headers=[('_relative', '1')])
99
103
  self.assertStatus(200)
100
104
  # Then each field is render properly.
101
105
  # 1. Check title
@@ -103,15 +107,16 @@ class UrlTest(helper.CPWebCase):
103
107
  # 2. Check user field
104
108
  self.assertInBody('Empty: <br/>')
105
109
  self.assertInBody('Dot: <br/>')
110
+ self.assertInBody('Dot page: my-page<br/>')
106
111
  self.assertInBody('Slash: <br/>')
107
112
  self.assertInBody('Page: my-page<br/>')
108
- self.assertInBody('Absolute page: my-page<br/>')
113
+ self.assertInBody('Slash page: my-page<br/>')
109
114
  self.assertInBody('Query: my-page?bar=test+with+space&amp;foo=1<br/>')
110
115
 
111
116
  def test_get_page_relative_server(self):
112
117
  # Given a form
113
118
  # When querying the page that include this form
114
- self.getPage("/?_relative=server")
119
+ self.getPage("/", headers=[('_relative', 'server')])
115
120
  self.assertStatus(200)
116
121
  # Then each field is render properly.
117
122
  # 1. Check title
@@ -119,9 +124,10 @@ class UrlTest(helper.CPWebCase):
119
124
  # 2. Check user field
120
125
  self.assertInBody('Empty: /<br/>')
121
126
  self.assertInBody('Dot: /<br/>')
127
+ self.assertInBody('Dot page: /my-page<br/>')
122
128
  self.assertInBody('Slash: /<br/>')
123
129
  self.assertInBody('Page: /my-page<br/>')
124
- self.assertInBody('Absolute page: /my-page<br/>')
130
+ self.assertInBody('Slash page: /my-page<br/>')
125
131
  self.assertInBody('Query: /my-page?bar=test+with+space&amp;foo=1<br/>')
126
132
 
127
133
  def test_get_page_proxied(self):
@@ -133,12 +139,13 @@ class UrlTest(helper.CPWebCase):
133
139
  # 1. Check title
134
140
  self.assertInBody('test-url')
135
141
  # 2. Check user field
136
- self.assertInBody('Empty: https://www.example.com/proxied/')
142
+ self.assertInBody('Empty: https://www.example.com/')
137
143
  self.assertInBody('Dot: https://www.example.com/proxied/')
144
+ self.assertInBody('Dot page: https://www.example.com/proxied/my-page<br/>')
138
145
  self.assertInBody('Slash: https://www.example.com/')
139
- self.assertInBody('Page: https://www.example.com/proxied/my-page')
140
- self.assertInBody('Absolute page: https://www.example.com/my-page')
141
- self.assertInBody('Query: https://www.example.com/proxied/my-page?bar=test+with+space&amp;foo=1')
146
+ self.assertInBody('Page: https://www.example.com/my-page')
147
+ self.assertInBody('Slash page: https://www.example.com/my-page')
148
+ self.assertInBody('Query: https://www.example.com/my-page?bar=test+with+space&amp;foo=1')
142
149
 
143
150
  def test_get_sub_page(self):
144
151
  # Given a form
@@ -151,7 +158,8 @@ class UrlTest(helper.CPWebCase):
151
158
  # 2. Check user field
152
159
  self.assertInBody(f'Empty: http://{self.HOST}:{self.PORT}/sub-page/')
153
160
  self.assertInBody(f'Dot: http://{self.HOST}:{self.PORT}/sub-page/')
161
+ self.assertInBody(f'Dot page: http://{self.HOST}:{self.PORT}/sub-page/my-page')
154
162
  self.assertInBody(f'Slash: http://{self.HOST}:{self.PORT}/')
155
- self.assertInBody(f'Page: http://{self.HOST}:{self.PORT}/sub-page/my-page')
156
- self.assertInBody(f'Absolute page: http://{self.HOST}:{self.PORT}/my-page')
157
- self.assertInBody(f'Query: http://{self.HOST}:{self.PORT}/sub-page/my-page?bar=test+with+space&amp;foo=1')
163
+ self.assertInBody(f'Page: http://{self.HOST}:{self.PORT}/my-page')
164
+ self.assertInBody(f'Slash page: http://{self.HOST}:{self.PORT}/my-page')
165
+ self.assertInBody(f'Query: http://{self.HOST}:{self.PORT}/my-page?bar=test+with+space&amp;foo=1')
@@ -35,6 +35,9 @@ def url_for(*args, _relative=None, _base=None, **kwargs):
35
35
  - Integers are appended as path segments.
36
36
  - When path == "", existing request query parameters are merged (kwargs win).
37
37
  """
38
+ # Handle query-string
39
+ qs = [(k, v) for k, v in sorted(kwargs.items()) if v is not None]
40
+
38
41
  path = []
39
42
  for chunk in args:
40
43
  if hasattr(chunk, '__url_for__') and callable(chunk.__url_for__):
@@ -54,11 +57,10 @@ def url_for(*args, _relative=None, _base=None, **kwargs):
54
57
  params = cherrypy.request.params.copy()
55
58
  params.update(kwargs)
56
59
  qs = [(k, v) for k, v in sorted(params.items()) if v is not None]
57
- else:
58
- qs = [(k, v) for k, v in sorted(kwargs.items()) if v is not None]
60
+ elif not path.startswith('.'):
61
+ path = urljoin('/', path)
59
62
  # Outside a request, use cherrypy.tools.proxy config
60
63
  if not cherrypy.request.app:
61
- path = urljoin('/', path)
62
64
  if _base is None:
63
65
  _base = cherrypy.config.get('tools.proxy.base', None)
64
66
  # Use cherrypy to build the URL
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cherrypy-foundation
3
- Version: 1.0.0a4
3
+ Version: 1.0.0a5
4
4
  Summary: CherryPy Foundation
5
5
  Author-email: Patrik Dufresne <patrik@ikus-soft.com>
6
6
  License: GPLv3
@@ -4,7 +4,7 @@ cherrypy_foundation/flash.py,sha256=fFRbutUX6c1lVHqjehmO9y98dJgmfNCjhd76t2mth2s,
4
4
  cherrypy_foundation/form.py,sha256=8c9dO0o47sK3CBosTkGXoVRtzNQwY0aw0vNZfTqmhvo,3994
5
5
  cherrypy_foundation/logging.py,sha256=YIOK5ZAZLCv52YDdP66yBYpEX1C336JnI3wnrTKl1Lw,3468
6
6
  cherrypy_foundation/passwd.py,sha256=ZGdrBNKtLP75l01W6VEd8cIjSQ3guJ_YVPEfbSew7T0,2144
7
- cherrypy_foundation/url.py,sha256=sC3DOZApIcapiIiqcUZ83LI1UFyc_f06TER-qJP-xCs,3026
7
+ cherrypy_foundation/url.py,sha256=kpmZfsYEaj94Kdw82DADNReaV65RJsH21mWDO2UOd5w,3074
8
8
  cherrypy_foundation/widgets.py,sha256=0B5Y2V6x5Ufl6ExR3tc0Olrzj7N4TAAOtqGq_MUxBG0,1549
9
9
  cherrypy_foundation/components/ColorModes.jinja,sha256=8MzkeZsra1wtIdiaQKc7UQUbMfRMUlmM6e9X7V1vfq0,3501
10
10
  cherrypy_foundation/components/Datatable.css,sha256=7wSwgdA61vYCdEuQ0bp2o0oSvu5mGLN1c6ovCUSe718,947
@@ -93,9 +93,9 @@ cherrypy_foundation/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
93
93
  cherrypy_foundation/tests/test_error_page.py,sha256=8u5p6lv_I4XvfGipjJXNFwW7G1N8AK8IOnc_Th-Ebto,2181
94
94
  cherrypy_foundation/tests/test_form.py,sha256=KvVA7OEqaDR-A-1EJdA-WlXkqyK9YJkRHhoUvGx1zr8,4269
95
95
  cherrypy_foundation/tests/test_passwd.py,sha256=gC5O4yhHyU1YRYuDc0pG0T_5zvrG2qrr6P822iyK3Rg,1956
96
- cherrypy_foundation/tests/test_url.py,sha256=bjq9mCyuYpsykPYLGmgOjvP4RlFywIsRdTNslndcQoE,6025
96
+ cherrypy_foundation/tests/test_url.py,sha256=YXhCYBeOgX35lTkFYSimL4qaF_0ZLKLN3tarQhmx0rU,6624
97
97
  cherrypy_foundation/tests/templates/test_form.html,sha256=sm-n2cYvih2vbDE4Y8kkERSoulnKAbwoefbzBggMMnA,189
98
- cherrypy_foundation/tests/templates/test_url.html,sha256=nbDwrB9F-dVyn3cqcV2-5-ZOqQH55lgUi1cpVuAJh_o,443
98
+ cherrypy_foundation/tests/templates/test_url.html,sha256=Rb6NokHEduMHAXO8P6EduMMHXuNzJGN5Of2OF4fSWns,502
99
99
  cherrypy_foundation/tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
100
100
  cherrypy_foundation/tools/auth.py,sha256=lTSajxCiReMzm-Fl-xhTByi4yFnInEWOoNsmUMnHQhs,9761
101
101
  cherrypy_foundation/tools/auth_mfa.py,sha256=VaLvBz9wo6jTx-2mCGqFXPxl-z14f8UMWvd6_xeXd40,9212
@@ -120,8 +120,8 @@ cherrypy_foundation/tools/tests/locales/fr/LC_MESSAGES/messages.po,sha256=6_Sk9I
120
120
  cherrypy_foundation/tools/tests/templates/test_jinja2.html,sha256=v9AHxksbBvzE7sesPqE61HMhsvU4juXt3E0ZQo-zXVQ,190
121
121
  cherrypy_foundation/tools/tests/templates/test_jinja2_i18n.html,sha256=98S51dgG7Vb4rvMZNZvomw1D9pBiM4g6pdlxAgvrxXA,373
122
122
  cherrypy_foundation/tools/tests/templates/test_jinjax.html,sha256=NT19UaUzm8FRKOIc6H6HNGPDJU6KATnakd8zf3BCeAs,153
123
- cherrypy_foundation-1.0.0a4.dist-info/licenses/LICENSE.md,sha256=trSLYs5qlaow_bBwsLTRKpmTXsXzFksM_YUCMqrgAJQ,35149
124
- cherrypy_foundation-1.0.0a4.dist-info/METADATA,sha256=_72IwEjxgvFKdSmIFT0-NZRQrHqzL4MwbGTCSF9ZiX8,2022
125
- cherrypy_foundation-1.0.0a4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
126
- cherrypy_foundation-1.0.0a4.dist-info/top_level.txt,sha256=B1vQPTLYhpKJ6W0JkRCWyAf8RPcnwJWdYxixv75-4ew,20
127
- cherrypy_foundation-1.0.0a4.dist-info/RECORD,,
123
+ cherrypy_foundation-1.0.0a5.dist-info/licenses/LICENSE.md,sha256=trSLYs5qlaow_bBwsLTRKpmTXsXzFksM_YUCMqrgAJQ,35149
124
+ cherrypy_foundation-1.0.0a5.dist-info/METADATA,sha256=r_lyZ6WWQth8Dhp0PH9gjqI75NcJjXKCbUfjUxMdpAk,2022
125
+ cherrypy_foundation-1.0.0a5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
126
+ cherrypy_foundation-1.0.0a5.dist-info/top_level.txt,sha256=B1vQPTLYhpKJ6W0JkRCWyAf8RPcnwJWdYxixv75-4ew,20
127
+ cherrypy_foundation-1.0.0a5.dist-info/RECORD,,