Exemplo n.º 1
0
    def escape(self, dirty_text):
        text = html.escape(dirty_text)

        text = text.replace("\n", "<br>")

        mentions = mention_re.findall(text)
        for mention in mentions:
            user = app.login_name_exists(mention)
            if user:
                text = text.replace(
                    "[@%s]" % str(mention),
                    """<a href="/member/%s" class="hover_user">@%s</a>""" %
                    (user["my_url"], user["display_name"]), 1)
            else:
                text = text.replace("[@%s]" % str(mention), "", 1)

        smilies = app.get_local_smilies()
        for smiley in smilies:
            img_html = """<img src="%s" />""" % (os.path.join(
                "/static/smilies", smiley["filename"]), )
            text = text.replace(":" + smiley["code"] + ":", img_html)

        urls = url_rgx.findall(text)
        for url in urls:
            text = text.replace(
                url, """<a href="%s" target="_blank">%s</a>""" % (
                    str(url),
                    str(url),
                ), 1)

        return text
Exemplo n.º 2
0
    def tweet_clear(self, dirty_text):
        text = html.escape(dirty_text)

        urls = url_rgx.findall(text)
        for url in urls:
            text = text.replace(
                url, """<a href="%s" target="_blank">%s</a>""" % (
                    str(url),
                    str(url),
                ), 1)

        hashtags = twitter_hashtag_re.findall(text)
        for hashtag in hashtags:
            text = text.replace(
                "#" + hashtag, """<a href="%s" target="_blank">%s</a>""" % (
                    str("https://twitter.com/hashtag/") + str(hashtag),
                    str("#") + str(hashtag),
                ), 1)

        users = twitter_user_re.findall(text)
        for user in users:
            text = text.replace(
                "@" + user, """<a href="%s" target="_blank">%s</a>""" % (
                    str("https://twitter.com/") + str(user),
                    str("@") + str(user),
                ), 1)

        return text
def deEmojify(text):
    regrex_pattern = re.compile(
        pattern="["
        u"\U0001F600-\U0001F64F"  # emoticons
        u"\U0001F300-\U0001F5FF"  # symbols & pictographs
        u"\U0001F680-\U0001F6FF"  # transport & map symbols
        u"\U0001F1E0-\U0001F1FF"  # flags (iOS)
        "]+",
        flags=re.UNICODE)
    text = regrex_pattern.sub(r'', text)
    text = text.replace('\n', ' ')
    text = re.sub(' +', ' ', text)

    return text
Exemplo n.º 4
0
            def visit_column(element, compiler, **kw):
                """Patch for sqlalchemy bug

                TODO: sqlalchemy 1.2 release should be doing this on its own.
                Patch only if the column clause is specific for DateTime
                set and granularity is selected.
                """
                text = compiler.visit_column(element, **kw)
                try:
                    if (element.is_literal
                            and hasattr(element.type, 'python_type')
                            and type(element.type) is DateTime):
                        text = text.replace('%%', '%')
                except NotImplementedError:
                    # Some elements raise NotImplementedError for python_type
                    pass
                return text
Exemplo n.º 5
0
            def visit_column(element, compiler, **kw):
                """Patch for sqlalchemy bug

                TODO: sqlalchemy 1.2 release should be doing this on its own.
                Patch only if the column clause is specific for DateTime
                set and granularity is selected.
                """
                text = compiler.visit_column(element, **kw)
                try:
                    if (
                            element.is_literal and
                            hasattr(element.type, 'python_type') and
                            type(element.type) is DateTime
                    ):
                        text = text.replace('%%', '%')
                except NotImplementedError:
                    # Some elements raise NotImplementedError for python_type
                    pass
                return text
Exemplo n.º 6
0
def replace_query_from_dic(text, dic):
    for i, j in dic.items():
        text = text.replace(i, j)
    return text
Exemplo n.º 7
0
def _gerrit_rest_api_call(uri):
    ret_val = requests.get(uri)
    ret_val.raise_for_status()
    text = ret_val.text
    text = text.replace(')]}\'', '')
    return json.loads(text)