def load_feeds_infos( self, url ): try: html = urllib.urlopen( url ) if "code.google" in url: source = html.read() parsed = HTB.parse( StringIO( source ), "utf-8" ).findall( self.tags[ 1 ] ) else: source = re.sub( "<!\[CDATA\[|\]\]>", "", html.read() ) parsed = HTB.parse( StringIO( source ), "utf-8" ).findall( self.tags[ 0 ] )[ 0 ].findall( self.tags[ 1 ] ) html.close() return parsed except: print_exc()
def generateTitle(self): try: tree = HTMLTreeBuilder.parse(StringIO(self.input), encoding='utf8') result = tree.findtext("head/title") except Exception: result = None return result or self.context.Title()
def load_infos( url, onerror=True ): try: html = PassionXBMC.get_page( url ) source = re.sub( "<!\[CDATA\[|\]\]>", "", html ) return HTB.parse( StringIO( source ), "utf-8" ).findall( "channel" )[ 0 ] except: if onerror: print_exc()
def kidified_rest(rest_file, template_name): xhtml_file = StringIO() # prevent docutils from autoclosing the StringIO xhtml_file.close = lambda: None xhtml = publish_file(rest_file, writer_name='html', destination=xhtml_file, settings_overrides={"doctitle_xform": 0}) xhtml_file.seek(0) xml = HTMLTreeBuilder.parse(xhtml_file) head = xml.find('head') body = xml.find('body') assert head is not None assert body is not None template = kid.Template(file=template_name, head=head, body=body) return (template.serialize(output="html"))
def kidified_rest(rest_file, template_name): xhtml_file = StringIO() # prevent docutils from autoclosing the StringIO xhtml_file.close = lambda: None xhtml = publish_file(rest_file, writer_name='html', destination=xhtml_file, settings_overrides={"doctitle_xform": 0} ) xhtml_file.seek(0) xml = HTMLTreeBuilder.parse(xhtml_file) head = xml.find('head') body = xml.find('body') assert head is not None assert body is not None template=kid.Template(file=template_name, head=head, body=body) return (template.serialize(output="html"))