Warning:
Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.
Ticket #2430: lazy-param-initialization-2.patch
| File lazy-param-initialization-2.patch,
2.6 KB
(added by chrisz, 2 years ago) |
|
Slightly modified patch
|
-
|
|
|
|
| 3 | 3 | import pkg_resources |
| 4 | 4 | import warnings |
| 5 | 5 | from turbogears import view, startup, config |
| 6 | | from turbogears.util import setlike, to_unicode, copy_if_mutable, \ |
| 7 | | get_package_name, request_available |
| | 6 | from turbogears.util import (setlike, to_unicode, copy_if_mutable, |
| | 7 | get_package_name, request_available) |
| 8 | 8 | from turbogears.i18n.utils import get_locale |
| 9 | 9 | from turbogears.widgets.meta import MetaWidget, load_kid_template |
| 10 | 10 | from cherrypy import request |
| … |
… |
|
| 184 | 184 | setattr(self, param, copy_if_mutable(params.pop(param))) |
| 185 | 185 | |
| 186 | 186 | else: |
| 187 | | if hasattr(self, param): |
| 188 | | # make sure we don't alter mutable class attributes |
| 189 | | value = copy_if_mutable(getattr(self.__class__, param), |
| 190 | | True) |
| 191 | | if value[1]: |
| 192 | | # re-set it only if mutable |
| 193 | | setattr(self, param, value[0]) |
| 194 | | else: |
| 195 | | setattr(self, param, None) |
| | 187 | # make sure we don't alter mutable class attributes |
| | 188 | value, mutable = copy_if_mutable( |
| | 189 | getattr(self.__class__, param), True) |
| | 190 | if mutable: |
| | 191 | # re-set it only if mutable |
| | 192 | setattr(self, param, value) |
| 196 | 193 | |
| 197 | 194 | for unused in params.iterkeys(): |
| 198 | 195 | warnings.warn('keyword argument "%s" is unused at %r instance' % ( |
-
|
|
|
|
| 37 | 37 | for param in params: |
| 38 | 38 | # Swap all params listed at 'params' with a ParamDescriptor |
| 39 | 39 | try: |
| 40 | | dct[param_prefix+param] = dct[param] |
| | 40 | dct[param_prefix + param] = dct[param] |
| 41 | 41 | dct[param] = ParamDescriptor(param) |
| 42 | 42 | except KeyError: |
| 43 | | # declared in a superclass, skip it... |
| 44 | | pass |
| | 43 | for base in bases: |
| | 44 | if hasattr(base, param): |
| | 45 | break |
| | 46 | else: |
| | 47 | # not declared in any superclass, let default be None |
| | 48 | dct[param_prefix + param] = None |
| | 49 | dct[param] = ParamDescriptor(param) |
| 45 | 50 | params = list(params) |
| 46 | 51 | dct['params'] = params |
| 47 | 52 | if compound: |
Download in other formats: