Beispiel #1
0
    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)
Beispiel #2
0
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
Beispiel #3
0
    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)
Beispiel #4
0
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