__init__.py 1.12 KB
Newer Older
juga  's avatar
juga committed
1
__version__ = '1.0.3'
2

3
4
import threading  # noqa

5
6
7
8
from . import globals  # noqa


class Settings:
9
10
11
12
13
14
15
16
17
18
19
    """Singleton settings for all the packages.
    This way change settings can be seen by all the packages that import it.

    It lives in ``__init__.py`` to leave open the possibility of having a
    ``settings.py`` module for user settings.

    .. note:: After refactoring, globals should only have constants.
      Any other variable that needs to be modified when initializing
      should be initialized here.

    """
20
21
22
23
24
    def __init__(self):
        # update this dict from globals (but only for ALL_CAPS settings)
        for setting in dir(globals):
            if setting.isupper():
                setattr(self, setting, getattr(globals, setting))
25
        self.end_event = threading.Event()
26
27
28
29
30
31

    def init_http_headers(self, nickname, uuid, tor_version):
        self.HTTP_HEADERS['Tor-Bandwidth-Scanner-Nickname'] = nickname
        self.HTTP_HEADERS['Tor-Bandwidth-Scanner-UUID'] = uuid
        self.HTTP_HEADERS['User-Agent'] += tor_version

32
33
34
    def set_end_event(self):
        self.end_event.set()

juga  's avatar
juga committed
35

36
settings = Settings()  # noqa