• File: url.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/paste/__pycache__/url.cpython-37.pyc
  • Date Modified: 12/01/2019 7:09 PM
  • File size: 14.46 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

aN 9@sdZddlZddlZddlmZdaddgZddZdd	Zej	Z
d
dZGdd
d
eZ
Gddde
ZGddde
ZGddde
ZGddde
ZedkrddlZedS)z3
This module implements a class for handling URLs.
N)requestURLImagecCs|dkrdStt|dS)N)cgiescapestr)vr:/opt/alt/python37/lib/python3.7/site-packages/paste/url.py
html_quotesr
cCs|dkrdStt|S)Nr)urllibquoter	)r
rrr	url_quotesrcCs|dkrdS|dkrdS|dkr$dSt|trBddtt|St|trdddd	d
|DSt|trvt|St|trt|	dSt|t
tfrt|St|trt|
dSt|d
r|Std|dS)NZnullFfalseTtruez[%s]z, z{%s}cSs$g|]\}}dt|t|fqS)z%s: %s)js_repr).0keyvaluerrr
<listcomp>&szjs_repr.<locals>.<listcomp>zUTF-8L__js_repr__z<I don't know how to turn %r into a Javascript representation)
isinstancelistjoinmaprdictr	reprunicodeencodefloatintlonglstriphasattrr
ValueError)r
rrrrs2





rc@seZdZdZiZd,ddZd-ddZeeZdd	Zd
dZ	dd
Z
ddZddZddZ
ddZddZddZeZddZddZeeZddZd d!ZeeZd"d#Zd$d%Zd&d'Zd(d)Zd*d+ZdS).URLResourcezD
    This is an abstract superclass for different kinds of URLs
    NcCsH|pd|_|pg|_|pi|_|j|_|p0i|_|rD|j|dS)N/)urlvarsattrsdefault_paramscopyparamsoriginal_paramsupdate)selfr*r+r,r/rrr__init__@s



zURLResource.__init__Tc
CsRtj|d|||d}|r>|dkr,t|}qBtj|ddd}nd}|||d}	|	S)NF)with_query_stringwith_path_infoscript_name	path_infoT)keep_blank_valuesstrict_parsing)r+)rZ
construct_urlZparse_querystringr	parse_qsl)
clsenvironr4r5r6r7Zquerystringr*r+r
rrrfrom_environKs
zURLResource.from_environcOs||}||}|S)N)_add_positional	_add_vars)r2argskwresrrr__call__as

zURLResource.__call__cCs:d|kr.|dd\}}|t|t|iS||fS)N=r)splitr?url_unquoter>)r2itemnamerrrr__getitem__fszURLResource.__getitem__cKsbx4|D](}|dr
||||dd<||=q
W|j}|||j|j|j||jdS)N_)r+r,r/)	keysendswithr,r.r1	__class__r*r+r0)r2rArZ	new_attrsrrrattrls



zURLResource.attrcKs,|j}|||j|j|j|j|dS)N)r+r,r/)r0r.r1rNr*r+r,)r2rA
new_paramsrrrparamws


zURLResource.paramcCsrd}xF|D]:\}}t|tr$d}|dr||||dd<||=qW|rntdkrdddlmat|}|S)NFTrJrKr)variabledecode)itemsrrrMrRZ
formencodeZvariable_encode)r2r+Zneed_variable_encoderrrrrcoerce_vars~s



zURLResource.coerce_varscKs0||}|j|}|j|j||j|jdS)N)r+r,r/)rTr+rSrNr*r,r0)r2rAnew_varsrrrvars


