def status_creation_handler(sender, **kwargs): status = kwargs.get('instance', None) created = kwargs.get('created', False) if not created or not isinstance(status, Status): return # convert status body to markdown and bleachify bl = Bleach() status.status = urlize(status.status) status.status = bl.clean(markdown(status.status), tags=TAGS) status.save() # fire activity activity = Activity( actor=status.author, verb='http://activitystrea.ms/schema/1.0/post', status=status, ) if status.project: activity.target_project = status.project activity.save() # Send notifications. if activity.target_project: activity.target_project.send_update_notification(activity)
def sanitize_html(input): # HTML sanitizer and auto-linker # http://coffeeonthekeyboard.com/bleach-html-sanitizer-and-auto-linker-for-django-344/ bl = Bleach() cleaned_input = bl.clean( input, tags=ALLOWED_TAGS ) cleaned_input = bl.linkify( cleaned_input ) cleaned_input = linebreaks( cleaned_input )# linebreaks converts newlines into <p> and <br />s. return cleaned_input
def __init__(self, fp, site): TextPost.__init__(self, fp, site) self.type = 'text' # TODO: this ASCII encoding hack is *not* OK, man! NOT OK self.markdown_text = markdown2.markdown(self.text).encode('ascii', 'ignore') bl = Bleach() self.markdown_text = bl.linkify(self.markdown_text, nofollow=False)
def project_markdown_handler(sender, **kwargs): project = kwargs.get('instance', None) if not isinstance(project, Project): return log.debug("Creating html project description") if project.detailed_description: bl = Bleach() project.detailed_description_html = bl.clean( markdown(project.detailed_description), tags=TAGS, attributes=ALLOWED_ATTRIBUTES)
def __init_xattr__(self): self.attribs = xattr.xattr(self.filepath) self.source_url = self.get_x_attr('com.apple.metadata:kMDItemWhereFroms') if self.source_url: self.source_url = self.source_url.replace('(', '') self.source_url = self.source_url.replace(')', '') self.source_url = self.source_url.replace('"', '') self.source_url = self.source_url.replace(' ', '') self.finder_comment = self.get_x_attr('com.apple.metadata:kMDItemFinderComment') if self.finder_comment: bl = Bleach() self.finder_comment = bl.linkify(self.finder_comment, nofollow=False)
def _proccess_tweet(self, text): if not getattr(self, 'bleach', None): self.bleach = Bleach() text = re.sub(r'(?m)(^|\s)@(\w+)', lambda m: m.group(1) + '<a href="http://twitter.com/' + m.group(2) + '"> @' + m.group(2) + '</a>', text) text = self.bleach.linkify(text) return text
def status_creation_handler(sender, **kwargs): status = kwargs.get('instance', None) created = kwargs.get('created', False) if not created or not isinstance(status, Status): return # convert status body to markdown and bleachify bl = Bleach() status.status = urlize(status.status) status.status = bl.clean(markdown(status.status), tags=TAGS) status.save() # fire activity activity = Activity( actor=status.author, verb='http://activitystrea.ms/schema/1.0/post', status=status, ) if status.project: activity.target_project = status.project activity.save()
def todo_creation_handler(sender, **kwargs): todo = kwargs.get('instance', None) created = kwargs.get('created', False) if not created or not isinstance(todo, Todo): return # convert todo body to markdown and bleachify bl = Bleach() todo.title = urlize(todo.title) todo.description = urlize(todo.description) todo.title = bl.clean(markdown(todo.title), tags=TAGS) todo.description = bl.clean(markdown(todo.description), tags=TAGS) todo.save() # fire activity activity = Activity( actor=todo.author, verb='http://activitystrea.ms/schema/1.0/post', target_todo=todo, ) if todo.project: activity.target_project = todo.project activity.save()
class TwitterStreamHandler(BaseHandler, tornado.auth.TwitterMixin): @tornado.web.authenticated @tornado.web.asynchronous def get(self): self.twitter_request("/statuses/home_timeline", access_token=self.get_current_user()['access_token'], callback=self.async_callback(self._on_finish_get), count=50) @tornado.web.authenticated @tornado.web.asynchronous def post(self): since = self.get_argument('since') logging.info(since) self.twitter_request("/statuses/home_timeline", access_token=self.get_current_user()['access_token'], callback=self.async_callback(self._on_finish_post), since_id=since, count=200) def _on_finish_get(self, posts): if not posts: raise tornado.web.HTTPError(500); for post in posts: post['text'] = self._proccess_tweet(post['text']) self.finish(self.render_string("stream.html", posts=posts)) def _on_finish_post(self, posts): if not posts: raise tornado.web.HTTPError(500); for post in posts: post['text'] = self._proccess_tweet(post['text']) post['html'] = self.render_string("post.html", post=post) self.finish(tornado.escape.json_encode(posts)) def _proccess_tweet(self, text): if not getattr(self, 'bleach', None): self.bleach = Bleach() text = re.sub(r'(?m)(^|\s)@(\w+)', lambda m: m.group(1) + '<a href="http://twitter.com/' + m.group(2) + '"> @' + m.group(2) + '</a>', text) text = self.bleach.linkify(text) return text
pkgdir = os.path.dirname(os.path.abspath(__file__)) os.sys.path.append(pkgdir) apktool = os.path.join(pkgdir, 'apktool', 'apktool') signapk_dir = os.path.join(pkgdir, 'signapk') output_apk = apkname + ".Eink.apk" outdir = apkname + "-out" # dump apk os.system("{apktool} d -f -o {apkdir} {apk}".format(apktool=apktool, apkdir=outdir, apk=apk)) # handle from bleach import Bleach bleacher = Bleach(outdir) bleacher.run() # build again tmp_apk = apkname + 'tmp' os.system("{apktool} b -f -o {apk} {apkdir}".format(apktool=apktool, apk=tmp_apk, apkdir=outdir)) # signapk os.system("java -jar {path}/signapk.jar {path}/certificate.pem {path}/key.pk8 \ {in_apk} {out_apk}".format(path=signapk_dir, in_apk=tmp_apk, out_apk=output_apk)) # clean up os.system("rm -rf " + outdir) os.system("rm " + tmp_apk)
import re import lxml.etree import lxml.html.soupparser from django.conf import settings from bleach import Bleach bleach = Bleach() def tidy_up(entry, log): # TODO Security, mostly using bleach to linkify and cleanup (tidy style) html_tags = [ 'a', 'abbr', 'b', 'blockquote', 'br', 'cite', 'code', 'dd', 'dl', 'div', 'dt', 'em', 'font', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'img', 'hr', 'math', 'mi', 'mo', 'mn', 'mfrac', 'mrow', 'msqrt', 'msup', 'pre', 'span', 'strong', 'svg', 'path', 'line', 'circle', 'strike', 'strong', 'sub' 'table', 'caption', 'thead', 'tfoot', 'tbody', 'tr', 'td', 'th', 'colgroup', 'col', 'tt', 'var', 'ul', 'li', 'ol', 'p', 'q' ] a_attrs = ['href', 'rel', 'title'] img_attrs = ['align', 'alt', 'border', 'height', 'src', 'width'] basic_attrs = ['class', 'dir', 'lang', 'title'] [x.extend(basic_attrs) for x in (a_attrs, img_attrs)] attrs = { 'a': a_attrs,