def _run_search(self,pattern,href=None): if href==None: href="http://www.torrent411.com/search/"+urllib.quote_plus(pattern) resp,content=self.http_queue_request(href) content=_codecs.utf_8_encode(_codecs.latin_1_decode(content)[0])[0] tree=libxml2.htmlParseDoc(content,"utf-8") pager=htmltools.find_elements(htmltools.find_elements(tree.getRootElement(),"table",**{'class':'NB-frame'})[1],"p")[0] try: b=htmltools.find_elements(pager,"b")[-1] data=b.getContent() i=len(data)-1 while data[i] in "012346789": i-=1 self.results_count=eval(data[i+1:]) except: pass restable=htmltools.find_elements(pager.next.next,"table")[0] restable=htmltools.find_elements(restable,"table")[1] body=htmltools.find_elements(restable,"tbody")[0] lines=htmltools.find_elements(body,"tr",1) for i in lines: try: cat,link,a,date,b,c,d,e,f,g,h,i,size,j,seeders,leechers=htmltools.find_elements(i,"td") date=date.getContent().replace(chr(194)+chr(160)+"at"+chr(194)+chr(160)," ") date=time.strptime(date,"%Y-%m-%d %H:%M:%S") date=datetime.date(date.tm_year,date.tm_mon,date.tm_mday) size=size.getContent().replace(chr(194)+chr(160)," ") seeders=eval(seeders.getContent()) leechers=eval(leechers.getContent()) link=htmltools.find_elements(link,"a")[0] label=link.prop('title') link=urllib.basejoin("http://www.torrent411.com",link.prop('href')) resp,content=self.http_queue_request(link) content=_codecs.utf_8_encode(_codecs.latin_1_decode(content)[0])[0] itemtree=libxml2.htmlParseDoc(content,"utf-8") table=htmltools.find_elements(itemtree.getRootElement(),"table",**{'cellpadding':'3'})[1] desc,name,torrent,cat,siz,hashvalue=htmltools.find_elements(table,"tr")[:6] torrent=htmltools.find_elements(torrent,"a")[0].prop('href') hashvalue=htmltools.find_elements(hashvalue,"td")[1].getContent() self.add_result(Torrent411PluginResult(label,date,size,seeders,leechers,torrent,hashvalue)) except: pass if self.stop_search: return if not self.stop_search: try: links=htmltools.find_elements(pager,"a") next_link=None for i in links: if i.getContent()=="Next"+chr(194)+chr(160)+">>": next_link=i if next_link: link=urllib.basejoin("http://www.torrent411.com",next_link.prop('href')) self._run_search(pattern,link) except: pass
def test_latin_1_decode(): ''' ''' #sanity new_str, size = codecs.latin_1_decode("abc") AreEqual(new_str, u'abc') AreEqual(size, 3)
def PyUnicode_DecodeCharmap(s, size, mapping, errors): ## /* Default to Latin-1 */ if (mapping == None): import _codecs return _codecs.latin_1_decode(s, size, errors) if (size == 0): return u'' p = [] inpos = 0 while (inpos< len(s)): #/* Get mapping (char ordinal -> integer, Unicode char or None) */ ch = s[inpos] try: x = mapping[ord(ch)] if isinstance(x, int): if x < 65536: p += unichr(x) else: raise TypeError("character mapping must be in range(65536)") elif isinstance(x, unicode): p += x elif not x: raise KeyError else: raise TypeError except KeyError: x = unicode_call_errorhandler(errors, "charmap", "character maps to <undefined>", s, inpos, inpos+1) p += x[0] inpos += 1 return p
def test_decode_bytearray(self): import _codecs b = bytearray() assert _codecs.ascii_decode(b) == (u'', 0) assert _codecs.latin_1_decode(b) == (u'', 0) assert _codecs.utf_7_decode(b) == (u'', 0) assert _codecs.utf_8_decode(b) == (u'', 0) assert _codecs.utf_16_be_decode(b) == (u'', 0) assert _codecs.utf_16_decode(b) == (u'', 0) assert _codecs.utf_16_le_decode(b) == (u'', 0) assert _codecs.utf_16_ex_decode(b) == (u'', 0, 0) assert _codecs.utf_32_decode(b) == (u'', 0) assert _codecs.utf_32_be_decode(b) == (u'', 0) assert _codecs.utf_32_le_decode(b) == (u'', 0) assert _codecs.utf_32_ex_decode(b) == (u'', 0, 0) assert _codecs.charmap_decode(b) == (u'', 0) assert _codecs.unicode_escape_decode(b) == (u'', 0) assert _codecs.raw_unicode_escape_decode(b) == (u'', 0) assert _codecs.unicode_internal_decode(b) == (u'', 0)
def PyUnicode_DecodeCharmap(s, mapping, errors): size = len(s) ## /* Default to Latin-1 */ if mapping is None: import _codecs return _codecs.latin_1_decode(s, errors)[0] if (size == 0): return u'' p = [] inpos = 0 while (inpos < len(s)): #/* Get mapping (char ordinal -> integer, Unicode char or None) */ ch = s[inpos] try: x = mapping[ord(ch)] if isinstance(x, int): if x < 65536: p += unichr(x) else: raise TypeError( "character mapping must be in range(65536)") elif isinstance(x, unicode): if x == u"\ufffe": raise KeyError p += x elif not x: raise KeyError else: raise TypeError inpos += 1 except (KeyError, IndexError): next, inpos = unicode_call_errorhandler( errors, "charmap", "character maps to <undefined>", s, inpos, inpos + 1) p += next inpos return p