# Path: webtools/utils/timezone.py
# def get_default_timezone(application):
#     global _localtime
# 
#     if _localtime is None:
#         default_tzname = get_default_timezone_name(application)
#         _localtime = pytz.timezone(default_tzname)
# 
#     return _localtime
# 
# def get_timezone(name):
#     return pytz.timezone(name)


from tornado import locale
from webtools.utils.timezone import get_default_timezone, get_timezone
    def get_user_locale(self):
        if "webtools_locale" in self.session:
            return locale.get(self.session["webtools_locale"])
        return None

    def _(self, message, plural_message=None, count=None):
        return self.locale.translate(message, plural_message=plural_message, count=count)

    def activate_locale(self, locale_name):
        """
        Activate a specific locale for current user.
        """
        self.session["webtools_locale"] = locale_name
        self._locale = locale.get(locale_name)


class TimezoneMixin(object):
    @property
    def timezone(self):
        if not hasattr(self, "_timezone"):
            self._timezone = self.get_user_timezone()
        return self._timezone

    def get_user_timezone(self):
        if "webtools_timezone" in self.session:
            return get_timezone(self.session["webtools_timezone"])
        return get_timezone(self.application.conf.DEFAULT_TZ)

    def activate_timezone(self, timezone_name):
        self.session["webtools_timezone"] = timezone_name

# Path: webtools/utils/timezone.py
# def get_default_timezone(application):
#     global _localtime
# 
#     if _localtime is None:
#         default_tzname = get_default_timezone_name(application)
#         _localtime = pytz.timezone(default_tzname)
# 
#     return _localtime
# 
# def get_timezone(name):
#     return pytz.timezone(name)


# Path: webtools/handlers/i18n.py
from tornado import locale
from webtools.utils.timezone import get_default_timezone, get_timezone

    def get_user_locale(self):
        if "webtools_locale" in self.session:
            return locale.get(self.session["webtools_locale"])
        return None

    def _(self, message, plural_message=None, count=None):
        return self.locale.translate(message, plural_message=plural_message, count=count)

    def activate_locale(self, locale_name):
        """
        Activate a specific locale for current user.
        """
        self.session["webtools_locale"] = locale_name
        self._locale = locale.get(locale_name)


class TimezoneMixin(object):
    @property
    def timezone(self):
        if not hasattr(self, "_timezone"):
            self._timezone = self.get_user_timezone()
        return self._timezone

    def get_user_timezone(self):
        if "webtools_timezone" in self.session:
            return get_timezone(self.session["webtools_timezone"])
        return get_timezone(self.application.conf.DEFAULT_TZ)

    def activate_timezone(self, timezone_name):
        self.session["webtools_timezone"] = timezone_name

        self._timezone = get_timezone(timezone_name)