# Path: coldsweat/markup.py
# HTML_RESERVED_CHARREFS = 38, 60, 62, 34
# HTML_RESERVED_ENTITIES = 'amp', 'lt', 'gt', 'quot'
#     FEED_TYPES = [
#         'application/rss+xml',
#         'text/xml',
#         'application/atom+xml',
#         'application/x.atom+xml',
#         'application/x-atom+xml'
#     ]
# def _normalize_attrs(attrs):
#     def handle_starttag(self, tag, attrs):
#     def handle_endtag(self, tag):
#     def unknown_starttag(self, tag, attrs):
#     def unknown_endtag(self, tag):
#     def __init__(self, xhtml_mode=False):
#     def reset(self):
#     def output(self):
#     def unknown_starttag(self, tag, attrs):
#     def unknown_endtag(self, tag):
#     def handle_charref(self, ref):
#     def handle_entityref(self, ref):
#     def handle_data(self, text):
#     def handle_comment(self, text):
#     def handle_pi(self, text):
#     def handle_decl(self, text):
#     def handle_starttag(self, tag, attrs):
#     def handle_endtag(self, tag):
#     def handle_charref(self, ref):
#     def handle_entityref(self, ref):
#     def __init__(self, base_url=''):
#     def start_base(self, attrs):
#     def start_link(self, attrs):                
#     def __init__(self, blacklist):
#     def start_a(self, attrs):
#     def end_a(self):
#     def start_img(self, attrs):
#     def is_blacklisted(self, value):
# def _parse(parser, data):    
# def find_feed_links(data, base_url=''):
# def sniff_feed(data): 
# def strip_html(data):
# def scrub_html(data, blacklist):
# class BaseParser(HTMLParser):
# class BaseProcessor(BaseParser):
# class Stripper(BaseProcessor):
# class FeedLinkFinder(BaseParser):
# class Scrubber(BaseProcessor):


import os
from coldsweat import *
from coldsweat.plugins import *
from coldsweat import markup
'''
Description: Scrubber plugin. Remove links and images from 
  feed entries according to given blacklist

Copyright (c) 2013—2016 Andrea Peltrin
License: MIT (see LICENSE for details)
'''



DOMAINS = []    

@event('fetch_started')
def fetcher_started():
    if DOMAINS: return # Already initialized
    
    blacklist = getattr(config.plugins, 'scrubber_blacklist', '')
    
    if blacklist:
      DOMAINS.extend(blacklist.split(','))    
    
    if DOMAINS:
      logger.debug(u"scrubber plugin: loaded blacklist: %s" % ', '.join(DOMAINS))
    else:
      logger.info(u"scrubber plugin: blacklist is empty, nothing to do")
    
    
@event('entry_parsed')
def entry_parsed(entry, parsed_entry):
    if DOMAINS and ('html' in entry.content_type):

# Path: coldsweat/markup.py
# HTML_RESERVED_CHARREFS = 38, 60, 62, 34
# HTML_RESERVED_ENTITIES = 'amp', 'lt', 'gt', 'quot'
#     FEED_TYPES = [
#         'application/rss+xml',
#         'text/xml',
#         'application/atom+xml',
#         'application/x.atom+xml',
#         'application/x-atom+xml'
#     ]
# def _normalize_attrs(attrs):
#     def handle_starttag(self, tag, attrs):
#     def handle_endtag(self, tag):
#     def unknown_starttag(self, tag, attrs):
#     def unknown_endtag(self, tag):
#     def __init__(self, xhtml_mode=False):
#     def reset(self):
#     def output(self):
#     def unknown_starttag(self, tag, attrs):
#     def unknown_endtag(self, tag):
#     def handle_charref(self, ref):
#     def handle_entityref(self, ref):
#     def handle_data(self, text):
#     def handle_comment(self, text):
#     def handle_pi(self, text):
#     def handle_decl(self, text):
#     def handle_starttag(self, tag, attrs):
#     def handle_endtag(self, tag):
#     def handle_charref(self, ref):
#     def handle_entityref(self, ref):
#     def __init__(self, base_url=''):
#     def start_base(self, attrs):
#     def start_link(self, attrs):                
#     def __init__(self, blacklist):
#     def start_a(self, attrs):
#     def end_a(self):
#     def start_img(self, attrs):
#     def is_blacklisted(self, value):
# def _parse(parser, data):    
# def find_feed_links(data, base_url=''):
# def sniff_feed(data): 
# def strip_html(data):
# def scrub_html(data, blacklist):
# class BaseParser(HTMLParser):
# class BaseProcessor(BaseParser):
# class Stripper(BaseProcessor):
# class FeedLinkFinder(BaseParser):
# class Scrubber(BaseProcessor):


# Path: plugins/scrubber.py
import os
from coldsweat import *
from coldsweat.plugins import *
from coldsweat import markup

'''
Description: Scrubber plugin. Remove links and images from 
  feed entries according to given blacklist

Copyright (c) 2013—2016 Andrea Peltrin
License: MIT (see LICENSE for details)
'''



DOMAINS = []    

@event('fetch_started')
def fetcher_started():
    if DOMAINS: return # Already initialized
    
    blacklist = getattr(config.plugins, 'scrubber_blacklist', '')
    
    if blacklist:
      DOMAINS.extend(blacklist.split(','))    
    
    if DOMAINS:
      logger.debug(u"scrubber plugin: loaded blacklist: %s" % ', '.join(DOMAINS))
    else:
      logger.info(u"scrubber plugin: blacklist is empty, nothing to do")
    
    
@event('entry_parsed')
def entry_parsed(entry, parsed_entry):
    if DOMAINS and ('html' in entry.content_type):

        entry.content = markup.scrub_html(entry.content, DOMAINS)    