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 listAnchorNames(self): """Return a list of Anchor names""" results = [] tree = HTMLTreeBuilder.TreeBuilder() tree.feed('<root>%s</root>' % self.context.getPrimaryField().getAccessor(self.context)()) rootnode = tree.close() for x in rootnode.getiterator(): if x.tag == "a": if "name" in x.keys(): results.append(x.attrib['name']) return results
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"))
def getDetails(self): """Builds a JSON object based on the details of this object. """ utility = getUtility(ITinyMCE) anchor_portal_types = utility.containsanchors.split('\n') image_portal_types = utility.imageobjects.split('\n') results = {} results['title'] = self.context.title_or_id() results['description'] = self.context.Description() if self.context.portal_type in image_portal_types: if IPhoto.providedBy(self.context): image_field = self.context.getField('photo') results['owner'] = self.context.owner_name results['date_y'] = self.context.year results['date_m'] = self.context.month results['date_d'] = self.context.day else: image_field = self.context.getField('image') results['thumb'] = self.context.absolute_url() + "/image_thumb" results['scales'] = utility.getImageScales(image_field, context=self.context) else: results['thumb'] = "" if self.context.portal_type in anchor_portal_types: results['anchors'] = [] tree = HTMLTreeBuilder.TreeBuilder() tree.feed('<root>%s</root>' % self.context.getPrimaryField().getAccessor(self.context)()) rootnode = tree.close() for x in rootnode.getiterator(): if x.tag == "a": if "name" in x.keys(): results['anchors'].append(x.attrib['name']) else: results['anchors'] = [] return json.dumps(results)
def fromstring(text): parser = HTMLTreeBuilder.TreeBuilder() text = '<root>%s</root>' % text parser.feed(text) return parser.close()