Warning: session_start(): Session cannot be started after headers have already been sent in /home/tvrreohg/public_html/manga.php on line 13
3 #6]„ã@s dZdZddlZddlmZddlmZddlZddlmZm Z ddl m Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZdd „Zd#d d „ZGd d„deƒZdd„ZdZdZd$dd„Zd%dd„Zd&dd„Zd'dd„Zd(d d!„Zed"k�reejj ƒƒdS))z=Diagnostic functions, mainly for use when doing tech support.ZMITéN)ÚStringIO)Ú HTMLParser)Ú BeautifulSoupÚ __version__)Úbuilder_registryc ;CsXtdtƒtdtjƒdddg}x>|D]6}x0tjD]}||jkr6Pq6W|j|ƒtd|ƒq*Wd|krÌ|jdƒy*dd l m }td d j t t |jƒƒƒWn*tk rÊ}ztd ƒWYd d }~XnXd|k�rydd l}td|jƒWn,tk �r}ztdƒWYd d }~XnXt|dƒ�r4|jƒ}nˆ|jdƒ�sL|jdƒ�rdtd|ƒtdƒd Sy:tjj|ƒ�rœtd|ƒt|ƒ�}|jƒ}Wd QRXWntk �r´YnXtƒx–|D]Ž}td|ƒd} yt||d�} d} Wn8tk �r"}ztd|ƒtjƒWYd d }~XnX| �rBtd|ƒt| jƒƒtddƒ�qÂWd S)z/Diagnostic suite for isolating common problems.z'Diagnostic running on Beautiful Soup %szPython version %sz html.parserÚhtml5libÚlxmlz;I noticed that %s is not installed. Installing it may help.zlxml-xmlr)ÚetreezFound lxml version %sÚ.z.lxml is not installed or couldn't be imported.NzFound html5lib version %sz2html5lib is not installed or couldn't be imported.Úreadzhttp:zhttps:z<"%s" looks like a URL. Beautiful Soup is not an HTTP client.zpYou need to use some other library to get the document behind the URL, and feed that document to Beautiful Soup.z7"%s" looks like a filename. Reading data from the file.z#Trying to parse your markup with %sF)ÚfeaturesTz%s could not parse the markup.z#Here's what %s did with the markup:ú-éP)ÚprintrÚsysÚversionrZbuildersr ÚremoveÚappendrr ÚjoinÚmapÚstrZ LXML_VERSIONÚ ImportErrorrÚhasattrr Ú startswithÚosÚpathÚexistsÚopenÚ ValueErrorrÚ ExceptionÚ tracebackÚ print_excZprettify) ÚdataZ basic_parsersÚnameZbuilderr ÚerÚfpÚparserÚsuccessÚsoup©r)ú/usr/lib/python3.6/diagnose.pyÚdiagnosesj                     r+TcKsNddlm}x<|jt|ƒfd|i|—ŽD]\}}td||j|jfƒq(WdS)z—Print out the lxml events that occur during parsing. This lets you see how lxml parses a document when no Beautiful Soup code is running. r)r Úhtmlz %s, %4s, %sN)rr Z iterparserrÚtagÚtext)r"r,Úkwargsr ZeventÚelementr)r)r*Ú lxml_traceZs $r1c@s`eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dS)ÚAnnouncingParserz?Announces HTMLParser parse events, without doing anything else.cCs t|ƒdS)N)r)ÚselfÚsr)r)r*Ú_pgszAnnouncingParser._pcCs|jd|ƒdS)Nz%s START)r5)r3r#Zattrsr)r)r*Úhandle_starttagjsz AnnouncingParser.handle_starttagcCs|jd|ƒdS)Nz%s END)r5)r3r#r)r)r*Ú handle_endtagmszAnnouncingParser.handle_endtagcCs|jd|ƒdS)Nz%s DATA)r5)r3r"r)r)r*Ú handle_datapszAnnouncingParser.handle_datacCs|jd|ƒdS)Nz %s CHARREF)r5)r3r#r)r)r*Úhandle_charrefsszAnnouncingParser.handle_charrefcCs|jd|ƒdS)Nz %s ENTITYREF)r5)r3r#r)r)r*Úhandle_entityrefvsz!AnnouncingParser.handle_entityrefcCs|jd|ƒdS)Nz %s COMMENT)r5)r3r"r)r)r*Úhandle_commentyszAnnouncingParser.handle_commentcCs|jd|ƒdS)Nz%s DECL)r5)r3r"r)r)r*Ú handle_decl|szAnnouncingParser.handle_declcCs|jd|ƒdS)Nz%s UNKNOWN-DECL)r5)r3r"r)r)r*Ú unknown_declszAnnouncingParser.unknown_declcCs|jd|ƒdS)Nz%s PI)r5)r3r"r)r)r*Ú handle_pi‚szAnnouncingParser.handle_piN)Ú__name__Ú __module__Ú __qualname__Ú__doc__r5r6r7r8r9r:r;r<r=r>r)r)r)r*r2dsr2cCstƒ}|j|ƒdS)z£Print out the HTMLParser events that occur during parsing. This lets you see how HTMLParser parses a document when no Beautiful Soup code is running. N)r2Zfeed)r"r&r)r)r*Úhtmlparser_trace…srCZaeiouZbcdfghjklmnpqrstvwxyzécCs>d}x4t|ƒD](}|ddkr$t}nt}|tj|ƒ7}qW|S)z#Generate a random word-like string.Úér)ÚrangeÚ _consonantsÚ_vowelsÚrandomÚchoice)Úlengthr4ÚiÚtr)r)r*Úrword‘s rOécCsdjdd„t|ƒDƒƒS)z'Generate a random sentence-like string.ú css|]}ttjddƒƒVqdS)rPé N)rOrJÚrandint)Ú.0rMr)r)r*ú žszrsentence..)rrG)rLr)r)r*Ú rsentenceœsrVéècCs¨dddddddg}g}x~t|ƒD]r}tjdd ƒ}|dkrRtj|ƒ}|jd |ƒq |d krr|jttjd d ƒƒƒq |d kr tj|ƒ}|jd|ƒq Wddj|ƒdS)z+Randomly generate an invalid HTML document.ÚpZdivÚspanrMÚbZscriptÚtableréz<%s>érPrFzzÚ z)rGrJrSrKrrVr)Ú num_elementsZ tag_namesÚelementsrMrKZtag_namer)r)r*Úrdoc s   raé †c Cs(tdtƒt|ƒ}tdt|ƒƒxŽdddgddgD]z}d}y"tjƒ}t||ƒ}tjƒ}d}Wn6tk r–}ztd |ƒtjƒWYd d }~XnX|r6td |||fƒq6Wd d l m }tjƒ}|j |ƒtjƒ}td||ƒd d l } | j ƒ}tjƒ}|j|ƒtjƒ}td||ƒd S)z.Very basic head-to-head performance benchmark.z1Comparative parser benchmark on Beautiful Soup %sz3Generated a large invalid HTML document (%d bytes).rr,rz html.parserFTz%s could not parse the markup.Nz"BS4+%s parsed the markup in %.2fs.r)r z$Raw lxml parsed the markup in %.2fs.z(Raw html5lib parsed the markup in %.2fs.)rrraÚlenÚtimerrr r!rr ZHTMLrrÚparse) r_r"r&r'Úar(rZr$r rr)r)r*Úbenchmark_parsers²s4      rgrcCsXtjƒ}|j}t|ƒ}tt||d�}tjd|||ƒtj |ƒ}|j dƒ|j ddƒdS)N)Úbs4r"r&zbs4.BeautifulSoup(data, parser)Z cumulativez _html5lib|bs4é2) ÚtempfileZNamedTemporaryFiler#raÚdictrhÚcProfileZrunctxÚpstatsZStatsZ sort_statsZ print_stats)r_r&Z filehandleÚfilenamer"ÚvarsZstatsr)r)r*ÚprofileÒs  rpÚ__main__)T)rD)rP)rW)rb)rbr)!rBZ __license__rlÚiorZ html.parserrrhrrZ bs4.builderrrrmrJrjrdr rr+r1r2rCrIrHrOrVrargrpr?Ústdinr r)r)r)r*Ús8   C !