# Path: deluge/component.py
# class ComponentAlreadyRegistered(Exception):
# class Component(object):
# class ComponentRegistry(object):
#     def __init__(self, name, interval=1, depend=None):
#     def _component_start_timer(self):
#     def _component_start(self):
#         def on_start(result):
#         def on_start_fail(result):
#     def _component_stop(self):
#         def on_stop(result):
#     def _component_pause(self):
#         def on_pause(result):
#     def _component_resume(self):
#         def on_resume(result):
#     def _component_shutdown(self):
#         def on_stop(result):
#     def __init__(self):
#     def register(self, obj):
#     def deregister(self, name):
#             def on_stop(result, name):
#     def start(self, names=[]):
#         def on_depends_started(result, name):
#     def stop(self, names=[]):
#     def pause(self, names=[]):
#     def resume(self, names=[]):
#     def shutdown(self):
#     def update(self):
# def get(name):
# 
# Path: deluge/ui/web/json_api.py
# class JSONComponent(component.Component):
#     def __init__(self, name, interval=1, depend=None):
#         super(JSONComponent, self).__init__(name, interval, depend)
#         self._json = component.get("JSON")
#         self._json.register_object(self, name)
# 
# def export(auth_level=AUTH_LEVEL_DEFAULT):
#     """
#     Decorator function to register an object's method as a RPC. The object
#     will need to be registered with a `:class:JSON` to be effective.
# 
#     :param func: the function to export
#     :type func: function
#     :keyword auth_level: the auth level required to call this method
#     :type auth_level: int
# 
#     """
#     global AUTH_LEVEL_DEFAULT, AuthError
#     if AUTH_LEVEL_DEFAULT is None:
#         from deluge.ui.web.auth import AUTH_LEVEL_DEFAULT, AuthError
# 
#     def wrap(func, *args, **kwargs):
#         func._json_export = True
#         func._json_auth_level = auth_level
#         return func
# 
#     if type(auth_level) is FunctionType:
#         func = auth_level
#         auth_level = AUTH_LEVEL_DEFAULT
#         return wrap(func)
#     else:
#         return wrap
# 
# Path: deluge/ui/web/auth_config.py
# AUTH_LEVEL_NONE = 0
# AUTH_LEVEL_READONLY = 1
# AUTH_LEVEL_NORMAL = 5
# AUTH_LEVEL_ADMIN = 10


import time
import random
import hashlib
import logging
from datetime import datetime, timedelta
from email.utils import formatdate
from twisted.internet.defer import Deferred
from twisted.internet.task import LoopingCall
from deluge import component
from deluge.ui.web.json_api import JSONComponent, export
from deluge.ui.web.auth_config import remote_methods_access
            from base64 import decodestring
# deluge is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with deluge.    If not, write to:
#   The Free Software Foundation, Inc.,
#   51 Franklin Street, Fifth Floor
#   Boston, MA  02110-1301, USA.
#
#    In addition, as a special exception, the copyright holders give
#    permission to link the code of portions of this program with the OpenSSL
#    library.
#    You must obey the GNU General Public License in all respects for all of
#    the code used other than OpenSSL. If you modify file(s) with this
#    exception, you may extend this exception to your version of the file(s),
#    but you are not obligated to do so. If you do not wish to do so, delete
#    this exception statement from your version. If you delete this exception
#    statement from all source files in the program, then also delete it here.
#
#

AUTH_LEVEL_NONE = 0
AUTH_LEVEL_READONLY = 1
AUTH_LEVEL_NORMAL = 5
AUTH_LEVEL_ADMIN = 10

AUTH_LEVEL_DEFAULT = AUTH_LEVEL_NORMAL


# Path: deluge/component.py
# class ComponentAlreadyRegistered(Exception):
# class Component(object):
# class ComponentRegistry(object):
#     def __init__(self, name, interval=1, depend=None):
#     def _component_start_timer(self):
#     def _component_start(self):
#         def on_start(result):
#         def on_start_fail(result):
#     def _component_stop(self):
#         def on_stop(result):
#     def _component_pause(self):
#         def on_pause(result):
#     def _component_resume(self):
#         def on_resume(result):
#     def _component_shutdown(self):
#         def on_stop(result):
#     def __init__(self):
#     def register(self, obj):
#     def deregister(self, name):
#             def on_stop(result, name):
#     def start(self, names=[]):
#         def on_depends_started(result, name):
#     def stop(self, names=[]):
#     def pause(self, names=[]):
#     def resume(self, names=[]):
#     def shutdown(self):
#     def update(self):
# def get(name):
# 
# Path: deluge/ui/web/json_api.py
# class JSONComponent(component.Component):
#     def __init__(self, name, interval=1, depend=None):
#         super(JSONComponent, self).__init__(name, interval, depend)
#         self._json = component.get("JSON")
#         self._json.register_object(self, name)
# 
# def export(auth_level=AUTH_LEVEL_DEFAULT):
#     """
#     Decorator function to register an object's method as a RPC. The object
#     will need to be registered with a `:class:JSON` to be effective.
# 
#     :param func: the function to export
#     :type func: function
#     :keyword auth_level: the auth level required to call this method
#     :type auth_level: int
# 
#     """
#     global AUTH_LEVEL_DEFAULT, AuthError
#     if AUTH_LEVEL_DEFAULT is None:
#         from deluge.ui.web.auth import AUTH_LEVEL_DEFAULT, AuthError
# 
#     def wrap(func, *args, **kwargs):
#         func._json_export = True
#         func._json_auth_level = auth_level
#         return func
# 
#     if type(auth_level) is FunctionType:
#         func = auth_level
#         auth_level = AUTH_LEVEL_DEFAULT
#         return wrap(func)
#     else:
#         return wrap
# 
# Path: deluge/ui/web/auth_config.py
# AUTH_LEVEL_NONE = 0
# AUTH_LEVEL_READONLY = 1
# AUTH_LEVEL_NORMAL = 5
# AUTH_LEVEL_ADMIN = 10


# Path: deluge/ui/web/auth.py
import time
import random
import hashlib
import logging
from datetime import datetime, timedelta
from email.utils import formatdate
from twisted.internet.defer import Deferred
from twisted.internet.task import LoopingCall
from deluge import component
from deluge.ui.web.json_api import JSONComponent, export
from deluge.ui.web.auth_config import remote_methods_access
            from base64 import decodestring

# deluge is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with deluge.    If not, write to:
#   The Free Software Foundation, Inc.,
#   51 Franklin Street, Fifth Floor
#   Boston, MA  02110-1301, USA.
#
#    In addition, as a special exception, the copyright holders give
#    permission to link the code of portions of this program with the OpenSSL
#    library.
#    You must obey the GNU General Public License in all respects for all of
#    the code used other than OpenSSL. If you modify file(s) with this
#    exception, you may extend this exception to your version of the file(s),
#    but you are not obligated to do so. If you do not wish to do so, delete
#    this exception statement from your version. If you delete this exception
#    statement from all source files in the program, then also delete it here.
#
#

AUTH_LEVEL_NONE = 0
AUTH_LEVEL_READONLY = 1
AUTH_LEVEL_NORMAL = 5
AUTH_LEVEL_ADMIN = 10

AUTH_LEVEL_DEFAULT = AUTH_LEVEL_NORMAL


class AuthError(Exception):