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()
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,