# Path: deluge/common.py
# def is_url(url):
#     """
#     A simple test to check if the URL is valid
# 
#     :param url: the url to test
#     :type url: string
#     :returns: True or False
#     :rtype: bool
# 
#     **Usage**
# 
#     >>> is_url("http://deluge-torrent.org")
#     True
# 
#     """
#     return url.partition('://')[0] in ("http", "https", "ftp", "udp")
# 
# Path: deluge/httpdownloader.py
# def download_file(url, filename, callback=None, headers=None, force_filename=False, allow_compression=True):
#     """
#     Downloads a file from a specific URL and returns a Deferred.  You can also
#     specify a callback function to be called as parts are received.
# 
#     :param url: the url to download from
#     :type url: string
#     :param filename: the filename to save the file as
#     :type filename: string
#     :param callback: a function to be called when a part of data is received,
#          it's signature should be: func(data, current_length, total_length)
#     :type callback: function
#     :param headers: any optional headers to send
#     :type headers: dictionary
#     :param force_filename: force us to use the filename specified rather than
#                            one the server may suggest
#     :type force_filename: boolean
#     :param allow_compression: allows gzip & deflate decoding
#     :type allow_compression: boolean
# 
#     :returns: the filename of the downloaded file
#     :rtype: Deferred
# 
#     :raises t.w.e.PageRedirect: when server responds with a temporary redirect
#          or permanently moved.
#     :raises t.w.e.Error: for all other HTTP response errors (besides OK)
#     """
#     url = str(url)
#     filename = str(filename)
#     if headers:
#         for key, value in headers.items():
#             headers[str(key)] = str(value)
# 
#     if allow_compression:
#         if not headers:
#             headers = {}
#         headers["accept-encoding"] = "deflate, gzip, x-gzip"
# 
#     scheme, host, port, path = client._parse(url)
#     factory = HTTPDownloader(url, filename, callback, headers, force_filename, allow_compression)
#     if scheme == "https":
#         from twisted.internet import ssl
#         reactor.connectSSL(host, port, factory, ssl.ClientContextFactory())
#     else:
#         reactor.connectTCP(host, port, factory)
# 
#     return factory.deferred


import os
import time
import shutil
import deluge.component as component
import deluge.configmanager
        import socket
from datetime import datetime, timedelta
from wsgiref.handlers import format_date_time
from urlparse import urljoin
from twisted.internet.task import LoopingCall
from twisted.internet import threads, defer
from twisted.web import error
from deluge.log import LOG as log
from deluge.plugins.pluginbase import CorePluginBase
from deluge.common import is_url
from deluge.core.rpcserver import export
from deluge.httpdownloader import download_file
from detect import detect_compression, detect_format, create_reader, UnknownFormatError
from readers import ReaderParseError

    def disable(self):
        self.config.save()
        log.debug('Blocklist: Plugin disabled')

    def update(self):
        pass

    ## Exported RPC methods ###
    @export
    def check_import(self, force=False):
        """
        Imports latest blocklist specified by blocklist url
        Only downloads/imports if necessary or forced

        :param force: optional argument to force download/import
        :type force: boolean
        :returns: a Deferred which fires when the blocklist has been imported
        :rtype: Deferred
        """


        # Reset variables
        self.filename = None
        self.force_download = force
        self.failed_attempts = 0
        self.auto_detected = False
        self.up_to_date = False
        if force:
            self.reader = None

# Path: deluge/common.py
# def is_url(url):
#     """
#     A simple test to check if the URL is valid
# 
#     :param url: the url to test
#     :type url: string
#     :returns: True or False
#     :rtype: bool
# 
#     **Usage**
# 
#     >>> is_url("http://deluge-torrent.org")
#     True
# 
#     """
#     return url.partition('://')[0] in ("http", "https", "ftp", "udp")
# 
# Path: deluge/httpdownloader.py
# def download_file(url, filename, callback=None, headers=None, force_filename=False, allow_compression=True):
#     """
#     Downloads a file from a specific URL and returns a Deferred.  You can also
#     specify a callback function to be called as parts are received.
# 
#     :param url: the url to download from
#     :type url: string
#     :param filename: the filename to save the file as
#     :type filename: string
#     :param callback: a function to be called when a part of data is received,
#          it's signature should be: func(data, current_length, total_length)
#     :type callback: function
#     :param headers: any optional headers to send
#     :type headers: dictionary
#     :param force_filename: force us to use the filename specified rather than
#                            one the server may suggest
#     :type force_filename: boolean
#     :param allow_compression: allows gzip & deflate decoding
#     :type allow_compression: boolean
# 
#     :returns: the filename of the downloaded file
#     :rtype: Deferred
# 
#     :raises t.w.e.PageRedirect: when server responds with a temporary redirect
#          or permanently moved.
#     :raises t.w.e.Error: for all other HTTP response errors (besides OK)
#     """
#     url = str(url)
#     filename = str(filename)
#     if headers:
#         for key, value in headers.items():
#             headers[str(key)] = str(value)
# 
#     if allow_compression:
#         if not headers:
#             headers = {}
#         headers["accept-encoding"] = "deflate, gzip, x-gzip"
# 
#     scheme, host, port, path = client._parse(url)
#     factory = HTTPDownloader(url, filename, callback, headers, force_filename, allow_compression)
#     if scheme == "https":
#         from twisted.internet import ssl
#         reactor.connectSSL(host, port, factory, ssl.ClientContextFactory())
#     else:
#         reactor.connectTCP(host, port, factory)
# 
#     return factory.deferred


# Path: deluge/plugins/blocklist/blocklist/core.py
import os
import time
import shutil
import deluge.component as component
import deluge.configmanager
        import socket
from datetime import datetime, timedelta
from wsgiref.handlers import format_date_time
from urlparse import urljoin
from twisted.internet.task import LoopingCall
from twisted.internet import threads, defer
from twisted.web import error
from deluge.log import LOG as log
from deluge.plugins.pluginbase import CorePluginBase
from deluge.common import is_url
from deluge.core.rpcserver import export
from deluge.httpdownloader import download_file
from detect import detect_compression, detect_format, create_reader, UnknownFormatError
from readers import ReaderParseError


    def disable(self):
        self.config.save()
        log.debug('Blocklist: Plugin disabled')

    def update(self):
        pass

    ## Exported RPC methods ###
    @export
    def check_import(self, force=False):
        """
        Imports latest blocklist specified by blocklist url
        Only downloads/imports if necessary or forced

        :param force: optional argument to force download/import
        :type force: boolean
        :returns: a Deferred which fires when the blocklist has been imported
        :rtype: Deferred
        """


        # Reset variables
        self.filename = None
        self.force_download = force
        self.failed_attempts = 0
        self.auto_detected = False
        self.up_to_date = False
        if force:
            self.reader = None

        self.is_url = is_url(self.config["url"])