Merge lp:~kernevil/ubuntu/saucy/pylons/fix-useless-import into lp:ubuntu/saucy/pylons

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
Reviewer Review Type Date Requested Status
Sebastien Bacher Needs Fixing
Review via email: mp+211046@code.launchpad.net
To post a comment you must log in.
14. By Kernevil

Fix useless import

Revision history for this message
Sebastien Bacher (seb128) wrote :

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/StableReleaseUpdates) and add a changelog entry to your update?

review: Needs Fixing

Unmerged revisions

14. By Kernevil

Fix useless import

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file '.pc/.quilt_patches'
--- .pc/.quilt_patches 1970-01-01 00:00:00 +0000
+++ .pc/.quilt_patches 2014-03-14 14:46:27 +0000
@@ -0,0 +1,1 @@
1debian/patches
02
=== added file '.pc/.quilt_series'
--- .pc/.quilt_series 1970-01-01 00:00:00 +0000
+++ .pc/.quilt_series 2014-03-14 14:46:27 +0000
@@ -0,0 +1,1 @@
1series
02
=== modified file '.pc/applied-patches'
--- .pc/applied-patches 2011-08-02 21:17:36 +0000
+++ .pc/applied-patches 2014-03-14 14:46:27 +0000
@@ -1,2 +1,3 @@
1move_data_outside_site-packages.patch1move_data_outside_site-packages.patch
2ipython_0.11_compatibility.patch2ipython_0.11_compatibility.patch
3fix-useless-import.patch
34
=== added directory '.pc/fix-useless-import.patch'
=== added file '.pc/fix-useless-import.patch/.timestamp'
=== added directory '.pc/fix-useless-import.patch/pylons'
=== added directory '.pc/fix-useless-import.patch/pylons/decorators'
=== added file '.pc/fix-useless-import.patch/pylons/decorators/__init__.py'
--- .pc/fix-useless-import.patch/pylons/decorators/__init__.py 1970-01-01 00:00:00 +0000
+++ .pc/fix-useless-import.patch/pylons/decorators/__init__.py 2014-03-14 14:46:27 +0000
@@ -0,0 +1,207 @@
1"""Pylons Decorators
2
3Common decorators intended for use in controllers. Additional
4decorators for use with controllers are in the
5:mod:`~pylons.decorators.cache`, :mod:`~pylons.decorators.rest` and
6:mod:`~pylons.decorators.secure` modules.
7
8"""
9import logging
10import sys
11import warnings
12
13import formencode
14import simplejson
15from decorator import decorator
16from formencode import api, htmlfill, variabledecode
17from webob.multidict import UnicodeMultiDict
18
19from pylons.decorators.util import get_pylons
20from pylons.i18n import _ as pylons_gettext
21
22__all__ = ['jsonify', 'validate']
23
24log = logging.getLogger(__name__)
25
26@decorator
27def jsonify(func, *args, **kwargs):
28 """Action decorator that formats output for JSON
29
30 Given a function that will return content, this decorator will turn
31 the result into JSON, with a content-type of 'application/json' and
32 output it.
33
34 """
35 pylons = get_pylons(args)
36 pylons.response.headers['Content-Type'] = 'application/json'
37 data = func(*args, **kwargs)
38 if isinstance(data, (list, tuple)):
39 msg = "JSON responses with Array envelopes are susceptible to " \
40 "cross-site data leak attacks, see " \
41 "http://pylonshq.com/warnings/JSONArray"
42 warnings.warn(msg, Warning, 2)
43 log.warning(msg)
44 log.debug("Returning JSON wrapped action output")
45 return simplejson.dumps(data)
46
47
48def validate(schema=None, validators=None, form=None, variable_decode=False,
49 dict_char='.', list_char='-', post_only=True, state=None,
50 on_get=False, **htmlfill_kwargs):
51 """Validate input either for a FormEncode schema, or individual
52 validators
53
54 Given a form schema or dict of validators, validate will attempt to
55 validate the schema or validator list.
56
57 If validation was successful, the valid result dict will be saved
58 as ``self.form_result``. Otherwise, the action will be re-run as if
59 it was a GET, and the output will be filled by FormEncode's
60 htmlfill to fill in the form field errors.
61
62 ``schema``
63 Refers to a FormEncode Schema object to use during validation.
64 ``form``
65 Method used to display the form, which will be used to get the
66 HTML representation of the form for error filling.
67 ``variable_decode``
68 Boolean to indicate whether FormEncode's variable decode
69 function should be run on the form input before validation.
70 ``dict_char``
71 Passed through to FormEncode. Toggles the form field naming
72 scheme used to determine what is used to represent a dict. This
73 option is only applicable when used with variable_decode=True.
74 ``list_char``
75 Passed through to FormEncode. Toggles the form field naming
76 scheme used to determine what is used to represent a list. This
77 option is only applicable when used with variable_decode=True.
78 ``post_only``
79 Boolean that indicates whether or not GET (query) variables
80 should be included during validation.
81
82 .. warning::
83 ``post_only`` applies to *where* the arguments to be
84 validated come from. It does *not* restrict the form to
85 only working with post, merely only checking POST vars.
86 ``state``
87 Passed through to FormEncode for use in validators that utilize
88 a state object.
89 ``on_get``
90 Whether to validate on GET requests. By default only POST
91 requests are validated.
92
93 Example::
94
95 class SomeController(BaseController):
96
97 def create(self, id):
98 return render('/myform.mako')
99
100 @validate(schema=model.forms.myshema(), form='create')
101 def update(self, id):
102 # Do something with self.form_result
103 pass
104
105 """
106 if state is None:
107 state = PylonsFormEncodeState
108 def wrapper(func, self, *args, **kwargs):
109 """Decorator Wrapper function"""
110 request = self._py_object.request
111 errors = {}
112
113 # Skip the validation if on_get is False and its a GET
114 if not on_get and request.environ['REQUEST_METHOD'] == 'GET':
115 return func(self, *args, **kwargs)
116
117 # If they want post args only, use just the post args
118 if post_only:
119 params = request.POST
120 else:
121 params = request.params
122
123 params = params.mixed()
124 if variable_decode:
125 log.debug("Running variable_decode on params")
126 decoded = variabledecode.variable_decode(params, dict_char,
127 list_char)
128 else:
129 decoded = params
130
131 if schema:
132 log.debug("Validating against a schema")
133 try:
134 self.form_result = schema.to_python(decoded, state)
135 except formencode.Invalid, e:
136 errors = e.unpack_errors(variable_decode, dict_char, list_char)
137 if validators:
138 log.debug("Validating against provided validators")
139 if isinstance(validators, dict):
140 if not hasattr(self, 'form_result'):
141 self.form_result = {}
142 for field, validator in validators.iteritems():
143 try:
144 self.form_result[field] = \
145 validator.to_python(decoded.get(field), state)
146 except formencode.Invalid, error:
147 errors[field] = error
148 if errors:
149 log.debug("Errors found in validation, parsing form with htmlfill "
150 "for errors")
151 request.environ['REQUEST_METHOD'] = 'GET'
152 self._py_object.tmpl_context.form_errors = errors
153
154 # If there's no form supplied, just continue with the current
155 # function call.
156 if not form:
157 return func(self, *args, **kwargs)
158
159 request.environ['pylons.routes_dict']['action'] = form
160 response = self._dispatch_call()
161
162 # If the form_content is an exception response, return it
163 if hasattr(response, '_exception'):
164 return response
165
166 htmlfill_kwargs2 = htmlfill_kwargs.copy()
167 htmlfill_kwargs2.setdefault('encoding', request.charset)
168 return htmlfill.render(response, defaults=params, errors=errors,
169 **htmlfill_kwargs2)
170 return func(self, *args, **kwargs)
171 return decorator(wrapper)
172
173
174def pylons_formencode_gettext(value):
175 """Translates a string ``value`` using pylons gettext first and if
176 that fails, formencode gettext.
177
178 This allows to "merge" localized error messages from built-in
179 FormEncode's validators with application-specific validators.
180
181 """
182 trans = pylons_gettext(value)
183 if trans == value:
184 # translation failed, try formencode
185 trans = api._stdtrans(value)
186 return trans
187
188
189class PylonsFormEncodeState(object):
190 """A ``state`` for FormEncode validate API that includes smart
191 ``_`` hook.
192
193 The FormEncode library used by validate() decorator has some
194 provision for localizing error messages. In particular, it looks
195 for attribute ``_`` in the application-specific state object that
196 gets passed to every ``.to_python()`` call. If it is found, the
197 ``_`` is assumed to be a gettext-like function and is called to
198 localize error messages.
199
200 One complication is that FormEncode ships with localized error
201 messages for standard validators so the user may want to re-use
202 them instead of gathering and translating everything from scratch.
203 To allow this, we pass as ``_`` a function which looks up
204 translation both in application and formencode message catalogs.
205
206 """
207 _ = staticmethod(pylons_formencode_gettext)
0208
=== added file '.pc/ipython_0.11_compatibility.patch/.timestamp'
=== added file '.pc/move_data_outside_site-packages.patch/.timestamp'
=== modified file 'debian/changelog'
--- debian/changelog 2011-08-02 21:17:36 +0000
+++ debian/changelog 2014-03-14 14:46:27 +0000
@@ -1,3 +1,9 @@
1pylons (1.0-3) unstable; urgency=low
2
3 * Add fix-useless-import.patch (closes: #1292505)
4
5 -- Samuel Cabrero <scabrero@zentyal.com> Fri, 14 Mar 2014 15:28:15 +0100
6
1pylons (1.0-2) unstable; urgency=low7pylons (1.0-2) unstable; urgency=low
28
3 * Add ipython_0.11_compatibility patch (thanks to Julian Taylor)9 * Add ipython_0.11_compatibility patch (thanks to Julian Taylor)
410
=== added file 'debian/patches/fix-useless-import.patch'
--- debian/patches/fix-useless-import.patch 1970-01-01 00:00:00 +0000
+++ debian/patches/fix-useless-import.patch 2014-03-14 14:46:27 +0000
@@ -0,0 +1,12 @@
1Index: fix-useless-import/pylons/decorators/__init__.py
2===================================================================
3--- fix-useless-import.orig/pylons/decorators/__init__.py 2014-03-14 15:25:49.079736000 +0100
4+++ fix-useless-import/pylons/decorators/__init__.py 2014-03-14 15:26:55.106453748 +0100
5@@ -14,7 +14,6 @@
6 import simplejson
7 from decorator import decorator
8 from formencode import api, htmlfill, variabledecode
9-from webob.multidict import UnicodeMultiDict
10
11 from pylons.decorators.util import get_pylons
12 from pylons.i18n import _ as pylons_gettext
013
=== modified file 'debian/patches/ipython_0.11_compatibility.patch'
--- debian/patches/ipython_0.11_compatibility.patch 2011-08-02 21:17:36 +0000
+++ debian/patches/ipython_0.11_compatibility.patch 2014-03-14 14:46:27 +0000
@@ -1,8 +1,8 @@
1Index: pylons-0.10/pylons/commands.py1Index: fix-useless-import/pylons/commands.py
2===================================================================2===================================================================
3--- pylons-0.10.orig/pylons/commands.py 2011-07-24 15:28:25.708719706 +02003--- fix-useless-import.orig/pylons/commands.py 2014-03-14 15:43:20.402418528 +0100
4+++ pylons-0.10/pylons/commands.py 2011-07-24 15:28:31.848719709 +02004+++ fix-useless-import/pylons/commands.py 2014-03-14 15:43:20.398418528 +0100
5@@ -514,10 +514,14 @@5@@ -560,10 +560,14 @@
6 raise ImportError()6 raise ImportError()
7 7
8 # try to use IPython if possible8 # try to use IPython if possible
99
=== modified file 'debian/patches/move_data_outside_site-packages.patch'
--- debian/patches/move_data_outside_site-packages.patch 2009-11-30 00:26:47 +0000
+++ debian/patches/move_data_outside_site-packages.patch 2014-03-14 14:46:27 +0000
@@ -3,11 +3,11 @@
3# note that paster is modified in Debian to look for templates in3# note that paster is modified in Debian to look for templates in
4# /usr/share/paster_templates/ so this part of the code doesn't have to4# /usr/share/paster_templates/ so this part of the code doesn't have to
5# be patched5# be patched
6Index: pylons-0.9.7/setup.py6Index: fix-useless-import/setup.py
7===================================================================7===================================================================
8--- pylons-0.9.7.orig/setup.py8--- fix-useless-import.orig/setup.py 2014-03-14 15:43:20.382418528 +0100
9+++ pylons-0.9.7/setup.py9+++ fix-useless-import/setup.py 2014-03-14 15:43:20.378418529 +0100
10@@ -74,7 +74,7 @@ the `Pylons download page <http://pylons10@@ -74,7 +74,7 @@
11 url='http://www.pylonshq.com/',11 url='http://www.pylonshq.com/',
12 packages=find_packages(exclude=['ez_setup', 'tests', 'tests.*']),12 packages=find_packages(exclude=['ez_setup', 'tests', 'tests.*']),
13 zip_safe=False,13 zip_safe=False,
@@ -16,11 +16,11 @@
16 test_suite='nose.collector',16 test_suite='nose.collector',
17 tests_require=tests_require,17 tests_require=tests_require,
18 install_requires=[18 install_requires=[
19Index: pylons-0.9.7/pylons/middleware.py19Index: fix-useless-import/pylons/middleware.py
20===================================================================20===================================================================
21--- pylons-0.9.7.orig/pylons/middleware.py21--- fix-useless-import.orig/pylons/middleware.py 2014-03-14 15:43:20.382418528 +0100
22+++ pylons-0.9.7/pylons/middleware.py22+++ fix-useless-import/pylons/middleware.py 2014-03-14 15:43:20.378418529 +0100
23@@ -24,7 +24,7 @@ __all__ = ['ErrorDocuments', 'ErrorHandl23@@ -18,7 +18,7 @@
24 24
25 log = logging.getLogger(__name__)25 log = logging.getLogger(__name__)
26 26
@@ -29,11 +29,11 @@
29 29
30 head_html = """\30 head_html = """\
31 <link rel="stylesheet" href="{{prefix}}/media/pylons/style/itraceback.css" \31 <link rel="stylesheet" href="{{prefix}}/media/pylons/style/itraceback.css" \
32Index: pylons-0.9.7/pylons/commands.py32Index: fix-useless-import/pylons/commands.py
33===================================================================33===================================================================
34--- pylons-0.9.7.orig/pylons/commands.py34--- fix-useless-import.orig/pylons/commands.py 2014-03-14 15:43:20.382418528 +0100
35+++ pylons-0.9.7/pylons/commands.py35+++ fix-useless-import/pylons/commands.py 2014-03-14 15:43:29.000000000 +0100
36@@ -169,7 +169,7 @@ class ControllerCommand(Command):36@@ -170,7 +170,7 @@
37 def command(self):37 def command(self):
38 """Main command to create controller"""38 """Main command to create controller"""
39 try:39 try:
@@ -42,7 +42,7 @@
42 try:42 try:
43 name, directory = file_op.parse_path_name_args(self.args[0])43 name, directory = file_op.parse_path_name_args(self.args[0])
44 except:44 except:
45@@ -276,7 +276,7 @@ class RestControllerCommand(Command):45@@ -279,7 +279,7 @@
46 def command(self):46 def command(self):
47 """Main command to create controller"""47 """Main command to create controller"""
48 try:48 try:
4949
=== modified file 'debian/patches/series'
--- debian/patches/series 2011-08-02 21:17:36 +0000
+++ debian/patches/series 2014-03-14 14:46:27 +0000
@@ -1,2 +1,3 @@
1move_data_outside_site-packages.patch1move_data_outside_site-packages.patch
2ipython_0.11_compatibility.patch2ipython_0.11_compatibility.patch
3fix-useless-import.patch
34
=== modified file 'pylons/decorators/__init__.py'
--- pylons/decorators/__init__.py 2011-08-02 21:17:36 +0000
+++ pylons/decorators/__init__.py 2014-03-14 14:46:27 +0000
@@ -14,7 +14,6 @@
14import simplejson14import simplejson
15from decorator import decorator15from decorator import decorator
16from formencode import api, htmlfill, variabledecode16from formencode import api, htmlfill, variabledecode
17from webob.multidict import UnicodeMultiDict
1817
19from pylons.decorators.util import get_pylons18from pylons.decorators.util import get_pylons
20from pylons.i18n import _ as pylons_gettext19from pylons.i18n import _ as pylons_gettext

Subscribers

People subscribed via source and target branches

to all changes: