<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import sys <EOL> import random <EOL> import mimetypes <EOL> import time <EOL> import cgi <EOL> import os <EOL> import shutil <EOL> import smtplib <EOL> import shlex <EOL> import re <EOL> import six <EOL> import subprocess <EOL> from six . moves import cStringIO as StringIO <EOL> from six . moves . urllib . parse import urlencode <EOL> from six . moves . urllib import parse as urlparse <EOL> try : <EOL> from http . cookies import BaseCookie <EOL> from urllib . parse import splittype , splithost <EOL> except ImportError : <EOL> from Cookie import BaseCookie <EOL> from urllib import splittype , splithost <EOL> from paste import wsgilib <EOL> from paste import lint <EOL> from paste . response import HeaderDict <EOL> def tempnam_no_warning ( * args ) : <EOL> """<STR_LIT>""" <EOL> return os . tempnam ( * args ) <EOL> class NoDefault ( object ) : <EOL> pass <EOL> def sorted ( l ) : <EOL> l = list ( l ) <EOL> l . sort ( ) <EOL> return l <EOL> class Dummy_smtplib ( object ) : <EOL> existing = None <EOL> def __init__ ( self , server ) : <EOL> import warnings <EOL> warnings . warn ( <EOL> '<STR_LIT>' , <EOL> DeprecationWarning , <NUM_LIT:2> ) <EOL> assert not self . existing , ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . server = server <EOL> self . open = True <EOL> self . __class__ . existing = self <EOL> def quit ( self ) : <EOL> assert self . open , ( <EOL> "<STR_LIT>" % self ) <EOL> self . open = False <EOL> def sendmail ( self , from_address , to_addresses , msg ) : <EOL> self . from_address = from_address <EOL> self . to_addresses = to_addresses <EOL> self . message = msg <EOL> def install ( cls ) : <EOL> smtplib . SMTP = cls <EOL> install = classmethod ( install ) <EOL> def reset ( self ) : <EOL> assert not self . open , ( <EOL> "<STR_LIT>" ) <EOL> self . __class__ . existing = None <EOL> class AppError ( Exception ) : <EOL> pass <EOL> class TestApp ( object ) : <EOL> disabled = True <EOL> def __init__ ( self , app , namespace = None , relative_to = None , <EOL> extra_environ = None , pre_request_hook = None , <EOL> post_request_hook = None ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( app , ( six . binary_type , six . text_type ) ) : <EOL> from paste . deploy import loadapp <EOL> app = loadapp ( app , relative_to = relative_to ) <EOL> self . app = app <EOL> self . namespace = namespace <EOL> self . relative_to = relative_to <EOL> if extra_environ is None : <EOL> extra_environ = { } <EOL> self . extra_environ = extra_environ <EOL> self . pre_request_hook = pre_request_hook <EOL> self . post_request_hook = post_request_hook <EOL> self . reset ( ) <EOL> def reset ( self ) : <EOL> """<STR_LIT>""" <EOL> self . cookies = { } <EOL> def _make_environ ( self ) : <EOL> environ = self . extra_environ . copy ( ) <EOL> environ [ '<STR_LIT>' ] = True <EOL> return environ <EOL> def get ( self , url , params = None , headers = None , extra_environ = None , <EOL> status = None , expect_errors = False ) : <EOL> """<STR_LIT>""" <EOL> if extra_environ is None : <EOL> extra_environ = { } <EOL> __tracebackhide__ = True <EOL> if params : <EOL> if not isinstance ( params , ( six . binary_type , six . text_type ) ) : <EOL> params = urlencode ( params , doseq = True ) <EOL> if '<STR_LIT:?>' in url : <EOL> url += '<STR_LIT:&>' <EOL> else : <EOL> url += '<STR_LIT:?>' <EOL> url += params <EOL> environ = self . _make_environ ( ) <EOL> url = str ( url ) <EOL> if '<STR_LIT:?>' in url : <EOL> url , environ [ '<STR_LIT>' ] = url . split ( '<STR_LIT:?>' , <NUM_LIT:1> ) <EOL> else : <EOL> environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . _set_headers ( headers , environ ) <EOL> environ . update ( extra_environ ) <EOL> req = TestRequest ( url , environ , expect_errors ) <EOL> return self . do_request ( req , status = status ) <EOL> def _gen_request ( self , method , url , params = b'<STR_LIT>' , headers = None , extra_environ = None , <EOL> status = None , upload_files = None , expect_errors = False ) : <EOL> """<STR_LIT>""" <EOL> if headers is None : <EOL> headers = { } <EOL> if extra_environ is None : <EOL> extra_environ = { } <EOL> environ = self . _make_environ ( ) <EOL> if isinstance ( params , ( list , tuple , dict ) ) : <EOL> params = urlencode ( params ) <EOL> if hasattr ( params , '<STR_LIT>' ) : <EOL> params = urlencode ( params . items ( ) ) <EOL> if six . PY3 : <EOL> params = params . encode ( '<STR_LIT:utf8>' ) <EOL> if upload_files : <EOL> params = cgi . parse_qsl ( params , keep_blank_values = True ) <EOL> content_type , params = self . encode_multipart ( <EOL> params , upload_files ) <EOL> environ [ '<STR_LIT>' ] = content_type <EOL> elif params : <EOL> environ . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if '<STR_LIT:?>' in url : <EOL> url , environ [ '<STR_LIT>' ] = url . split ( '<STR_LIT:?>' , <NUM_LIT:1> ) <EOL> else : <EOL> environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> environ [ '<STR_LIT>' ] = str ( len ( params ) ) <EOL> environ [ '<STR_LIT>' ] = method <EOL> environ [ '<STR_LIT>' ] = six . BytesIO ( params ) <EOL> self . _set_headers ( headers , environ ) <EOL> environ . update ( extra_environ ) <EOL> req = TestRequest ( url , environ , expect_errors ) <EOL> return self . do_request ( req , status = status ) <EOL> def post ( self , url , params = b'<STR_LIT>' , headers = None , extra_environ = None , <EOL> status = None , upload_files = None , expect_errors = False ) : <EOL> """<STR_LIT>""" <EOL> return self . _gen_request ( '<STR_LIT:POST>' , url , params = params , headers = headers , <EOL> extra_environ = extra_environ , status = status , <EOL> upload_files = upload_files , <EOL> expect_errors = expect_errors ) <EOL> def put ( self , url , params = b'<STR_LIT>' , headers = None , extra_environ = None , <EOL> status = None , upload_files = None , expect_errors = False ) : <EOL> """<STR_LIT>""" <EOL> return self . _gen_request ( '<STR_LIT>' , url , params = params , headers = headers , <EOL> extra_environ = extra_environ , status = status , <EOL> upload_files = upload_files , <EOL> expect_errors = expect_errors ) <EOL> def delete ( self , url , params = b'<STR_LIT>' , headers = None , extra_environ = None , <EOL> status = None , expect_errors = False ) : <EOL> """<STR_LIT>""" <EOL> return self . _gen_request ( '<STR_LIT>' , url , params = params , headers = headers , <EOL> extra_environ = extra_environ , status = status , <EOL> upload_files = None , expect_errors = expect_errors ) <EOL> def _set_headers ( self , headers , environ ) : <EOL> """<STR_LIT>""" <EOL> if not headers : <EOL> return <EOL> for header , value in headers . items ( ) : <EOL> if header . lower ( ) == '<STR_LIT>' : <EOL> var = '<STR_LIT>' <EOL> elif header . lower ( ) == '<STR_LIT>' : <EOL> var = '<STR_LIT>' <EOL> else : <EOL> var = '<STR_LIT>' % header . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) . upper ( ) <EOL> environ [ var ] = value <EOL> def encode_multipart ( self , params , files ) : <EOL> """<STR_LIT>""" <EOL> boundary = '<STR_LIT>' % random . random ( ) <EOL> content_type = '<STR_LIT>' % boundary <EOL> if six . PY3 : <EOL> boundary = boundary . encode ( '<STR_LIT:ascii>' ) <EOL> lines = [ ] <EOL> for key , value in params : <EOL> lines . append ( b'<STR_LIT>' + boundary ) <EOL> line = '<STR_LIT>' % key <EOL> if six . PY3 : <EOL> line = line . encode ( '<STR_LIT:utf8>' ) <EOL> lines . append ( line ) <EOL> lines . append ( b'<STR_LIT>' ) <EOL> line = value <EOL> if six . PY3 and isinstance ( line , six . text_type ) : <EOL> line = line . encode ( '<STR_LIT:utf8>' ) <EOL> lines . append ( line ) <EOL> for file_info in files : <EOL> key , filename , value = self . _get_file_info ( file_info ) <EOL> lines . append ( b'<STR_LIT>' + boundary ) <EOL> line = ( '<STR_LIT>' <EOL> % ( key , filename ) ) <EOL> if six . PY3 : <EOL> line = line . encode ( '<STR_LIT:utf8>' ) <EOL> lines . append ( line ) <EOL> fcontent = mimetypes . guess_type ( filename ) [ <NUM_LIT:0> ] <EOL> line = ( '<STR_LIT>' <EOL> % ( fcontent or '<STR_LIT>' ) ) <EOL> if six . PY3 : <EOL> line = line . encode ( '<STR_LIT:utf8>' ) <EOL> lines . append ( line ) <EOL> lines . append ( b'<STR_LIT>' ) <EOL> lines . append ( value ) <EOL> lines . append ( b'<STR_LIT>' + boundary + b'<STR_LIT>' ) <EOL> lines . append ( b'<STR_LIT>' ) <EOL> body = b'<STR_LIT:\r\n>' . join ( lines ) <EOL> return content_type , body <EOL> def _get_file_info ( self , file_info ) : <EOL> if len ( file_info ) == <NUM_LIT:2> : <EOL> filename = file_info [ <NUM_LIT:1> ] <EOL> if self . relative_to : <EOL> filename = os . path . join ( self . relative_to , filename ) <EOL> f = open ( filename , '<STR_LIT:rb>' ) <EOL> content = f . read ( ) <EOL> f . close ( ) <EOL> return ( file_info [ <NUM_LIT:0> ] , filename , content ) <EOL> elif len ( file_info ) == <NUM_LIT:3> : <EOL> return file_info <EOL> else : <EOL> raise ValueError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % repr ( file_info ) [ : <NUM_LIT:100> ] ) <EOL> def do_request ( self , req , status ) : <EOL> """<STR_LIT>""" <EOL> if self . pre_request_hook : <EOL> self . pre_request_hook ( self ) <EOL> __tracebackhide__ = True <EOL> if self . cookies : <EOL> c = BaseCookie ( ) <EOL> for name , value in self . cookies . items ( ) : <EOL> c [ name ] = value <EOL> hc = '<STR_LIT>' . join ( [ '<STR_LIT:=>' . join ( [ m . key , m . value ] ) for m in c . values ( ) ] ) <EOL> req . environ [ '<STR_LIT>' ] = hc <EOL> req . environ [ '<STR_LIT>' ] = True <EOL> req . environ [ '<STR_LIT>' ] = { } <EOL> app = lint . middleware ( self . app ) <EOL> old_stdout = sys . stdout <EOL> out = CaptureStdout ( old_stdout ) <EOL> try : <EOL> sys . stdout = out <EOL> start_time = time . time ( ) <EOL> raise_on_wsgi_error = not req . expect_errors <EOL> raw_res = wsgilib . raw_interactive ( <EOL> app , req . url , <EOL> raise_on_wsgi_error = raise_on_wsgi_error , <EOL> ** req . environ ) <EOL> end_time = time . time ( ) <EOL> finally : <EOL> sys . stdout = old_stdout <EOL> sys . stderr . write ( out . getvalue ( ) ) <EOL> res = self . _make_response ( raw_res , end_time - start_time ) <EOL> res . request = req <EOL> for name , value in req . environ [ '<STR_LIT>' ] . items ( ) : <EOL> if hasattr ( res , name ) : <EOL> raise ValueError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT:name>" % name ) <EOL> setattr ( res , name , value ) <EOL> if self . namespace is not None : <EOL> self . namespace [ '<STR_LIT>' ] = res <EOL> if not req . expect_errors : <EOL> self . _check_status ( status , res ) <EOL> self . _check_errors ( res ) <EOL> res . cookies_set = { } <EOL> for header in res . all_headers ( '<STR_LIT>' ) : <EOL> c = BaseCookie ( header ) <EOL> for key , morsel in c . items ( ) : <EOL> self . cookies [ key ] = morsel . value <EOL> res . cookies_set [ key ] = morsel . value <EOL> if self . post_request_hook : <EOL> self . post_request_hook ( self ) <EOL> if self . namespace is None : <EOL> return res <EOL> def _check_status ( self , status , res ) : <EOL> __tracebackhide__ = True <EOL> if status == '<STR_LIT:*>' : <EOL> return <EOL> if isinstance ( status , ( list , tuple ) ) : <EOL> if res . status not in status : <EOL> raise AppError ( <EOL> "<STR_LIT>" <EOL> % ( res . full_status , '<STR_LIT:U+002CU+0020>' . join ( map ( str , status ) ) , <EOL> res . request . url , res . body ) ) <EOL> return <EOL> if status is None : <EOL> if res . status >= <NUM_LIT:200> and res . status < <NUM_LIT> : <EOL> return <EOL> body = res . body <EOL> if six . PY3 : <EOL> body = body . decode ( '<STR_LIT:utf8>' , '<STR_LIT>' ) <EOL> raise AppError ( <EOL> "<STR_LIT>" <EOL> % ( res . full_status , res . request . url , <EOL> body ) ) <EOL> if status != res . status : <EOL> raise AppError ( <EOL> "<STR_LIT>" % ( res . full_status , status ) ) <EOL> def _check_errors ( self , res ) : <EOL> if res . errors : <EOL> raise AppError ( <EOL> "<STR_LIT>" % res . errors ) <EOL> def _make_response ( self , resp , total_time ) : <EOL> status , headers , body , errors = resp <EOL> return TestResponse ( self , status , headers , body , errors , <EOL> total_time ) <EOL> class CaptureStdout ( object ) : <EOL> def __init__ ( self , actual ) : <EOL> self . captured = StringIO ( ) <EOL> self . actual = actual <EOL> def write ( self , s ) : <EOL> self . captured . write ( s ) <EOL> self . actual . write ( s ) <EOL> def flush ( self ) : <EOL> self . actual . flush ( ) <EOL> def writelines ( self , lines ) : <EOL> for item in lines : <EOL> self . write ( item ) <EOL> def getvalue ( self ) : <EOL> return self . captured . getvalue ( ) <EOL> class TestResponse ( object ) : <EOL> disabled = True <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , test_app , status , headers , body , errors , <EOL> total_time ) : <EOL> self . test_app = test_app <EOL> self . status = int ( status . split ( ) [ <NUM_LIT:0> ] ) <EOL> self . full_status = status <EOL> self . headers = headers <EOL> self . header_dict = HeaderDict . fromlist ( self . headers ) <EOL> self . body = body <EOL> self . errors = errors <EOL> self . _normal_body = None <EOL> self . time = total_time <EOL> self . _forms_indexed = None <EOL> def forms__get ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _forms_indexed is None : <EOL> self . _parse_forms ( ) <EOL> return self . _forms_indexed <EOL> forms = property ( forms__get , <EOL> doc = """<STR_LIT>""" ) <EOL> def form__get ( self ) : <EOL> forms = self . forms <EOL> if not forms : <EOL> raise TypeError ( <EOL> "<STR_LIT>" ) <EOL> if <NUM_LIT:1> in forms : <EOL> raise TypeError ( <EOL> "<STR_LIT>" ) <EOL> return forms [ <NUM_LIT:0> ] <EOL> form = property ( form__get , <EOL> doc = """<STR_LIT>""" ) <EOL> _tag_re = re . compile ( r'<STR_LIT>' , re . S | re . I ) <EOL> def _parse_forms ( self ) : <EOL> forms = self . _forms_indexed = { } <EOL> form_texts = [ ] <EOL> started = None <EOL> for match in self . _tag_re . finditer ( self . body ) : <EOL> end = match . group ( <NUM_LIT:1> ) == '<STR_LIT:/>' <EOL> tag = match . group ( <NUM_LIT:2> ) . lower ( ) <EOL> if tag != '<STR_LIT>' : <EOL> continue <EOL> if end : <EOL> assert started , ( <EOL> "<STR_LIT>" % match . start ( ) ) <EOL> form_texts . append ( self . body [ started : match . end ( ) ] ) <EOL> started = None <EOL> else : <EOL> assert not started , ( <EOL> "<STR_LIT>" % match . start ( ) ) <EOL> started = match . start ( ) <EOL> assert not started , ( <EOL> "<STR_LIT>" % self . body [ started : ] ) <EOL> for i , text in enumerate ( form_texts ) : <EOL> form = Form ( self , text ) <EOL> forms [ i ] = form <EOL> if form . id : <EOL> forms [ form . id ] = form <EOL> def header ( self , name , default = NoDefault ) : <EOL> """<STR_LIT>""" <EOL> found = None <EOL> for cur_name , value in self . headers : <EOL> if cur_name . lower ( ) == name . lower ( ) : <EOL> assert not found , ( <EOL> "<STR_LIT>" <EOL> % ( name , found , value ) ) <EOL> found = value <EOL> if found is None : <EOL> if default is NoDefault : <EOL> raise KeyError ( <EOL> "<STR_LIT>" <EOL> % ( name , '<STR_LIT:U+002CU+0020>' . join ( [ n for n , v in self . headers ] ) ) ) <EOL> else : <EOL> return default <EOL> return found <EOL> def all_headers ( self , name ) : <EOL> """<STR_LIT>""" <EOL> found = [ ] <EOL> for cur_name , value in self . headers : <EOL> if cur_name . lower ( ) == name . lower ( ) : <EOL> found . append ( value ) <EOL> return found <EOL> def follow ( self , ** kw ) : <EOL> """<STR_LIT>""" <EOL> assert self . status >= <NUM_LIT> and self . status < <NUM_LIT> , ( <EOL> "<STR_LIT>" <EOL> % self . full_status ) <EOL> location = self . header ( '<STR_LIT:location>' ) <EOL> type , rest = splittype ( location ) <EOL> host , path = splithost ( rest ) <EOL> return self . test_app . get ( location , ** kw ) <EOL> def click ( self , description = None , linkid = None , href = None , <EOL> anchor = None , index = None , verbose = False ) : <EOL> """<STR_LIT>""" <EOL> __tracebackhide__ = True <EOL> found_html , found_desc , found_attrs = self . _find_element ( <EOL> tag = '<STR_LIT:a>' , href_attr = '<STR_LIT>' , <EOL> href_extract = None , <EOL> content = description , <EOL> id = linkid , <EOL> href_pattern = href , <EOL> html_pattern = anchor , <EOL> index = index , verbose = verbose ) <EOL> return self . goto ( found_attrs [ '<STR_LIT>' ] ) <EOL> def clickbutton ( self , description = None , buttonid = None , href = None , <EOL> button = None , index = None , verbose = False ) : <EOL> """<STR_LIT>""" <EOL> __tracebackhide__ = True <EOL> found_html , found_desc , found_attrs = self . _find_element ( <EOL> tag = '<STR_LIT>' , href_attr = '<STR_LIT>' , <EOL> href_extract = re . compile ( r"<STR_LIT>" ) , <EOL> content = description , <EOL> id = buttonid , <EOL> href_pattern = href , <EOL> html_pattern = button , <EOL> index = index , verbose = verbose ) <EOL> return self . goto ( found_attrs [ '<STR_LIT>' ] ) <EOL> def _find_element ( self , tag , href_attr , href_extract , <EOL> content , id , <EOL> href_pattern , <EOL> html_pattern , <EOL> index , verbose ) : <EOL> content_pat = _make_pattern ( content ) <EOL> id_pat = _make_pattern ( id ) <EOL> href_pat = _make_pattern ( href_pattern ) <EOL> html_pat = _make_pattern ( html_pattern ) <EOL> _tag_re = re . compile ( r'<STR_LIT>' % ( tag , tag ) , <EOL> re . I + re . S ) <EOL> def printlog ( s ) : <EOL> if verbose : <EOL> print ( s ) <EOL> found_links = [ ] <EOL> total_links = <NUM_LIT:0> <EOL> for match in _tag_re . finditer ( self . body ) : <EOL> el_html = match . group ( <NUM_LIT:0> ) <EOL> el_attr = match . group ( <NUM_LIT:1> ) <EOL> el_content = match . group ( <NUM_LIT:2> ) <EOL> attrs = _parse_attrs ( el_attr ) <EOL> if verbose : <EOL> printlog ( '<STR_LIT>' % el_html ) <EOL> if not attrs . get ( href_attr ) : <EOL> printlog ( '<STR_LIT>' % href_attr ) <EOL> continue <EOL> el_href = attrs [ href_attr ] <EOL> if href_extract : <EOL> m = href_extract . search ( el_href ) <EOL> if not m : <EOL> printlog ( "<STR_LIT>" ) <EOL> continue <EOL> el_href = m . group ( <NUM_LIT:1> ) <EOL> attrs [ '<STR_LIT>' ] = el_href <EOL> if el_href . startswith ( '<STR_LIT:#>' ) : <EOL> printlog ( '<STR_LIT>' ) <EOL> continue <EOL> if el_href . startswith ( '<STR_LIT>' ) : <EOL> printlog ( '<STR_LIT>' ) <EOL> continue <EOL> total_links += <NUM_LIT:1> <EOL> if content_pat and not content_pat ( el_content ) : <EOL> printlog ( "<STR_LIT>" ) <EOL> continue <EOL> if id_pat and not id_pat ( attrs . get ( '<STR_LIT:id>' , '<STR_LIT>' ) ) : <EOL> printlog ( "<STR_LIT>" ) <EOL> continue <EOL> if href_pat and not href_pat ( el_href ) : <EOL> printlog ( "<STR_LIT>" ) <EOL> continue <EOL> if html_pat and not html_pat ( el_html ) : <EOL> printlog ( "<STR_LIT>" ) <EOL> continue <EOL> printlog ( "<STR_LIT>" ) <EOL> found_links . append ( ( el_html , el_content , attrs ) ) <EOL> if not found_links : <EOL> raise IndexError ( <EOL> "<STR_LIT>" <EOL> % total_links ) <EOL> if index is None : <EOL> if len ( found_links ) > <NUM_LIT:1> : <EOL> raise IndexError ( <EOL> "<STR_LIT>" <EOL> % '<STR_LIT:U+002CU+0020>' . join ( [ repr ( anc ) for anc , d , attr in found_links ] ) ) <EOL> found_link = found_links [ <NUM_LIT:0> ] <EOL> else : <EOL> try : <EOL> found_link = found_links [ index ] <EOL> except IndexError : <EOL> raise IndexError ( <EOL> "<STR_LIT>" <EOL> % ( len ( found_links ) , total_links , index ) ) <EOL> return found_link <EOL> def goto ( self , href , method = '<STR_LIT>' , ** args ) : <EOL> """<STR_LIT>""" <EOL> scheme , host , path , query , fragment = urlparse . urlsplit ( href ) <EOL> scheme = host = fragment = '<STR_LIT>' <EOL> href = urlparse . urlunsplit ( ( scheme , host , path , query , fragment ) ) <EOL> href = urlparse . urljoin ( self . request . full_url , href ) <EOL> method = method . lower ( ) <EOL> assert method in ( '<STR_LIT>' , '<STR_LIT>' ) , ( <EOL> '<STR_LIT>' <EOL> % method ) <EOL> if method == '<STR_LIT>' : <EOL> method = self . test_app . get <EOL> else : <EOL> method = self . test_app . post <EOL> return method ( href , ** args ) <EOL> _normal_body_regex = re . compile ( br'<STR_LIT>' ) <EOL> def normal_body__get ( self ) : <EOL> if self . _normal_body is None : <EOL> self . _normal_body = self . _normal_body_regex . sub ( <EOL> b'<STR_LIT:U+0020>' , self . body ) <EOL> return self . _normal_body <EOL> normal_body = property ( normal_body__get , <EOL> doc = """<STR_LIT>""" ) <EOL> def __contains__ ( self , s ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( s , ( six . binary_type , six . text_type ) ) : <EOL> s = str ( s ) <EOL> if isinstance ( s , six . text_type ) : <EOL> s = s . encode ( '<STR_LIT:utf8>' ) <EOL> return ( self . body . find ( s ) != - <NUM_LIT:1> <EOL> or self . normal_body . find ( s ) != - <NUM_LIT:1> ) <EOL> def mustcontain ( self , * strings , ** kw ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in kw : <EOL> no = kw [ '<STR_LIT>' ] <EOL> del kw [ '<STR_LIT>' ] <EOL> if isinstance ( no , ( six . binary_type , six . text_type ) ) : <EOL> no = [ no ] <EOL> else : <EOL> no = [ ] <EOL> if kw : <EOL> raise TypeError ( <EOL> "<STR_LIT>" ) <EOL> for s in strings : <EOL> if not s in self : <EOL> print ( "<STR_LIT>" % s , file = sys . stderr ) <EOL> print ( self , file = sys . stderr ) <EOL> raise IndexError ( <EOL> "<STR_LIT>" % s ) <EOL> for no_s in no : <EOL> if no_s in self : <EOL> print ( "<STR_LIT>" % no_s , file = sys . stderr ) <EOL> print ( self , file = sys . stderr ) <EOL> raise IndexError ( <EOL> "<STR_LIT>" % s ) <EOL> def __repr__ ( self ) : <EOL> body = self . body <EOL> if six . PY3 : <EOL> body = body . decode ( '<STR_LIT:utf8>' , '<STR_LIT>' ) <EOL> body = body [ : <NUM_LIT:20> ] <EOL> return '<STR_LIT>' % ( self . full_status , body ) <EOL> def __str__ ( self ) : <EOL> simple_body = b'<STR_LIT:\n>' . join ( [ l for l in self . body . splitlines ( ) <EOL> if l . strip ( ) ] ) <EOL> if six . PY3 : <EOL> simple_body = simple_body . decode ( '<STR_LIT:utf8>' , '<STR_LIT>' ) <EOL> return '<STR_LIT>' % ( <EOL> self . status , <EOL> '<STR_LIT:\n>' . join ( [ '<STR_LIT>' % ( n , v ) for n , v in self . headers ] ) , <EOL> simple_body ) <EOL> def showbrowser ( self ) : <EOL> """<STR_LIT>""" <EOL> import webbrowser <EOL> fn = tempnam_no_warning ( None , '<STR_LIT>' ) + '<STR_LIT>' <EOL> f = open ( fn , '<STR_LIT:wb>' ) <EOL> f . write ( self . body ) <EOL> f . close ( ) <EOL> url = '<STR_LIT>' + fn . replace ( os . sep , '<STR_LIT:/>' ) <EOL> webbrowser . open_new ( url ) <EOL> class TestRequest ( object ) : <EOL> disabled = True <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , url , environ , expect_errors = False ) : <EOL> if url . startswith ( '<STR_LIT>' ) : <EOL> url = url [ len ( '<STR_LIT>' ) : ] <EOL> self . url = url <EOL> self . environ = environ <EOL> if environ . get ( '<STR_LIT>' ) : <EOL> self . full_url = url + '<STR_LIT:?>' + environ [ '<STR_LIT>' ] <EOL> else : <EOL> self . full_url = url <EOL> self . expect_errors = expect_errors <EOL> class Form ( object ) : <EOL> """<STR_LIT>""" <EOL> _tag_re = re . compile ( r'<STR_LIT>' , re . I ) <EOL> def __init__ ( self , response , text ) : <EOL> self . response = response <EOL> self . text = text <EOL> self . _parse_fields ( ) <EOL> self . _parse_action ( ) <EOL> def _parse_fields ( self ) : <EOL> in_select = None <EOL> in_textarea = None <EOL> fields = { } <EOL> for match in self . _tag_re . finditer ( self . text ) : <EOL> end = match . group ( <NUM_LIT:1> ) == '<STR_LIT:/>' <EOL> tag = match . group ( <NUM_LIT:2> ) . lower ( ) <EOL> if tag not in ( '<STR_LIT:input>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) : <EOL> continue <EOL> if tag == '<STR_LIT>' and end : <EOL> assert in_select , ( <EOL> '<STR_LIT>' % match . group ( <NUM_LIT:0> ) ) <EOL> in_select = None <EOL> continue <EOL> if tag == '<STR_LIT>' and end : <EOL> assert in_textarea , ( <EOL> "<STR_LIT>" % match . start ( ) ) <EOL> in_textarea [ <NUM_LIT:0> ] . value = html_unquote ( self . text [ in_textarea [ <NUM_LIT:1> ] : match . start ( ) ] ) <EOL> in_textarea = None <EOL> continue <EOL> if end : <EOL> continue <EOL> attrs = _parse_attrs ( match . group ( <NUM_LIT:3> ) ) <EOL> if '<STR_LIT:name>' in attrs : <EOL> name = attrs . pop ( '<STR_LIT:name>' ) <EOL> else : <EOL> name = None <EOL> if tag == '<STR_LIT>' : <EOL> in_select . options . append ( ( attrs . get ( '<STR_LIT:value>' ) , <EOL> '<STR_LIT>' in attrs ) ) <EOL> continue <EOL> if tag == '<STR_LIT:input>' and attrs . get ( '<STR_LIT:type>' ) == '<STR_LIT>' : <EOL> field = fields . get ( name ) <EOL> if not field : <EOL> field = Radio ( self , tag , name , match . start ( ) , ** attrs ) <EOL> fields . setdefault ( name , [ ] ) . append ( field ) <EOL> else : <EOL> field = field [ <NUM_LIT:0> ] <EOL> assert isinstance ( field , Radio ) <EOL> field . options . append ( ( attrs . get ( '<STR_LIT:value>' ) , <EOL> '<STR_LIT>' in attrs ) ) <EOL> continue <EOL> tag_type = tag <EOL> if tag == '<STR_LIT:input>' : <EOL> tag_type = attrs . get ( '<STR_LIT:type>' , '<STR_LIT:text>' ) . lower ( ) <EOL> FieldClass = Field . classes . get ( tag_type , Field ) <EOL> field = FieldClass ( self , tag , name , match . start ( ) , ** attrs ) <EOL> if tag == '<STR_LIT>' : <EOL> assert not in_textarea , ( <EOL> "<STR_LIT>" <EOL> % ( in_textarea , match . group ( <NUM_LIT:0> ) ) ) <EOL> in_textarea = field , match . end ( ) <EOL> elif tag == '<STR_LIT>' : <EOL> assert not in_select , ( <EOL> "<STR_LIT>" <EOL> % ( in_select , match . group ( <NUM_LIT:0> ) ) ) <EOL> in_select = field <EOL> fields . setdefault ( name , [ ] ) . append ( field ) <EOL> self . fields = fields <EOL> def _parse_action ( self ) : <EOL> self . action = None <EOL> for match in self . _tag_re . finditer ( self . text ) : <EOL> end = match . group ( <NUM_LIT:1> ) == '<STR_LIT:/>' <EOL> tag = match . group ( <NUM_LIT:2> ) . lower ( ) <EOL> if tag != '<STR_LIT>' : <EOL> continue <EOL> if end : <EOL> break <EOL> attrs = _parse_attrs ( match . group ( <NUM_LIT:3> ) ) <EOL> self . action = attrs . get ( '<STR_LIT:action>' , '<STR_LIT>' ) <EOL> self . method = attrs . get ( '<STR_LIT>' , '<STR_LIT:GET>' ) <EOL> self . id = attrs . get ( '<STR_LIT:id>' ) <EOL> else : <EOL> assert <NUM_LIT:0> , "<STR_LIT>" <EOL> assert self . action is not None , ( <EOL> "<STR_LIT>" ) <EOL> def __setitem__ ( self , name , value ) : <EOL> """<STR_LIT>""" <EOL> fields = self . fields . get ( name ) <EOL> assert fields is not None , ( <EOL> "<STR_LIT>" <EOL> % ( name , '<STR_LIT:U+002CU+0020>' . join ( map ( repr , self . fields . keys ( ) ) ) ) ) <EOL> assert len ( fields ) == <NUM_LIT:1> , ( <EOL> "<STR_LIT>" <EOL> % ( name , '<STR_LIT:U+002CU+0020>' . join ( map ( repr , fields ) ) ) ) <EOL> fields [ <NUM_LIT:0> ] . value = value <EOL> def __getitem__ ( self , name ) : <EOL> """<STR_LIT>""" <EOL> fields = self . fields . get ( name ) <EOL> assert fields is not None , ( <EOL> "<STR_LIT>" % name ) <EOL> assert len ( fields ) == <NUM_LIT:1> , ( <EOL> "<STR_LIT>" <EOL> % ( name , '<STR_LIT:U+002CU+0020>' . join ( map ( repr , fields ) ) ) ) <EOL> return fields [ <NUM_LIT:0> ] <EOL> def set ( self , name , value , index = None ) : <EOL> """<STR_LIT>""" <EOL> if index is None : <EOL> self [ name ] = value <EOL> else : <EOL> fields = self . fields . get ( name ) <EOL> assert fields is not None , ( <EOL> "<STR_LIT>" % name ) <EOL> field = fields [ index ] <EOL> field . value = value <EOL> def get ( self , name , index = None , default = NoDefault ) : <EOL> """<STR_LIT>""" <EOL> fields = self . fields . get ( name ) <EOL> if fields is None and default is not NoDefault : <EOL> return default <EOL> if index is None : <EOL> return self [ name ] <EOL> else : <EOL> fields = self . fields . get ( name ) <EOL> assert fields is not None , ( <EOL> "<STR_LIT>" % name ) <EOL> field = fields [ index ] <EOL> return field <EOL> def select ( self , name , value , index = None ) : <EOL> """<STR_LIT>""" <EOL> field = self . get ( name , index = index ) <EOL> assert isinstance ( field , Select ) <EOL> field . value = value <EOL> def submit ( self , name = None , index = None , ** args ) : <EOL> """<STR_LIT>""" <EOL> fields = self . submit_fields ( name , index = index ) <EOL> return self . response . goto ( self . action , method = self . method , <EOL> params = fields , ** args ) <EOL> def submit_fields ( self , name = None , index = None ) : <EOL> """<STR_LIT>""" <EOL> submit = [ ] <EOL> if name is not None : <EOL> field = self . get ( name , index = index ) <EOL> submit . append ( ( field . name , field . value_if_submitted ( ) ) ) <EOL> for name , fields in self . fields . items ( ) : <EOL> if name is None : <EOL> continue <EOL> for field in fields : <EOL> value = field . value <EOL> if value is None : <EOL> continue <EOL> submit . append ( ( name , value ) ) <EOL> return submit <EOL> _attr_re = re . compile ( r'<STR_LIT>' , re . S ) <EOL> def _parse_attrs ( text ) : <EOL> attrs = { } <EOL> for match in _attr_re . finditer ( text ) : <EOL> attr_name = match . group ( <NUM_LIT:1> ) . lower ( ) <EOL> attr_body = match . group ( <NUM_LIT:2> ) or match . group ( <NUM_LIT:3> ) <EOL> attr_body = html_unquote ( attr_body or '<STR_LIT>' ) <EOL> attrs [ attr_name ] = attr_body <EOL> return attrs <EOL> class Field ( object ) : <EOL> """<STR_LIT>""" <EOL> classes = { } <EOL> settable = True <EOL> def __init__ ( self , form , tag , name , pos , <EOL> value = None , id = None , ** attrs ) : <EOL> self . form = form <EOL> self . tag = tag <EOL> self . name = name <EOL> self . pos = pos <EOL> self . _value = value <EOL> self . id = id <EOL> self . attrs = attrs <EOL> def value__set ( self , value ) : <EOL> if not self . settable : <EOL> raise AttributeError ( <EOL> "<STR_LIT>" <EOL> % ( self . tag , self . name ) ) <EOL> self . _value = value <EOL> def force_value ( self , value ) : <EOL> """<STR_LIT>""" <EOL> self . _value = value <EOL> def value__get ( self ) : <EOL> return self . _value <EOL> value = property ( value__get , value__set ) <EOL> class Select ( Field ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** attrs ) : <EOL> super ( Select , self ) . __init__ ( * args , ** attrs ) <EOL> self . options = [ ] <EOL> self . multiple = attrs . get ( '<STR_LIT>' ) <EOL> assert not self . multiple , ( <EOL> "<STR_LIT>" ) <EOL> self . selectedIndex = None <EOL> def value__set ( self , value ) : <EOL> for i , ( option , checked ) in enumerate ( self . options ) : <EOL> if option == str ( value ) : <EOL> self . selectedIndex = i <EOL> break <EOL> else : <EOL> raise ValueError ( <EOL> "<STR_LIT>" <EOL> % ( value , '<STR_LIT:U+002CU+0020>' . join ( <EOL> [ repr ( o ) for o , c in self . options ] ) ) ) <EOL> def value__get ( self ) : <EOL> if self . selectedIndex is not None : <EOL> return self . options [ self . selectedIndex ] [ <NUM_LIT:0> ] <EOL> else : <EOL> for option , checked in self . options : <EOL> if checked : <EOL> return option <EOL> else : <EOL> if self . options : <EOL> return self . options [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> else : <EOL> return None <EOL> value = property ( value__get , value__set ) <EOL> Field . classes [ '<STR_LIT>' ] = Select <EOL> class Radio ( Select ) : <EOL> """<STR_LIT>""" <EOL> Field . classes [ '<STR_LIT>' ] = Radio <EOL> class Checkbox ( Field ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** attrs ) : <EOL> super ( Checkbox , self ) . __init__ ( * args , ** attrs ) <EOL> self . checked = '<STR_LIT>' in attrs <EOL> def value__set ( self , value ) : <EOL> self . checked = not not value <EOL> def value__get ( self ) : <EOL> if self . checked : <EOL> if self . _value is None : <EOL> return '<STR_LIT>' <EOL> else : <EOL> return self . _value <EOL> else : <EOL> return None <EOL> value = property ( value__get , value__set ) <EOL> Field . classes [ '<STR_LIT>' ] = Checkbox <EOL> class Text ( Field ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , form , tag , name , pos , <EOL> value = '<STR_LIT>' , id = None , ** attrs ) : <EOL> Field . __init__ ( self , form , tag , name , pos , <EOL> value = value , id = id , ** attrs ) <EOL> Field . classes [ '<STR_LIT:text>' ] = Text <EOL> class Textarea ( Text ) : <EOL> """<STR_LIT>""" <EOL> Field . classes [ '<STR_LIT>' ] = Textarea <EOL> class Hidden ( Text ) : <EOL> """<STR_LIT>""" <EOL> Field . classes [ '<STR_LIT>' ] = Hidden <EOL> class Submit ( Field ) : <EOL> """<STR_LIT>""" <EOL> settable = False <EOL> def value__get ( self ) : <EOL> return None <EOL> value = property ( value__get ) <EOL> def value_if_submitted ( self ) : <EOL> return self . _value <EOL> Field . classes [ '<STR_LIT>' ] = Submit <EOL> Field . classes [ '<STR_LIT>' ] = Submit <EOL> Field . classes [ '<STR_LIT:image>' ] = Submit <EOL> class TestFileEnvironment ( object ) : <EOL> """<STR_LIT>""" <EOL> disabled = True <EOL> def __init__ ( self , base_path , template_path = None , <EOL> script_path = None , <EOL> environ = None , cwd = None , start_clear = True , <EOL> ignore_paths = None , ignore_hidden = True ) : <EOL> """<STR_LIT>""" <EOL> self . base_path = base_path <EOL> self . template_path = template_path <EOL> if environ is None : <EOL> environ = os . environ . copy ( ) <EOL> self . environ = environ <EOL> if script_path is None : <EOL> if sys . platform == '<STR_LIT:win32>' : <EOL> script_path = environ . get ( '<STR_LIT>' , '<STR_LIT>' ) . split ( '<STR_LIT:;>' ) <EOL> else : <EOL> script_path = environ . get ( '<STR_LIT>' , '<STR_LIT>' ) . split ( '<STR_LIT::>' ) <EOL> self . script_path = script_path <EOL> if cwd is None : <EOL> cwd = base_path <EOL> self . cwd = cwd <EOL> if start_clear : <EOL> self . clear ( ) <EOL> elif not os . path . exists ( base_path ) : <EOL> os . makedirs ( base_path ) <EOL> self . ignore_paths = ignore_paths or [ ] <EOL> self . ignore_hidden = ignore_hidden <EOL> def run ( self , script , * args , ** kw ) : <EOL> """<STR_LIT>""" <EOL> __tracebackhide__ = True <EOL> expect_error = _popget ( kw , '<STR_LIT>' , False ) <EOL> expect_stderr = _popget ( kw , '<STR_LIT>' , expect_error ) <EOL> cwd = _popget ( kw , '<STR_LIT>' , self . cwd ) <EOL> stdin = _popget ( kw , '<STR_LIT>' , None ) <EOL> printresult = _popget ( kw , '<STR_LIT>' , True ) <EOL> args = map ( str , args ) <EOL> assert not kw , ( <EOL> "<STR_LIT>" % '<STR_LIT:U+002CU+0020>' . join ( kw . keys ( ) ) ) <EOL> if '<STR_LIT:U+0020>' in script : <EOL> assert not args , ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( script , args ) ) <EOL> script , args = script . split ( None , <NUM_LIT:1> ) <EOL> args = shlex . split ( args ) <EOL> script = self . _find_exe ( script ) <EOL> all = [ script ] + args <EOL> files_before = self . _find_files ( ) <EOL> proc = subprocess . Popen ( all , stdin = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> stdout = subprocess . PIPE , <EOL> cwd = cwd , <EOL> env = self . environ ) <EOL> stdout , stderr = proc . communicate ( stdin ) <EOL> files_after = self . _find_files ( ) <EOL> result = ProcResult ( <EOL> self , all , stdin , stdout , stderr , <EOL> returncode = proc . returncode , <EOL> files_before = files_before , <EOL> files_after = files_after ) <EOL> if printresult : <EOL> print ( result ) <EOL> print ( '<STR_LIT:->' * <NUM_LIT> ) <EOL> if not expect_error : <EOL> result . assert_no_error ( ) <EOL> if not expect_stderr : <EOL> result . assert_no_stderr ( ) <EOL> return result <EOL> def _find_exe ( self , script_name ) : <EOL> if self . script_path is None : <EOL> script_name = os . path . join ( self . cwd , script_name ) <EOL> if not os . path . exists ( script_name ) : <EOL> raise OSError ( <EOL> "<STR_LIT>" % script_name ) <EOL> return script_name <EOL> for path in self . script_path : <EOL> fn = os . path . join ( path , script_name ) <EOL> if os . path . exists ( fn ) : <EOL> return fn <EOL> raise OSError ( <EOL> "<STR_LIT>" <EOL> % ( script_name , '<STR_LIT::>' . join ( self . script_path ) ) ) <EOL> def _find_files ( self ) : <EOL> result = { } <EOL> for fn in os . listdir ( self . base_path ) : <EOL> if self . _ignore_file ( fn ) : <EOL> continue <EOL> self . _find_traverse ( fn , result ) <EOL> return result <EOL> def _ignore_file ( self , fn ) : <EOL> if fn in self . ignore_paths : <EOL> return True <EOL> if self . ignore_hidden and os . path . basename ( fn ) . startswith ( '<STR_LIT:.>' ) : <EOL> return True <EOL> return False <EOL> def _find_traverse ( self , path , result ) : <EOL> full = os . path . join ( self . base_path , path ) <EOL> if os . path . isdir ( full ) : <EOL> result [ path ] = FoundDir ( self . base_path , path ) <EOL> for fn in os . listdir ( full ) : <EOL> fn = os . path . join ( path , fn ) <EOL> if self . _ignore_file ( fn ) : <EOL> continue <EOL> self . _find_traverse ( fn , result ) <EOL> else : <EOL> result [ path ] = FoundFile ( self . base_path , path ) <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> if os . path . exists ( self . base_path ) : <EOL> shutil . rmtree ( self . base_path ) <EOL> os . mkdir ( self . base_path ) <EOL> def writefile ( self , path , content = None , <EOL> frompath = None ) : <EOL> """<STR_LIT>""" <EOL> full = os . path . join ( self . base_path , path ) <EOL> if not os . path . exists ( os . path . dirname ( full ) ) : <EOL> os . makedirs ( os . path . dirname ( full ) ) <EOL> f = open ( full , '<STR_LIT:wb>' ) <EOL> if content is not None : <EOL> f . write ( content ) <EOL> if frompath is not None : <EOL> if self . template_path : <EOL> frompath = os . path . join ( self . template_path , frompath ) <EOL> f2 = open ( frompath , '<STR_LIT:rb>' ) <EOL> f . write ( f2 . read ( ) ) <EOL> f2 . close ( ) <EOL> f . close ( ) <EOL> return FoundFile ( self . base_path , path ) <EOL> class ProcResult ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , test_env , args , stdin , stdout , stderr , <EOL> returncode , files_before , files_after ) : <EOL> self . test_env = test_env <EOL> self . args = args <EOL> self . stdin = stdin <EOL> self . stdout = stdout <EOL> self . stderr = stderr <EOL> self . returncode = returncode <EOL> self . files_before = files_before <EOL> self . files_after = files_after <EOL> self . files_deleted = { } <EOL> self . files_updated = { } <EOL> self . files_created = files_after . copy ( ) <EOL> for path , f in files_before . items ( ) : <EOL> if path not in files_after : <EOL> self . files_deleted [ path ] = f <EOL> continue <EOL> del self . files_created [ path ] <EOL> if f . mtime < files_after [ path ] . mtime : <EOL> self . files_updated [ path ] = files_after [ path ] <EOL> def assert_no_error ( self ) : <EOL> __tracebackhide__ = True <EOL> assert self . returncode == <NUM_LIT:0> , ( <EOL> "<STR_LIT>" % self . returncode ) <EOL> def assert_no_stderr ( self ) : <EOL> __tracebackhide__ = True <EOL> if self . stderr : <EOL> print ( '<STR_LIT>' ) <EOL> print ( self . stderr ) <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> def __str__ ( self ) : <EOL> s = [ '<STR_LIT>' % '<STR_LIT:U+0020>' . join ( self . args ) ] <EOL> if self . returncode : <EOL> s . append ( '<STR_LIT>' % self . returncode ) <EOL> if self . stderr : <EOL> s . append ( '<STR_LIT>' ) <EOL> s . append ( self . stderr ) <EOL> if self . stdout : <EOL> s . append ( '<STR_LIT>' ) <EOL> s . append ( self . stdout ) <EOL> for name , files , show_size in [ <EOL> ( '<STR_LIT>' , self . files_created , True ) , <EOL> ( '<STR_LIT>' , self . files_deleted , True ) , <EOL> ( '<STR_LIT>' , self . files_updated , True ) ] : <EOL> if files : <EOL> s . append ( '<STR_LIT>' % name ) <EOL> files = files . items ( ) <EOL> files . sort ( ) <EOL> last = '<STR_LIT>' <EOL> for path , f in files : <EOL> t = '<STR_LIT>' % _space_prefix ( last , path , indent = <NUM_LIT:4> , <EOL> include_sep = False ) <EOL> last = path <EOL> if show_size and f . size != '<STR_LIT>' : <EOL> t += '<STR_LIT>' % f . size <EOL> s . append ( t ) <EOL> return '<STR_LIT:\n>' . join ( s ) <EOL> class FoundFile ( object ) : <EOL> """<STR_LIT>""" <EOL> file = True <EOL> dir = False <EOL> def __init__ ( self , base_path , path ) : <EOL> self . base_path = base_path <EOL> self . path = path <EOL> self . full = os . path . join ( base_path , path ) <EOL> self . stat = os . stat ( self . full ) <EOL> self . mtime = self . stat . st_mtime <EOL> self . size = self . stat . st_size <EOL> self . _bytes = None <EOL> def bytes__get ( self ) : <EOL> if self . _bytes is None : <EOL> f = open ( self . full , '<STR_LIT:rb>' ) <EOL> self . _bytes = f . read ( ) <EOL> f . close ( ) <EOL> return self . _bytes <EOL> bytes = property ( bytes__get ) <EOL> def __contains__ ( self , s ) : <EOL> return s in self . bytes <EOL> def mustcontain ( self , s ) : <EOL> __tracebackhide__ = True <EOL> bytes_ = self . bytes <EOL> if s not in bytes_ : <EOL> print ( '<STR_LIT>' % s ) <EOL> print ( bytes_ ) <EOL> assert s in bytes_ <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> self . base_path , self . path ) <EOL> class FoundDir ( object ) : <EOL> """<STR_LIT>""" <EOL> file = False <EOL> dir = True <EOL> def __init__ ( self , base_path , path ) : <EOL> self . base_path = base_path <EOL> self . path = path <EOL> self . full = os . path . join ( base_path , path ) <EOL> self . size = '<STR_LIT>' <EOL> self . mtime = '<STR_LIT>' <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> self . __class__ . __name__ , <EOL> self . base_path , self . path ) <EOL> def _popget ( d , key , default = None ) : <EOL> """<STR_LIT>""" <EOL> if key in d : <EOL> return d . pop ( key ) <EOL> return default <EOL> def _space_prefix ( pref , full , sep = None , indent = None , include_sep = True ) : <EOL> """<STR_LIT>""" <EOL> if sep is None : <EOL> sep = os . path . sep <EOL> pref = pref . split ( sep ) <EOL> full = full . split ( sep ) <EOL> padding = [ ] <EOL> while pref and full and pref [ <NUM_LIT:0> ] == full [ <NUM_LIT:0> ] : <EOL> if indent is None : <EOL> padding . append ( '<STR_LIT:U+0020>' * ( len ( full [ <NUM_LIT:0> ] ) + len ( sep ) ) ) <EOL> else : <EOL> padding . append ( '<STR_LIT:U+0020>' * indent ) <EOL> full . pop ( <NUM_LIT:0> ) <EOL> pref . pop ( <NUM_LIT:0> ) <EOL> if padding : <EOL> if include_sep : <EOL> return '<STR_LIT>' . join ( padding ) + sep + sep . join ( full ) <EOL> else : <EOL> return '<STR_LIT>' . join ( padding ) + sep . join ( full ) <EOL> else : <EOL> return sep . join ( full ) <EOL> def _make_pattern ( pat ) : <EOL> if pat is None : <EOL> return None <EOL> if isinstance ( pat , ( six . binary_type , six . text_type ) ) : <EOL> pat = re . compile ( pat ) <EOL> if hasattr ( pat , '<STR_LIT>' ) : <EOL> return pat . search <EOL> if callable ( pat ) : <EOL> return pat <EOL> assert <NUM_LIT:0> , ( <EOL> "<STR_LIT>" % pat ) <EOL> def setup_module ( module = None ) : <EOL> """<STR_LIT>""" <EOL> import warnings <EOL> warnings . warn ( <EOL> '<STR_LIT>' , <EOL> DeprecationWarning , <NUM_LIT:2> ) <EOL> if module is None : <EOL> module = sys . _getframe ( ) . f_back . f_globals [ '<STR_LIT>' ] <EOL> if isinstance ( module , ( six . binary_type , six . text_type ) ) : <EOL> module = sys . modules [ module ] <EOL> if hasattr ( module , '<STR_LIT>' ) : <EOL> module . reset_state ( ) <EOL> def html_unquote ( v ) : <EOL> """<STR_LIT>""" <EOL> for ent , repl in [ ( '<STR_LIT>' , '<STR_LIT:U+0020>' ) , ( '<STR_LIT>' , '<STR_LIT:>>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:<>' ) , ( '<STR_LIT>' , '<STR_LIT:">' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:&>' ) ] : <EOL> v = v . replace ( ent , repl ) <EOL> return v </s>
