Update by natay on Wed May 15 09:23:15 EDT 2019 from H7-D25RF0PLGQ18
@@ -2,87 +2,13 @@ import re
import bleach
import logging
import uuid
-import requests
+
from datetime import datetime, timedelta
-from django.template import loader, Context
+from django.template import loader
from django.utils.timezone import utc
-# Allowed html content.
-ALLOWED_TAGS = "p div br code pre h1 h2 h3 h4 hr span s sub sup b i img strong strike em underline super table thead tr th td tbody".split()
-ALLOWED_STYLES = 'color font-weight background-color width height'.split()
-DEFAULT_ATTRIBUTES = {
- '*': ['class', 'style'],
- 'a': ['href', 'rel'],
- 'img': ['src', 'alt', 'width', 'height'],
- 'table': ['border', 'cellpadding', 'cellspacing'],
-
-}
-
-ALLOWED_TAGS = bleach.ALLOWED_TAGS + ALLOWED_TAGS
-ALLOWED_STYLES = bleach.ALLOWED_STYLES + ALLOWED_STYLES
-ALLOWED_ATTRIBUTES = dict(bleach.ALLOWED_ATTRIBUTES)
-ALLOWED_ATTRIBUTES.update(DEFAULT_ATTRIBUTES)
-
-
-def user_pattern(base_site):
- user = fr"^http(s)?://{base_site}/accounts/profile/(?P<uid>(\w+))(/)?$"
- return user
-
-
-def post_pattern(base_site):
- post_pattern = fr"^http(s)?://{base_site}/p/(?P<uid>(\w+))(/)?$"
- return post_pattern
-
-
-# Matches gists that may be embeded.
-GIST_PATTERN = r"^https://gist.github.com/(?P<uid>([\w/]+))"
-# Matches Youtube video links.
-YOUTUBE_PATTERN1 = r"^http(s)?://www.youtube.com/watch\?v=(?P<uid>([\w-]+))(/)?"
-YOUTUBE_PATTERN2 = r"https://www.youtube.com/embed/(?P<uid>([\w-]+))(/)?"
-YOUTUBE_PATTERN3 = r"https://youtu.be/(?P<uid>([\w-]+))(/)?"
-
-# Twitter: tweets to embed.
-TWITTER_PATTERN = r"http(s)?://twitter.com/\w+/status(es)?/(?P<uid>([\d]+))"
-
-logger = logging.getLogger(__name__)
-
-
-def clean(text):
- """
- Sanitize text with no other substitutions
- """
- html = bleach.clean(text, tags=ALLOWED_TAGS,
- attributes=ALLOWED_ATTRIBUTES, styles=ALLOWED_STYLES)
- return html
-
-
-def get_embedded_tweet(tweet_id):
- """
- Get the HTML code with the embedded tweet.
- It requires an API call at https://api.twitter.com/1/statuses/oembed.json as documented here:
- https://dev.twitter.com/docs/embedded-tweets - section "Embedded Tweets for Developers"
- https://dev.twitter.com/docs/api/1/get/statuses/oembed
-
- Params:
- tweet_id -- a tweet's numeric id like 2311234267 for the tweet at
- https://twitter.com/Linux/status/2311234267
- """
- try:
- response = requests.get("https://api.twitter.com/1/statuses/oembed.json?id={}".format(
- tweet_id))
- return response.json()['html']
- except:
- return ''
-
-
-def get_target_text(pattern):
-
-
-
- return pattern_map.get(pattern)
-
def fixcase(name):
return name.upper() if len(name) == 1 else name.lower()
