# -*- coding: utf-8 -*-

import inspect

import packages
from core import *

from core import __version__

timeout = None

class settings:
    """Context manager for settings."""
    
    cache = {}
    
    def __init__(self, timeout):
        self.module = inspect.getmodule(self)
        
        # Cache settings
        self.cache['timeout'] = self.module.timeout
        
        self.module.timeout = timeout
        
    def __enter__(self):
        pass
        
    def __exit__(self, type, value, traceback):
        # Restore settings 
        for key in self.cache:
            setattr(self.module, key, self.cache[key])

# -*- coding: utf-8 -*-

import inspect

import packages
from core import *

from core import __version__

timeout = None

class settings:
    
    def __init__(self, **settings):
        self._cache_settings(**settings)
        self._alter_settings(**settings)
        
    def __enter__(self):
        pass
        
    def __exit__(self, type, value, traceback):
        self._restore_settings()
        
    def _cache_settings(self, **settings):
        self.cache = {}
        for setting in settings:
            self.cache[setting] = globals()[setting]
        
    def _alter_settings(self, **settings):
        for setting, value in settings.items():
            globals()[setting] = value
        
    def _restore_settings(self):
        for setting, value in self.cache.items():
            globals()[setting] = value
Refactor settings