コード例 #1
0
ファイル: serializers.py プロジェクト: rollick/bluebottle
 def to_native(self, value):
     if not value or not standalone_url_re.match(value):
         return ""
     url = value.strip()
     try:
         response = providers.request(url, **self.params)
     except ProviderException:
         return ""
     else:
         return full_handler(url, response, **self.params)
コード例 #2
0
ファイル: serializers.py プロジェクト: gichuru/bluebottle
 def to_native(self, value):
     if not value or not standalone_url_re.match(value):
         return ""
     url = value.strip()
     try:
         response = providers.request(url, **self.params)
     except ProviderException:
         return ""
     else:
         html = full_handler(url, response, **self.params)
         # Tweak for youtube to hide controls and info bars.
         html = html.replace('feature=oembed', 'feature=oembed&showinfo=0&controls=0')
         return html
コード例 #3
0
ファイル: serializers.py プロジェクト: gannetson/bluebottle
 def to_native(self, value):
     if not value or not standalone_url_re.match(value):
         return ""
     url = value.strip()
     if value == 'https://vimeo.com/85425318':
         return "<iframe src=\"//player.vimeo.com/video/85425318\" hard=\"code\" width=\"1024\" height=\"576\" frameborder=\"0\" title=\"How it works - Cares\" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>"
     try:
         response = providers.request(url, **self.params)
     except ProviderException:
         return ""
     except URLError:
         return ""
     else:
         html = full_handler(url, response, **self.params)
         # Tweak for youtube to hide controls and info bars.
         html = html.replace('feature=oembed', 'feature=oembed&showinfo=0&controls=0')
         return html
コード例 #4
0
def make_oembedplus(text, oembed_providers, **params):
    lines = text.splitlines()
    parsed = []
    home_url = re.escape(url_for('public.home', _external=True))
    home_url_re = re.compile('(%s.+)' % home_url)
    for line in lines:
        if home_url_re.match(line):
            line = re.sub(home_url_re, repl_onebox, line)
        elif standalone_url_re.match(line):
            url = line.strip()
            try:
                response = oembed_providers.request(url, **params)
            except Exception as e:
                logging.info("OEmbed could not parse: <%s>" % url)
            else:
                line = full_handler(url, response, **params)
        parsed.append(line)
    return '\n'.join(parsed)
コード例 #5
0
 def to_representation(self, value):
     if not value or not standalone_url_re.match(value):
         return ""
     url = value.strip()
     if value == 'https://vimeo.com/85425318':
         return "<iframe src=\"//player.vimeo.com/video/85425318\" " \
                "hard=\"code\" width=\"1024\" height=\"576\" " \
                "frameborder=\"0\" title=\"How it works - Cares\" " \
                "webkitallowfullscreen mozallowfullscreen " \
                "allowfullscreen></iframe>"
     try:
         response = providers.request(url, **self.params)
     except ProviderException:
         return ""
     except URLError:
         return ""
     else:
         html = full_handler(url, response, **self.params)
         # Tweak for youtube to hide controls and info bars.
         html = html.replace('feature=oembed',
                             'feature=oembed&showinfo=0&controls=0')
         return html