# Path: oembed/constants.py
# OEMBED_DEFAULT_PARSE_HTML = getattr(settings, 'OEMBED_DEFAULT_PARSE_HTML', True)
# 
# URL_RE = re.compile(URL_PATTERN)


import re
import oembed
from oembed.constants import OEMBED_DEFAULT_PARSE_HTML, URL_RE
from oembed.exceptions import OEmbedException
from oembed.parsers import text_parser, html_parser
    
    def handle_extracted_urls(self, url_set, maxwidth=None, maxheight=None, resource_type=None):
        embeds = []
        
        for user_url in url_set:
            try:
                resource = oembed.site.embed(user_url, maxwidth=maxwidth, maxheight=maxheight)
            except OEmbedException:
                continue
            else:
                if not resource_type or resource.type == resource_type:
                    data = resource.get_data()
                    data['original_url'] = user_url
                    embeds.append(data)
        
        return embeds
    
    def strip(self, text, *args, **kwargs):
        """
        Try to maintain parity with what is extracted by extract since strip
        will most likely be used in conjunction with extract
        """
        if OEMBED_DEFAULT_PARSE_HTML:
            extracted = self.extract_oembeds_html(text, *args, **kwargs)
        else:
            extracted = self.extract_oembeds(text, *args, **kwargs)
        
        matches = [r['original_url'] for r in extracted]
        match_handler = lambda m: m.group() not in matches and m.group() or ''
        

# Path: oembed/constants.py
# OEMBED_DEFAULT_PARSE_HTML = getattr(settings, 'OEMBED_DEFAULT_PARSE_HTML', True)
# 
# URL_RE = re.compile(URL_PATTERN)


# Path: oembed/consumer.py
import re
import oembed
from oembed.constants import OEMBED_DEFAULT_PARSE_HTML, URL_RE
from oembed.exceptions import OEmbedException
from oembed.parsers import text_parser, html_parser

    
    def handle_extracted_urls(self, url_set, maxwidth=None, maxheight=None, resource_type=None):
        embeds = []
        
        for user_url in url_set:
            try:
                resource = oembed.site.embed(user_url, maxwidth=maxwidth, maxheight=maxheight)
            except OEmbedException:
                continue
            else:
                if not resource_type or resource.type == resource_type:
                    data = resource.get_data()
                    data['original_url'] = user_url
                    embeds.append(data)
        
        return embeds
    
    def strip(self, text, *args, **kwargs):
        """
        Try to maintain parity with what is extracted by extract since strip
        will most likely be used in conjunction with extract
        """
        if OEMBED_DEFAULT_PARSE_HTML:
            extracted = self.extract_oembeds_html(text, *args, **kwargs)
        else:
            extracted = self.extract_oembeds(text, *args, **kwargs)
        
        matches = [r['original_url'] for r in extracted]
        match_handler = lambda m: m.group() not in matches and m.group() or ''
        

        return re.sub(URL_RE, match_handler, text)