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

]@sXdZddlmZddlZddlmZddlZddlZdgZGddde	Z
d
dd	ZdS)z
Middleware that tests the validity of all generated HTML using the
`WDG HTML Validator <http://www.htmlhelp.com/tools/validator/>`_
)StringION)header_valueWDGValidateMiddlewarec@s@eZdZdZedejZd
ddZddZ	d	d
Z
ddZdS)rab
    Middleware that checks HTML and appends messages about the validity of
    the HTML.  Uses: http://www.htmlhelp.com/tools/validator/ -- interacts
    with the command line client.  Use the configuration ``wdg_path`` to
    override the path (default: looks for ``validate`` in $PATH).

    To install, in your web context's __init__.py::

        def urlparser_wrap(environ, start_response, app):
            return wdg_validate.WDGValidateMiddleware(app)(
                environ, start_response)

    Or in your configuration::

        middleware.append('paste.wdg_validate.WDGValidateMiddleware')
    z</body>NvalidatecCs||_||_dS)N)appwdg_path)selfrglobal_confrr
I/opt/alt/python37/lib/python3.7/site-packages/paste/debug/wdg_validate.py__init__%szWDGValidateMiddleware.__init__c	stgdfdd	}|||}zx|D]}|q0WWdt|drX|X}\}}t|dpvd}	|	ds|	ds|	ds|gSg}
|	d	r|
d
|	|j
|
|}|r|||d}|dt
t|d
f|dt
t|f|gS)Ncs ||f|||jS)N)extendwrite)statusheadersexc_info)outputresponsestart_responser
rwriter_start_response-sz=WDGValidateMiddleware.__call__.<locals>.writer_start_responseclosezcontent-typez	text/htmlz
text/xhtmlzapplication/xhtmlztext/xhtml+xmlz--xmlrzContent-Lengthzcontent-length)N)rrrhasattrrgetvaluer
startswithappendcall_wdg_validater	add_errorremovestrlen)renvironrrZapp_iterspagerrvopshtml_errorsr
)rrrr__call__)s8







zWDGValidateMiddleware.__call__cCsLtdkrtdtj|g|ddtjtjtjd}||d}||S)Nz>This middleware requires the subprocess module from Python 2.4FT)shell	close_fdsstdoutstdinstderrr)
subprocess
ValueErrorPopenPIPESTDOUTcommunicatewait)rrr%r#procr*r
r
rrPs
z'WDGValidateMiddleware.call_wdg_validatecCsRdt|}|j|}|rD|d||||dgS||gSdS)NzR<pre style="background-color: #ffd; color: #600; border: 1px solid #000;">%s</pre>)cgiescape_end_body_regexsearchstart)rZ	html_pager&Zadd_textmatchr
r
rr_s&zWDGValidateMiddleware.add_error)Nr)__name__
__module____qualname____doc__recompileIr7rr'rrr
r
r
rrs
'rcCst|||dS)a
    Wraps the application in the WDG validator from
    http://www.htmlhelp.com/tools/validator/

    Validation errors are appended to the text of each page.
    You can configure this by giving the path to the validate
    executable (by default picked up from $PATH)
    )r)r)rr	rr
r
rmake_wdg_validate_middlewareks
rB)r)r>	cStringIOrr-Zpaste.responserr?r5__all__objectrrBr
r
r
r<module>s\