"qqRϱPUddlZddlZddlZddlmZddlmZddlmZddl Z ddl m Z m Z ddl m Z mZmZddlZddlmZdd lmZmZmZmZmZmZd Zeed <d d iZdZddgZdZ e degdZ!de"dee"fdZ#ede"fdZ$de"de"dee"fdZ%dS)N)contextmanager)Optional)quote)ConnectionErrorTimeout)SSLErrorRequestExceptionChunkedEncodingError)ReadTimeoutError)PhpLogErrorsFoundWebsiteCheckBadHttpCodeWebsiteTimeoutWebsiteHttpsBrokenWebsiteNotRespondingPostCheckRequestException TIMEOUTz User-AgentzjMozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101209 CentOS/3.6-2.el5.centos Firefox/3.6.13 error_logzPHP Fatal errorz Stack tracecfd}|S)z: Decorator to retry method on specific exceptions cfd}|S)Ncd}tdd}|krk |i|S#t$rG}|dz }tjdt ||}t jdYd}~nd}~wwxYw|kk|)Nrz%Request to website failed even after z retries.r z'Retry to request website, exception: %s) ValueErrortupleloggingwarningstrtimesleep)argskwargsretries exceptioneexceptions_to_retryfunc max_retriess (py/clwpos/user/website_check/checkers.pywrapperz7retry_on_exceptions..decorator..wrapper0sG"#a;#a#a#abbIK''"40000011"""qLGO$MsSTvvVVV !IJqMMMMMMMM "K''Os&A?=A::A?)r&r)r%r's` r( decoratorz&retry_on_exceptions..decorator/s.       r*)r'r%r+s`` r(retry_on_exceptionsr-+s*       r,cJtj|tdt}|S)zg retry on: - ChunkedEncodingError -> sometimes error happens due to network issues/glitch F)timeoutverifyheaders)requestsgetrHEADERS)urlresponses r( _request_urlr8?s( |C#(';;;H Or,r6returncV t|}d|jcxkrdkrnndSt|j|j#t$rt |t t$r#}t|t|d}~wt$r`}|j r6t|j dtrt |t t|t|d}~wtt f$r#}t#|t|d}~wwxYw)z Checks that website response http code is in range 200-400 and returns. Otherwise, throws a human-readable error. :param url: website url represented as "protocol://domain.zone/wp_installation_path" iN)r0)detailsr)error)r8 status_coderr6rrrrrrrr isinstancer rr rr)r6r7r$s r( _make_requestr@IsJ;$$ (& , , , , , , , , , F%hlH4HIII 333S'2222 666 c!ff5555 888 6 7j,<== 7 g666 6"3A7777 j );;;'3q66::::;s5$AA)D(+B  D(AC11D(D##D( abs_wp_pathc#Ktj|t}tj|rtj|}nd}dVtj|st jd|dStj|}t|d5}|r:|j |j kr*|j |j kr| |j | dD]2tfdtDs#t!| ddddS#1swxYwYdS)aM Looks into {doc_root}/public_html and searches for any php errors found. As log can be really big, this context manager captures log size at start point and then analyzes only part which was added during context execution :param abs_wp_path: path to the root directory of wordpress installation Nz2%s does not exists, nothing to analyze in log filerz [c3 K|]}|vV dS)Nr*).0 error_pattern log_records r( z"check_error_log..s(XX 3XXXXXXr,)ospathjoinERROR_LOGFILE_NAMEexistsstatrropenst_inost_sizeseekreadsplitanyERROR_PATTERNSr )rAerror_log_pathold_stat_resultcur_stat_resultfrGs @r(check_error_logr[esW\\+/ABBN w~~n%%'.11 EEE 7>>. ) )Ln]]]gn--O nc " "@a  ,#*o.DDD#+/FFF FF?* + + +&&((..// @ @JXXXXXXXYY #NJ?? ? @@@@@@@@@@@@@@@@@@@s=BE""E&)E&domainwp_pathctjtjj d|zdzt |dz}t |dS#t $r-d|zdzt |dz}t |YdSwxYw)aG Checks website to decide whether AccelerateWP installation was successful. :param domain: domain name represented as "domain.zone" protocol will be added automatically :param wp_path: path to the wordpress installation instance :raises: WebsiteCheckError and subclasses zhttp:///)safezhttps://N)urllib3disable_warnings exceptionsInsecureRequestWarningrr@r)r\r]http_url https_urls r(check_site_status_codergs W/FGGG!v%+eG#.F.F.FFh !!!'#-gC0H0H0HH i      !s)A3BB)&rrIr contextlibrtypingr urllib.parserr3rrrequests.exceptionsrr r raurllib3.exceptionsr errorsr rrrrrrint__annotations__r5rLrVr-r8rr@r[rgr*r,r(rps  %%%%%%--------PPPPPPPPPP//////J  ! (Q-.//0/;s;x};;;;8+@+@+@+@+@\!3!!#!!!!!!r,