zURLResource.varcKs`||}g}x*|jD] \}}||kr(q|||fqW|||j|j||j|jdS)z
        Like ``.var(...)``, except overwrites keys, where .var simply
        extends the keys.  Setting a variable to None here will
        effectively delete it.
        )r+r,r/)	rTr+appendextendrSrNr*r,r0)r2rArUrHvaluesrrrsetvars

zURLResource.setvarcKs|j|j||j|jdS)z
        Creates a copy of this URL, but with all the variables set/reset
        (like .setvar(), except clears past variables at the same time)
        )r+r,r/)rNr*rSr,r0)r2rArrrsetvarsszURLResource.setvarscGsX|}xN|D]F}t|d}|j}|ds4|d7}|j|||j|j|jd}q
W|S)Nr))r+r,r/)r	r%r*rMrNr+r,r0)r2pathsupathZnew_urlrrraddpaths

zURLResource.addpathcCs||j|j|j|jdS)N)r+r,r/)r*r+r,r0)r2Z
OtherClassrrrbecomes
zURLResource.becomecCsv|j}|jrr|d7}g}xH|jD]>\}}t|ttfrFdd|D}n
|dkrPq |||fq W|t|d7}|S)N?cSsg|]}|dk	r|qS)Nr)rr
rrrrsz)URLResource.href__get.<locals>.<listcomp>T)r*r+rrtuplerWr	urlencode)r2sr+rHvalrrr	href__getszURLResource.href__getcCsnd|jj|jpdf}|jr>|dddd|jD7}|jrf|ddd	d|jD7}|d
S)Nz<%s %sz''z
 attrs(%s) cSs$g|]\}}dt|t|fqS)z%s="%s")r
)rnr
rrrrsz(URLResource.__repr__.<locals>.<listcomp>z params(%s)z, cSsg|]\}}d||fqS)z%s=%rr)rrhr
rrrrs>)rN__name__hrefr,rrSr0)r2baserrr__repr__s

zURLResource.__repr__cCs|jdstd||}d|jd}ddd|D}|rX|d|7}||7}|dkrt|dSd|||jdfSdS)	Ntagz<You cannot get the HTML of %r until you set the 'tag' param'z<%srgcSs$g|]\}}dt|t|fqS)z%s="%s")r
)rrhr
rrrrsz)URLResource.html__get.<locals>.<listcomp>z />z
%s>%s</%s>)r/getr'_get_contentr_html_attrs_html_extra)r2contentrnr,rrr	html__getszURLResource.html__getcCs
|jS)N)r,rS)r2rrrrqszURLResource._html_attrscCsdS)Nrr)r2rrrrrszURLResource._html_extracCstdS)zw
        Return the content for a tag (for self.html); return None
        for an empty tag (like ``<img />``)
        N)NotImplementedError)r2rrrrpszURLResource._get_contentcCstdS)N)ru)r2r+rrrr?szURLResource._add_varscCstdS)N)ru)r2r@rrrr>szURLResource._add_positional)NNN)TTNNN)rj
__module____qualname____doc__r-r3r=classmethodrCrIrOrQrTrVrZr[r_Z__div__r`rfpropertyrkrmrthtmlrqrrrpr?r>rrrrr(8s:


	
r(c@speZdZdZddiZddZddZdd	Zd
dZdd
Z	ddZ
ee
ZddZ
ee
ZddZeeZdS)ra
    >>> u = URL('http://localhost')
    >>> u
    <URL http://localhost>
    >>> u = u['view']
    >>> str(u)
    'http://localhost/view'
    >>> u['//foo'].param(content='view').html
    '<a href="http://localhost/view/foo">view</a>'
    >>> u.param(confirm='Really?', content='goto').html
    '<a href="http://localhost/view" onclick="return confirm(\'Really?\')">goto</a>'
    >>> u(title='See "it"', content='goto').html
    '<a href="http://localhost/view?title=See+%22it%22">goto</a>'
    >>> u('another', var='fuggetaboutit', content='goto').html
    '<a href="http://localhost/view/another?var=fuggetaboutit">goto</a>'
    >>> u.attr(content='goto').html
    Traceback (most recent call last):
        ....
    ValueError: You must give a content param to <URL http://localhost/view attrs(content="goto")> generate anchor tags
    >>> str(u['foo=bar%20stuff'])
    'http://localhost/view?foo=bar+stuff'
    rnacCs|jS)N)rk)r2rrr__str__!szURL.__str__cCs"|jdstd||jdS)Nrsz8You must give a content param to %r generate anchor tags)r/ror')r2rrrrp$s
