Ñò ìÜIc@s*dZddkZddkZddkZddkZddkZddklZddklZlZl Z ddk l Z ddk l Z ddklZdd gZeieƒZd „ZeeƒZddded d eded „ Zd„Zdd„Zd„Zdefd„ƒYZdS(sïPylons Decorators Common decorators intended for use in controllers. Additional decorators for use with controllers are in the :mod:`~pylons.decorators.cache`, :mod:`~pylons.decorators.rest` and :mod:`~pylons.decorators.secure` modules. iÿÿÿÿN(t decorator(tapithtmlfilltvariabledecode(tUnicodeMultiDict(t get_pylons(t_tjsonifytvalidatecOs…t|ƒ}d|iid<|||Ž}t|ttfƒo*d}ti|tdƒt i |ƒnt i dƒt i |ƒS(s×Action decorator that formats output for JSON Given a function that will return content, this decorator will turn the result into JSON, with a content-type of 'application/json' and output it. sapplication/jsons Content-TypesJSON responses with Array envelopes are susceptible to cross-site data leak attacks, see http://pylonshq.com/warnings/JSONArrayis$Returning JSON wrapped action output(Rtresponsetheaderst isinstancetlistttupletwarningstwarntWarningtlogtwarningtdebugt simplejsontdumps(tfunctargstkwargstpylonstdatatmsg((s>/usr/lib/python2.6/site-packages/pylons/decorators/__init__.pyRs  t.t-c sKˆdjo t‰n‡‡‡‡‡‡ ‡‡‡‡f d†} t| ƒS(s›Validate input either for a FormEncode schema, or individual validators Given a form schema or dict of validators, validate will attempt to validate the schema or validator list. If validation was successful, the valid result dict will be saved as ``self.form_result``. Otherwise, the action will be re-run as if it was a GET, and the output will be filled by FormEncode's htmlfill to fill in the form field errors. ``schema`` Refers to a FormEncode Schema object to use during validation. ``form`` Method used to display the form, which will be used to get the HTML representation of the form for error filling. ``variable_decode`` Boolean to indicate whether FormEncode's variable decode function should be run on the form input before validation. ``dict_char`` Passed through to FormEncode. Toggles the form field naming scheme used to determine what is used to represent a dict. This option is only applicable when used with variable_decode=True. ``list_char`` Passed through to FormEncode. Toggles the form field naming scheme used to determine what is used to represent a list. This option is only applicable when used with variable_decode=True. ``post_only`` Boolean that indicates whether or not GET (query) variables should be included during validation. .. warning:: ``post_only`` applies to *where* the arguments to be validated come from. It does *not* restrict the form to only working with post, merely only checking POST vars. ``state`` Passed through to FormEncode for use in validators that utilize a state object. ``on_get`` Whether to validate on GET requests. By default only POST requests are validated. Example:: class SomeController(BaseController): def create(self, id): return render('/myform.mako') @validate(schema=model.forms.myshema(), form='create') def update(self, id): # Do something with self.form_result pass c si|ii}h}ˆ o%|iddjo||||ŽSˆo |i}n |i}t|tƒ}|iƒ}ˆo&ti dƒt i |ˆˆ ƒ}n|}ˆoZti dƒyˆi |ˆƒ|_ Wq tij o} | iˆˆˆ ƒ}q Xnˆoªti dƒtˆtƒo‰t|dƒp h|_ nxiˆiƒD]W\} } y&| i |i| ƒˆƒ|i | /usr/lib/python2.6/site-packages/pylons/decorators/__init__.pytwrapperlsˆ           &             N(tNonetPylonsFormEncodeStateR( RPRMRQR-RLRTRSRORRRNRU(( RSRQRTRNRRRORLR-RMRPs>/usr/lib/python2.6/site-packages/pylons/decorators/__init__.pyR0s:  *dcCs:|i}|djotiƒ}ntid|ƒ|S(srDetermine the charset of the specified Response object, returning the default system encoding when none is sets#Determined result charset to be: %sN(tcharsetRVtsystgetdefaultencodingRR(R RX((s>/usr/lib/python2.6/site-packages/pylons/decorators/__init__.pyR<Ós   tstrictcCs¿|djpt|tƒon›t|tƒo|i||ƒ}nut|tƒo7xa|iƒD]"\}}t|||ƒ||R2R4R?(R&RKtencoding_errorstkeytvaluet_[1]RH((s>/usr/lib/python2.6/site-packages/pylons/decorators/__init__.pyR?Ýs  &cCs0t|ƒ}||joti|ƒ}n|S(sòTranslates a string ``value`` using pylons gettext first and if that fails, formencode gettext. This allows to "merge" localized error messages from built-in FormEncode's validators with application-specific validators. (tpylons_gettextRt _stdtrans(R_ttrans((s>/usr/lib/python2.6/site-packages/pylons/decorators/__init__.pytpylons_formencode_gettextðs  RWcBseZdZeeƒZRS(sA ``state`` for FormEncode validate API that includes smart ``_`` hook. The FormEncode library used by validate() decorator has some provision for localizing error messages. In particular, it looks for attribute ``_`` in the application-specific state object that gets passed to every ``.to_python()`` call. If it is found, the ``_`` is assumed to be a gettext-like function and is called to localize error messages. One complication is that FormEncode ships with localized error messages for standard validators so the user may want to re-use them instead of gathering and translating everything from scratch. To allow this, we pass as ``_`` a function which looks up translation both in application and formencode message catalogs. (t__name__t __module__t__doc__t staticmethodRdR(((s>/usr/lib/python2.6/site-packages/pylons/decorators/__init__.pyRWÿs(RgtloggingRYRR/RRRRRtwebobRtpylons.decorators.utilRt pylons.i18nRRat__all__t getLoggerReRRRVR9R;RR<R?RdtobjectRW(((s>/usr/lib/python2.6/site-packages/pylons/decorators/__init__.pyts*           ¡