Merge lp:~kernevil/ubuntu/saucy/pylons/fix-useless-import into lp:ubuntu/saucy/pylons
- Saucy (13.10)
- fix-useless-import
- Merge into saucy
Proposed by
Kernevil
Status: | Needs review |
---|---|
Proposed branch: | lp:~kernevil/ubuntu/saucy/pylons/fix-useless-import |
Merge into: | lp:ubuntu/saucy/pylons |
Diff against target: |
366 lines (+246/-18) 10 files modified
.pc/.quilt_patches (+1/-0) .pc/.quilt_series (+1/-0) .pc/applied-patches (+1/-0) .pc/fix-useless-import.patch/pylons/decorators/__init__.py (+207/-0) debian/changelog (+6/-0) debian/patches/fix-useless-import.patch (+12/-0) debian/patches/ipython_0.11_compatibility.patch (+4/-4) debian/patches/move_data_outside_site-packages.patch (+13/-13) debian/patches/series (+1/-0) pylons/decorators/__init__.py (+0/-1) |
To merge this branch: | bzr merge lp:~kernevil/ubuntu/saucy/pylons/fix-useless-import |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Sebastien Bacher | Needs Fixing | ||
Review via email: mp+211046@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file '.pc/.quilt_patches' | |||
2 | --- .pc/.quilt_patches 1970-01-01 00:00:00 +0000 | |||
3 | +++ .pc/.quilt_patches 2014-03-14 14:46:27 +0000 | |||
4 | @@ -0,0 +1,1 @@ | |||
5 | 1 | debian/patches | ||
6 | 0 | 2 | ||
7 | === added file '.pc/.quilt_series' | |||
8 | --- .pc/.quilt_series 1970-01-01 00:00:00 +0000 | |||
9 | +++ .pc/.quilt_series 2014-03-14 14:46:27 +0000 | |||
10 | @@ -0,0 +1,1 @@ | |||
11 | 1 | series | ||
12 | 0 | 2 | ||
13 | === modified file '.pc/applied-patches' | |||
14 | --- .pc/applied-patches 2011-08-02 21:17:36 +0000 | |||
15 | +++ .pc/applied-patches 2014-03-14 14:46:27 +0000 | |||
16 | @@ -1,2 +1,3 @@ | |||
17 | 1 | move_data_outside_site-packages.patch | 1 | move_data_outside_site-packages.patch |
18 | 2 | ipython_0.11_compatibility.patch | 2 | ipython_0.11_compatibility.patch |
19 | 3 | fix-useless-import.patch | ||
20 | 3 | 4 | ||
21 | === added directory '.pc/fix-useless-import.patch' | |||
22 | === added file '.pc/fix-useless-import.patch/.timestamp' | |||
23 | === added directory '.pc/fix-useless-import.patch/pylons' | |||
24 | === added directory '.pc/fix-useless-import.patch/pylons/decorators' | |||
25 | === added file '.pc/fix-useless-import.patch/pylons/decorators/__init__.py' | |||
26 | --- .pc/fix-useless-import.patch/pylons/decorators/__init__.py 1970-01-01 00:00:00 +0000 | |||
27 | +++ .pc/fix-useless-import.patch/pylons/decorators/__init__.py 2014-03-14 14:46:27 +0000 | |||
28 | @@ -0,0 +1,207 @@ | |||
29 | 1 | """Pylons Decorators | ||
30 | 2 | |||
31 | 3 | Common decorators intended for use in controllers. Additional | ||
32 | 4 | decorators for use with controllers are in the | ||
33 | 5 | :mod:`~pylons.decorators.cache`, :mod:`~pylons.decorators.rest` and | ||
34 | 6 | :mod:`~pylons.decorators.secure` modules. | ||
35 | 7 | |||
36 | 8 | """ | ||
37 | 9 | import logging | ||
38 | 10 | import sys | ||
39 | 11 | import warnings | ||
40 | 12 | |||
41 | 13 | import formencode | ||
42 | 14 | import simplejson | ||
43 | 15 | from decorator import decorator | ||
44 | 16 | from formencode import api, htmlfill, variabledecode | ||
45 | 17 | from webob.multidict import UnicodeMultiDict | ||
46 | 18 | |||
47 | 19 | from pylons.decorators.util import get_pylons | ||
48 | 20 | from pylons.i18n import _ as pylons_gettext | ||
49 | 21 | |||
50 | 22 | __all__ = ['jsonify', 'validate'] | ||
51 | 23 | |||
52 | 24 | log = logging.getLogger(__name__) | ||
53 | 25 | |||
54 | 26 | @decorator | ||
55 | 27 | def jsonify(func, *args, **kwargs): | ||
56 | 28 | """Action decorator that formats output for JSON | ||
57 | 29 | |||
58 | 30 | Given a function that will return content, this decorator will turn | ||
59 | 31 | the result into JSON, with a content-type of 'application/json' and | ||
60 | 32 | output it. | ||
61 | 33 | |||
62 | 34 | """ | ||
63 | 35 | pylons = get_pylons(args) | ||
64 | 36 | pylons.response.headers['Content-Type'] = 'application/json' | ||
65 | 37 | data = func(*args, **kwargs) | ||
66 | 38 | if isinstance(data, (list, tuple)): | ||
67 | 39 | msg = "JSON responses with Array envelopes are susceptible to " \ | ||
68 | 40 | "cross-site data leak attacks, see " \ | ||
69 | 41 | "http://pylonshq.com/warnings/JSONArray" | ||
70 | 42 | warnings.warn(msg, Warning, 2) | ||
71 | 43 | log.warning(msg) | ||
72 | 44 | log.debug("Returning JSON wrapped action output") | ||
73 | 45 | return simplejson.dumps(data) | ||
74 | 46 | |||
75 | 47 | |||
76 | 48 | def validate(schema=None, validators=None, form=None, variable_decode=False, | ||
77 | 49 | dict_char='.', list_char='-', post_only=True, state=None, | ||
78 | 50 | on_get=False, **htmlfill_kwargs): | ||
79 | 51 | """Validate input either for a FormEncode schema, or individual | ||
80 | 52 | validators | ||
81 | 53 | |||
82 | 54 | Given a form schema or dict of validators, validate will attempt to | ||
83 | 55 | validate the schema or validator list. | ||
84 | 56 | |||
85 | 57 | If validation was successful, the valid result dict will be saved | ||
86 | 58 | as ``self.form_result``. Otherwise, the action will be re-run as if | ||
87 | 59 | it was a GET, and the output will be filled by FormEncode's | ||
88 | 60 | htmlfill to fill in the form field errors. | ||
89 | 61 | |||
90 | 62 | ``schema`` | ||
91 | 63 | Refers to a FormEncode Schema object to use during validation. | ||
92 | 64 | ``form`` | ||
93 | 65 | Method used to display the form, which will be used to get the | ||
94 | 66 | HTML representation of the form for error filling. | ||
95 | 67 | ``variable_decode`` | ||
96 | 68 | Boolean to indicate whether FormEncode's variable decode | ||
97 | 69 | function should be run on the form input before validation. | ||
98 | 70 | ``dict_char`` | ||
99 | 71 | Passed through to FormEncode. Toggles the form field naming | ||
100 | 72 | scheme used to determine what is used to represent a dict. This | ||
101 | 73 | option is only applicable when used with variable_decode=True. | ||
102 | 74 | ``list_char`` | ||
103 | 75 | Passed through to FormEncode. Toggles the form field naming | ||
104 | 76 | scheme used to determine what is used to represent a list. This | ||
105 | 77 | option is only applicable when used with variable_decode=True. | ||
106 | 78 | ``post_only`` | ||
107 | 79 | Boolean that indicates whether or not GET (query) variables | ||
108 | 80 | should be included during validation. | ||
109 | 81 | |||
110 | 82 | .. warning:: | ||
111 | 83 | ``post_only`` applies to *where* the arguments to be | ||
112 | 84 | validated come from. It does *not* restrict the form to | ||
113 | 85 | only working with post, merely only checking POST vars. | ||
114 | 86 | ``state`` | ||
115 | 87 | Passed through to FormEncode for use in validators that utilize | ||
116 | 88 | a state object. | ||
117 | 89 | ``on_get`` | ||
118 | 90 | Whether to validate on GET requests. By default only POST | ||
119 | 91 | requests are validated. | ||
120 | 92 | |||
121 | 93 | Example:: | ||
122 | 94 | |||
123 | 95 | class SomeController(BaseController): | ||
124 | 96 | |||
125 | 97 | def create(self, id): | ||
126 | 98 | return render('/myform.mako') | ||
127 | 99 | |||
128 | 100 | @validate(schema=model.forms.myshema(), form='create') | ||
129 | 101 | def update(self, id): | ||
130 | 102 | # Do something with self.form_result | ||
131 | 103 | pass | ||
132 | 104 | |||
133 | 105 | """ | ||
134 | 106 | if state is None: | ||
135 | 107 | state = PylonsFormEncodeState | ||
136 | 108 | def wrapper(func, self, *args, **kwargs): | ||
137 | 109 | """Decorator Wrapper function""" | ||
138 | 110 | request = self._py_object.request | ||
139 | 111 | errors = {} | ||
140 | 112 | |||
141 | 113 | # Skip the validation if on_get is False and its a GET | ||
142 | 114 | if not on_get and request.environ['REQUEST_METHOD'] == 'GET': | ||
143 | 115 | return func(self, *args, **kwargs) | ||
144 | 116 | |||
145 | 117 | # If they want post args only, use just the post args | ||
146 | 118 | if post_only: | ||
147 | 119 | params = request.POST | ||
148 | 120 | else: | ||
149 | 121 | params = request.params | ||
150 | 122 | |||
151 | 123 | params = params.mixed() | ||
152 | 124 | if variable_decode: | ||
153 | 125 | log.debug("Running variable_decode on params") | ||
154 | 126 | decoded = variabledecode.variable_decode(params, dict_char, | ||
155 | 127 | list_char) | ||
156 | 128 | else: | ||
157 | 129 | decoded = params | ||
158 | 130 | |||
159 | 131 | if schema: | ||
160 | 132 | log.debug("Validating against a schema") | ||
161 | 133 | try: | ||
162 | 134 | self.form_result = schema.to_python(decoded, state) | ||
163 | 135 | except formencode.Invalid, e: | ||
164 | 136 | errors = e.unpack_errors(variable_decode, dict_char, list_char) | ||
165 | 137 | if validators: | ||
166 | 138 | log.debug("Validating against provided validators") | ||
167 | 139 | if isinstance(validators, dict): | ||
168 | 140 | if not hasattr(self, 'form_result'): | ||
169 | 141 | self.form_result = {} | ||
170 | 142 | for field, validator in validators.iteritems(): | ||
171 | 143 | try: | ||
172 | 144 | self.form_result[field] = \ | ||
173 | 145 | validator.to_python(decoded.get(field), state) | ||
174 | 146 | except formencode.Invalid, error: | ||
175 | 147 | errors[field] = error | ||
176 | 148 | if errors: | ||
177 | 149 | log.debug("Errors found in validation, parsing form with htmlfill " | ||
178 | 150 | "for errors") | ||
179 | 151 | request.environ['REQUEST_METHOD'] = 'GET' | ||
180 | 152 | self._py_object.tmpl_context.form_errors = errors | ||
181 | 153 | |||
182 | 154 | # If there's no form supplied, just continue with the current | ||
183 | 155 | # function call. | ||
184 | 156 | if not form: | ||
185 | 157 | return func(self, *args, **kwargs) | ||
186 | 158 | |||
187 | 159 | request.environ['pylons.routes_dict']['action'] = form | ||
188 | 160 | response = self._dispatch_call() | ||
189 | 161 | |||
190 | 162 | # If the form_content is an exception response, return it | ||
191 | 163 | if hasattr(response, '_exception'): | ||
192 | 164 | return response | ||
193 | 165 | |||
194 | 166 | htmlfill_kwargs2 = htmlfill_kwargs.copy() | ||
195 | 167 | htmlfill_kwargs2.setdefault('encoding', request.charset) | ||
196 | 168 | return htmlfill.render(response, defaults=params, errors=errors, | ||
197 | 169 | **htmlfill_kwargs2) | ||
198 | 170 | return func(self, *args, **kwargs) | ||
199 | 171 | return decorator(wrapper) | ||
200 | 172 | |||
201 | 173 | |||
202 | 174 | def pylons_formencode_gettext(value): | ||
203 | 175 | """Translates a string ``value`` using pylons gettext first and if | ||
204 | 176 | that fails, formencode gettext. | ||
205 | 177 | |||
206 | 178 | This allows to "merge" localized error messages from built-in | ||
207 | 179 | FormEncode's validators with application-specific validators. | ||
208 | 180 | |||
209 | 181 | """ | ||
210 | 182 | trans = pylons_gettext(value) | ||
211 | 183 | if trans == value: | ||
212 | 184 | # translation failed, try formencode | ||
213 | 185 | trans = api._stdtrans(value) | ||
214 | 186 | return trans | ||
215 | 187 | |||
216 | 188 | |||
217 | 189 | class PylonsFormEncodeState(object): | ||
218 | 190 | """A ``state`` for FormEncode validate API that includes smart | ||
219 | 191 | ``_`` hook. | ||
220 | 192 | |||
221 | 193 | The FormEncode library used by validate() decorator has some | ||
222 | 194 | provision for localizing error messages. In particular, it looks | ||
223 | 195 | for attribute ``_`` in the application-specific state object that | ||
224 | 196 | gets passed to every ``.to_python()`` call. If it is found, the | ||
225 | 197 | ``_`` is assumed to be a gettext-like function and is called to | ||
226 | 198 | localize error messages. | ||
227 | 199 | |||
228 | 200 | One complication is that FormEncode ships with localized error | ||
229 | 201 | messages for standard validators so the user may want to re-use | ||
230 | 202 | them instead of gathering and translating everything from scratch. | ||
231 | 203 | To allow this, we pass as ``_`` a function which looks up | ||
232 | 204 | translation both in application and formencode message catalogs. | ||
233 | 205 | |||
234 | 206 | """ | ||
235 | 207 | _ = staticmethod(pylons_formencode_gettext) | ||
236 | 0 | 208 | ||
237 | === added file '.pc/ipython_0.11_compatibility.patch/.timestamp' | |||
238 | === added file '.pc/move_data_outside_site-packages.patch/.timestamp' | |||
239 | === modified file 'debian/changelog' | |||
240 | --- debian/changelog 2011-08-02 21:17:36 +0000 | |||
241 | +++ debian/changelog 2014-03-14 14:46:27 +0000 | |||
242 | @@ -1,3 +1,9 @@ | |||
243 | 1 | pylons (1.0-3) unstable; urgency=low | ||
244 | 2 | |||
245 | 3 | * Add fix-useless-import.patch (closes: #1292505) | ||
246 | 4 | |||
247 | 5 | -- Samuel Cabrero <scabrero@zentyal.com> Fri, 14 Mar 2014 15:28:15 +0100 | ||
248 | 6 | |||
249 | 1 | pylons (1.0-2) unstable; urgency=low | 7 | pylons (1.0-2) unstable; urgency=low |
250 | 2 | 8 | ||
251 | 3 | * Add ipython_0.11_compatibility patch (thanks to Julian Taylor) | 9 | * Add ipython_0.11_compatibility patch (thanks to Julian Taylor) |
252 | 4 | 10 | ||
253 | === added file 'debian/patches/fix-useless-import.patch' | |||
254 | --- debian/patches/fix-useless-import.patch 1970-01-01 00:00:00 +0000 | |||
255 | +++ debian/patches/fix-useless-import.patch 2014-03-14 14:46:27 +0000 | |||
256 | @@ -0,0 +1,12 @@ | |||
257 | 1 | Index: fix-useless-import/pylons/decorators/__init__.py | ||
258 | 2 | =================================================================== | ||
259 | 3 | --- fix-useless-import.orig/pylons/decorators/__init__.py 2014-03-14 15:25:49.079736000 +0100 | ||
260 | 4 | +++ fix-useless-import/pylons/decorators/__init__.py 2014-03-14 15:26:55.106453748 +0100 | ||
261 | 5 | @@ -14,7 +14,6 @@ | ||
262 | 6 | import simplejson | ||
263 | 7 | from decorator import decorator | ||
264 | 8 | from formencode import api, htmlfill, variabledecode | ||
265 | 9 | -from webob.multidict import UnicodeMultiDict | ||
266 | 10 | |||
267 | 11 | from pylons.decorators.util import get_pylons | ||
268 | 12 | from pylons.i18n import _ as pylons_gettext | ||
269 | 0 | 13 | ||
270 | === modified file 'debian/patches/ipython_0.11_compatibility.patch' | |||
271 | --- debian/patches/ipython_0.11_compatibility.patch 2011-08-02 21:17:36 +0000 | |||
272 | +++ debian/patches/ipython_0.11_compatibility.patch 2014-03-14 14:46:27 +0000 | |||
273 | @@ -1,8 +1,8 @@ | |||
275 | 1 | Index: pylons-0.10/pylons/commands.py | 1 | Index: fix-useless-import/pylons/commands.py |
276 | 2 | =================================================================== | 2 | =================================================================== |
280 | 3 | --- pylons-0.10.orig/pylons/commands.py 2011-07-24 15:28:25.708719706 +0200 | 3 | --- fix-useless-import.orig/pylons/commands.py 2014-03-14 15:43:20.402418528 +0100 |
281 | 4 | +++ pylons-0.10/pylons/commands.py 2011-07-24 15:28:31.848719709 +0200 | 4 | +++ fix-useless-import/pylons/commands.py 2014-03-14 15:43:20.398418528 +0100 |
282 | 5 | @@ -514,10 +514,14 @@ | 5 | @@ -560,10 +560,14 @@ |
283 | 6 | raise ImportError() | 6 | raise ImportError() |
284 | 7 | 7 | ||
285 | 8 | # try to use IPython if possible | 8 | # try to use IPython if possible |
286 | 9 | 9 | ||
287 | === modified file 'debian/patches/move_data_outside_site-packages.patch' | |||
288 | --- debian/patches/move_data_outside_site-packages.patch 2009-11-30 00:26:47 +0000 | |||
289 | +++ debian/patches/move_data_outside_site-packages.patch 2014-03-14 14:46:27 +0000 | |||
290 | @@ -3,11 +3,11 @@ | |||
291 | 3 | # note that paster is modified in Debian to look for templates in | 3 | # note that paster is modified in Debian to look for templates in |
292 | 4 | # /usr/share/paster_templates/ so this part of the code doesn't have to | 4 | # /usr/share/paster_templates/ so this part of the code doesn't have to |
293 | 5 | # be patched | 5 | # be patched |
295 | 6 | Index: pylons-0.9.7/setup.py | 6 | Index: fix-useless-import/setup.py |
296 | 7 | =================================================================== | 7 | =================================================================== |
300 | 8 | --- pylons-0.9.7.orig/setup.py | 8 | --- fix-useless-import.orig/setup.py 2014-03-14 15:43:20.382418528 +0100 |
301 | 9 | +++ pylons-0.9.7/setup.py | 9 | +++ fix-useless-import/setup.py 2014-03-14 15:43:20.378418529 +0100 |
302 | 10 | @@ -74,7 +74,7 @@ the `Pylons download page <http://pylons | 10 | @@ -74,7 +74,7 @@ |
303 | 11 | url='http://www.pylonshq.com/', | 11 | url='http://www.pylonshq.com/', |
304 | 12 | packages=find_packages(exclude=['ez_setup', 'tests', 'tests.*']), | 12 | packages=find_packages(exclude=['ez_setup', 'tests', 'tests.*']), |
305 | 13 | zip_safe=False, | 13 | zip_safe=False, |
306 | @@ -16,11 +16,11 @@ | |||
307 | 16 | test_suite='nose.collector', | 16 | test_suite='nose.collector', |
308 | 17 | tests_require=tests_require, | 17 | tests_require=tests_require, |
309 | 18 | install_requires=[ | 18 | install_requires=[ |
311 | 19 | Index: pylons-0.9.7/pylons/middleware.py | 19 | Index: fix-useless-import/pylons/middleware.py |
312 | 20 | =================================================================== | 20 | =================================================================== |
316 | 21 | --- pylons-0.9.7.orig/pylons/middleware.py | 21 | --- fix-useless-import.orig/pylons/middleware.py 2014-03-14 15:43:20.382418528 +0100 |
317 | 22 | +++ pylons-0.9.7/pylons/middleware.py | 22 | +++ fix-useless-import/pylons/middleware.py 2014-03-14 15:43:20.378418529 +0100 |
318 | 23 | @@ -24,7 +24,7 @@ __all__ = ['ErrorDocuments', 'ErrorHandl | 23 | @@ -18,7 +18,7 @@ |
319 | 24 | 24 | ||
320 | 25 | log = logging.getLogger(__name__) | 25 | log = logging.getLogger(__name__) |
321 | 26 | 26 | ||
322 | @@ -29,11 +29,11 @@ | |||
323 | 29 | 29 | ||
324 | 30 | head_html = """\ | 30 | head_html = """\ |
325 | 31 | <link rel="stylesheet" href="{{prefix}}/media/pylons/style/itraceback.css" \ | 31 | <link rel="stylesheet" href="{{prefix}}/media/pylons/style/itraceback.css" \ |
327 | 32 | Index: pylons-0.9.7/pylons/commands.py | 32 | Index: fix-useless-import/pylons/commands.py |
328 | 33 | =================================================================== | 33 | =================================================================== |
332 | 34 | --- pylons-0.9.7.orig/pylons/commands.py | 34 | --- fix-useless-import.orig/pylons/commands.py 2014-03-14 15:43:20.382418528 +0100 |
333 | 35 | +++ pylons-0.9.7/pylons/commands.py | 35 | +++ fix-useless-import/pylons/commands.py 2014-03-14 15:43:29.000000000 +0100 |
334 | 36 | @@ -169,7 +169,7 @@ class ControllerCommand(Command): | 36 | @@ -170,7 +170,7 @@ |
335 | 37 | def command(self): | 37 | def command(self): |
336 | 38 | """Main command to create controller""" | 38 | """Main command to create controller""" |
337 | 39 | try: | 39 | try: |
338 | @@ -42,7 +42,7 @@ | |||
339 | 42 | try: | 42 | try: |
340 | 43 | name, directory = file_op.parse_path_name_args(self.args[0]) | 43 | name, directory = file_op.parse_path_name_args(self.args[0]) |
341 | 44 | except: | 44 | except: |
343 | 45 | @@ -276,7 +276,7 @@ class RestControllerCommand(Command): | 45 | @@ -279,7 +279,7 @@ |
344 | 46 | def command(self): | 46 | def command(self): |
345 | 47 | """Main command to create controller""" | 47 | """Main command to create controller""" |
346 | 48 | try: | 48 | try: |
347 | 49 | 49 | ||
348 | === modified file 'debian/patches/series' | |||
349 | --- debian/patches/series 2011-08-02 21:17:36 +0000 | |||
350 | +++ debian/patches/series 2014-03-14 14:46:27 +0000 | |||
351 | @@ -1,2 +1,3 @@ | |||
352 | 1 | move_data_outside_site-packages.patch | 1 | move_data_outside_site-packages.patch |
353 | 2 | ipython_0.11_compatibility.patch | 2 | ipython_0.11_compatibility.patch |
354 | 3 | fix-useless-import.patch | ||
355 | 3 | 4 | ||
356 | === modified file 'pylons/decorators/__init__.py' | |||
357 | --- pylons/decorators/__init__.py 2011-08-02 21:17:36 +0000 | |||
358 | +++ pylons/decorators/__init__.py 2014-03-14 14:46:27 +0000 | |||
359 | @@ -14,7 +14,6 @@ | |||
360 | 14 | import simplejson | 14 | import simplejson |
361 | 15 | from decorator import decorator | 15 | from decorator import decorator |
362 | 16 | from formencode import api, htmlfill, variabledecode | 16 | from formencode import api, htmlfill, variabledecode |
363 | 17 | from webob.multidict import UnicodeMultiDict | ||
364 | 18 | 17 | ||
365 | 19 | from pylons.decorators.util import get_pylons | 18 | from pylons.decorators.util import get_pylons |
366 | 20 | from pylons.i18n import _ as pylons_gettext | 19 | from pylons.i18n import _ as pylons_gettext |
Thank you for your work there. The issue is fixed in trusty, if you want a stable update to saucy could you update the bug to include the SRU informations (https:/ /wiki.ubuntu. com/StableRelea seUpdates) and add a changelog entry to your update?