Ńň <0ŻHc@s,dZddkZdefd„ƒYZdS(s=MIMEType helpers These helpers depend on the WebOb package. i˙˙˙˙Nt MIMETypescBsYeZdZhZd„ZeeƒZd„ZeeƒZd„Zd„Zd„Z RS(s"MIMETypes registration mapping The MIMETypes object class provides a single point to hold onto all the registered mimetypes, and their association extensions. It's used by the mimetypes function to determine the appropriate content type to return to a client. cCstiƒdS(săLoads a default mapping of extensions and mimetypes These are suitable for most web applications by default. Additional types can be added with the using the mimetypes module. N(t mimetypestinit(tcls((s9/usr/lib/python2.6/site-packages/webhelpers/mimehelper.pyRscCs.d|jotdƒ‚n||i|text/html, xml->application/xml.t/s$MIMEType aliases may not contain '/'N(t ValueErrortaliases(Rtaliastmimetype((s9/usr/lib/python2.6/site-packages/webhelpers/mimehelper.pyt add_aliass cCs ||_dS(N(tenv(tselftenviron((s9/usr/lib/python2.6/site-packages/webhelpers/mimehelper.pyt__init__'scCs+d|ijo||idi_n|S(Ns pylons.pylons(R tresponset content_type(R R((s9/usr/lib/python2.6/site-packages/webhelpers/mimehelper.pyt_set_responce_conetent_type*scCsiddk}|tijoti|}n|id}ti|ƒd}d}t}t|i dƒƒdjo.|i dƒd}d|jo t }qŁnd|ijo |i i d |idƒ}n|tjo>|djo|i |ƒS||jo|i |ƒStSn||jo|i |ƒS|djo||jo|i |ƒStSdS( sECheck the PATH_INFO of the current request and clients HTTP Accept to attempt to use the appropriate mime-type If a content-type is matched, the appropriate response content type is set as well. This works best with URLs that end in extensions that differentiate content-type. Examples: http://example.com/example, http://example.com/example.xml, http://example.com/example.csv Since browsers generally allow for any content-type, but should be sent HTML when possible, the html mimetype check should always come first, as shown in the example below. Example:: # some code likely in environment.py MIMETypes.init() MIMETypes.add_alias('html', 'text/html') MIMETypes.add_alias('xml', 'application/xml') MIMETypes.add_alias('csv', 'text/csv') # code in a controller def somaction(self): # prepare a bunch of data # ...... # prepare MIMETypes object m = MIMETypes(request.environ) if m.mimetype('html'): return render('/some/template.html') elif m.mimetype('atom'): return render('/some/xml_template.xml') elif m.mimetype('csv'): # write the data to a csv file return csvfile else: abort(404) i˙˙˙˙Nt PATH_INFOiRit.t HTTP_ACCEPTtACCEPT(twebobRRR Rt guess_typetNonetFalsetlentsplittTruet acceptparset MIMEAcceptR(R RRtpathtguess_from_urltpossible_from_accept_headert has_extensiont last_part((s9/usr/lib/python2.6/site-packages/webhelpers/mimehelper.pyR/s2*        ( t__name__t __module__t__doc__RRt classmethodR R RR(((s9/usr/lib/python2.6/site-packages/webhelpers/mimehelper.pyRs     (R%RtobjectR(((s9/usr/lib/python2.6/site-packages/webhelpers/mimehelper.pyts