zURL._get_contentcCsV|}x*dD]"}||kr
|jf|||i}q
Wd|krJ|j|dd}|jf|S)N)confirmrstarget)r)rQpoprOrV)r2r+r*rHrrrr?+s
z
URL._add_varscCs
|j|S)N)r_)r2r@rrrr>4szURL._add_positionalcCsH|j}|dd|jf|jdrD|ddt|jdf|S)Nrrkr~onclickzreturn confirm(%s))r,rSinsertrkr/rorWr)r2r,rrrrq7s
zURL._html_attrscCsdt|jS)Nzlocation.href=%s; return false)rrk)r2rrronclick_goto__get?szURL.onclick_goto__getcCs
|tS)N)r`Button)r2rrrbutton__getDszURL.button__getcCs
|tS)N)r`JSPopup)r2rrr
js_popup__getIszURL.js_popup__getN)rjrvrwrxr-r}rpr?r>rqrrzZonclick_gotorbuttonrZjs_popuprrrrrs	c@s@eZdZdZddiZddZddZdd	Zd
dZdd
Z	dS)rz
    >>> i = Image('/images')
    >>> i = i / '/foo.png'
    >>> i.html
    '<img src="/images/foo.png" />'
    >>> str(i['alt=foo'])
    '<img src="/images/foo.png" alt="foo" />'
    >>> i.href
    '/images/foo.png'
    rnZimgcCs|jS)N)r{)r2rrrr}]sz
Image.__str__cCsdS)Nr)r2rrrrp`szImage._get_contentcCs|jf|S)N)rO)r2r+rrrr?cszImage._add_varscCs
|j|S)N)r_)r2r@rrrr>fszImage._add_positionalcCs |j}|dd|jf|S)Nrsrc)r,rSrrk)r2r,rrrrqis
zImage._html_attrsN)
rjrvrwrxr-r}rpr?r>rqrrrrrNsc@s@eZdZdZddiZddZddZdd	Zd
dZdd
Z	dS)rz
    >>> u = URL('/')
    >>> u = u / 'delete'
    >>> b = u.button['confirm=Sure?'](id=5, content='del')
    >>> str(b)
    '<button onclick="if (confirm(\'Sure?\')) {location.href=\'/delete?id=5\'}; return false">del</button>'
    rnrcCs|jS)N)r{)r2rrrr}zszButton.__str__cCs0|jdr|jdS|jdr,|jdSdS)Nrsr)r/ror,)r2rrrrp}s


zButton._get_contentcCsD|}d|kr|j|dd}d|kr8|j|dd}|jf|S)Nr~)r~rs)rs)rQrrV)r2r+rrrrr?szButton._add_varscCs
|j|S)N)r_)r2r@rrrr>szButton._add_positionalcCsV|j}dt|j}|jdr:dt|jd|f}|d7}|dd|f|S)Nzlocation.href=%sr~zif (confirm(%s)) {%s}z; return falserr)r,rSrrkr/ror)r2r,rrrrrqs
zButton._html_attrsN)
rjrvrwrxr-r}rpr?r>rqrrrrrnsrc@sBeZdZdZdddZddZddZd	d
ZddZd
dZ	dS)rz
    >>> u = URL('/')
    >>> u = u / 'view'
    >>> j = u.js_popup(content='view')
    >>> j.html
    '<a href="/view" onclick="window.open(\'/view\', \'_blank\'); return false" target="_blank">view</a>'
    r|Z_blank)rnrcCs<|}x*dD]"}||kr
|jf|||i}q
W|jf|S)N)widthheightstrippedrs)rQrrV)r2r+rrVrrrr?s

zJSPopup._add_varscCs|j}g}|dr,d|d<|d<|d<xJdD]>}||krDq6||}|dkrb|r^d}nd}|d	||fq6Wx.d
D]&}||sq~|d	|||fq~W|j|dg}|r|d|d
tt|S)Nr0locationstatusZtoolbarzXchannelmode directories fullscreen location menubar resizable scrollbars status titlebar)yesno1rrz%s=%szheight left top widthr,z, )r/rorErWrkrrr)r2pfeaturesrQr
r@rrr_window_argss*


zJSPopup._window_argscCsR|j}d|}|dd|jdf|dd|f|dd|jf|S)Nzwindow.open(%s); return falserrrrk)r,rSrrr/rk)r2r,rrrrrqs

zJSPopup._html_attrscCs"|jdstd||jdS)Nrsz8You must give a content param to %r generate anchor tags)r/ror')r2rrrrps
zJSPopup._get_contentcCs
|j|S)N)r_)r2r@rrrr>szJSPopup._add_positionalN)
rjrvrwrxr-r?rrqrpr>rrrrrs
	r__main__)rxrrpasterrR__all__r
runquoterFrobjectr(rrrrrjZdoctestZtestmodrrrr<module>s$OH ,>