# Path: khayyam/formatting/directives/base.py
# class Directive(object):
#     """
#     Base class for all formatting directives.
# 
#     """
# 
#     def __init__(self, key, name, regex, type_, formatter=None, post_parser=None):
#         self.key = key
#         self.name = name
#         self.regex = regex
#         self.type_ = type_
#         if formatter:
#             self.format = formatter
#         if post_parser:
#             self.post_parser = post_parser
# 
#     def __repr__(self):  # pragma: no cover
#         return '%' + self.key
# 
#     def post_parser(self, ctx, formatter):  # pragma: no cover
#         """
#         In overridden method, It should parse the formatted value from the given string.
#         :param ctx:
#         :param formatter:
#         :return:
#         """
#         pass
# 
#     def format(self, d):  # pragma: no cover
#         """
#         In overridden method, It Should return string representation of the given argument.
# 
#         :param d: a value to format
#         :return: Formatted value.
#         :rtype: str
#         """
#         return d
# 
# Path: khayyam/formatting/directives/persian.py
# class PersianNumberDirective(Directive):
#     def __init__(self, key, name, regex, zero_padding=False, zero_padding_length=2):
#     def format(self, i):
#     def post_parser(self, ctx, formatter):
# 
# Path: khayyam/timezones.py
# class Timezone(tzinfo):
# 
#     def __init__(self, offset, dst_offset=None, dst_checker=None, name=None):
#         assert (isinstance(offset, timedelta))
#         self._offset = offset
#         self._dst_offset = dst_offset
#         self._dst_checker = dst_checker
#         self._name = name
#         super(Timezone, self).__init__()
# 
#     def fromutc(self, dt):
#         if dt.tzinfo is None:
#             raise ValueError('The object: %s is naive.' % dt)
# 
#         if dt.tzinfo != self:
#             raise ValueError('Datetime timezone mismatch: %s != %s' % (dt.tzinfo, self))
# 
#         utc_offset = dt.utcoffset()
#         dst_offset = dt.dst()
#         delta = utc_offset - dst_offset  # this is self's standard offset
# 
#         if delta:
#             dt += delta  # convert to standard local time
#             dst_offset = dt.dst()
# 
#         if dst_offset:
#             return dt + dst_offset
#         else:
#             return dt
# 
#     def utcoffset(self, dt):
#         if self._is_dst(dt):
#             return self._offset + self._dst_offset
#         else:
#             return self._offset
# 
#     def dst(self, dt):
#         if self._dst_offset and self._is_dst(dt):
#             return self._dst_offset
#         else:
#             return ZERO_DELTA
# 
#     def __unicode__(self):
#         off = self._offset
#         return '%s%.2d:%.2d%s' % (
#             '+' if off.total_seconds() >= 0 else '-',
#             int(off.total_seconds() / 3600),
#             int((off.total_seconds() % 3600) / 60),
#             (' dst:%d' % (self._dst_offset.total_seconds() / 60)) if self._dst_offset else ''
#         )
# 
#     __repr__ = force_encoded_string_output(__unicode__)
# 
#     def tzname(self, dt):
#         if self._name:
#             return self._name
#         else:
#             return repr(self)
# 
#     def _is_dst(self, dt):
#         if self._dst_checker:
#             return self._dst_checker(dt)
#         return False
# 
#     def __hash__(self):
#         return hash(self._offset) ^ hash(self._dst_offset)


import re
from .base import Directive
from .persian import PersianNumberDirective, persian_to_eng
from datetime import timedelta
from khayyam.timezones import Timezone
    """

    def format(self, d):
        if not d.tzinfo:
            return ''
        seconds = d.utcoffset().total_seconds()
        return '%s%.2d:%.2d' % (
            '+' if seconds >= 0 else '-',
            int(seconds / 3600),
            int((seconds % 3600) / 60),
        )

    def post_parser(self, ctx, formatter):
        exp = ctx[self.name]
        if exp.strip() == '':
            return
        regex = '(?P<posneg>[-+]?)(?P<hour>\d{2}):(?P<minute>\d{2})'
        match = re.match(regex, exp)
        d = match.groupdict()
        posneg = lambda i: 0 - i if d['posneg'] == '-' else i
        hours = int(d['hour'])
        minutes = int(d['minute'])
        if not hours and not minutes:
            return
        ctx.update(dict(tzinfo=Timezone(timedelta(
            hours = posneg(hours),
            minutes = posneg(minutes)
        ))))



# Path: khayyam/formatting/directives/base.py
# class Directive(object):
#     """
#     Base class for all formatting directives.
# 
#     """
# 
#     def __init__(self, key, name, regex, type_, formatter=None, post_parser=None):
#         self.key = key
#         self.name = name
#         self.regex = regex
#         self.type_ = type_
#         if formatter:
#             self.format = formatter
#         if post_parser:
#             self.post_parser = post_parser
# 
#     def __repr__(self):  # pragma: no cover
#         return '%' + self.key
# 
#     def post_parser(self, ctx, formatter):  # pragma: no cover
#         """
#         In overridden method, It should parse the formatted value from the given string.
#         :param ctx:
#         :param formatter:
#         :return:
#         """
#         pass
# 
#     def format(self, d):  # pragma: no cover
#         """
#         In overridden method, It Should return string representation of the given argument.
# 
#         :param d: a value to format
#         :return: Formatted value.
#         :rtype: str
#         """
#         return d
# 
# Path: khayyam/formatting/directives/persian.py
# class PersianNumberDirective(Directive):
#     def __init__(self, key, name, regex, zero_padding=False, zero_padding_length=2):
#     def format(self, i):
#     def post_parser(self, ctx, formatter):
# 
# Path: khayyam/timezones.py
# class Timezone(tzinfo):
# 
#     def __init__(self, offset, dst_offset=None, dst_checker=None, name=None):
#         assert (isinstance(offset, timedelta))
#         self._offset = offset
#         self._dst_offset = dst_offset
#         self._dst_checker = dst_checker
#         self._name = name
#         super(Timezone, self).__init__()
# 
#     def fromutc(self, dt):
#         if dt.tzinfo is None:
#             raise ValueError('The object: %s is naive.' % dt)
# 
#         if dt.tzinfo != self:
#             raise ValueError('Datetime timezone mismatch: %s != %s' % (dt.tzinfo, self))
# 
#         utc_offset = dt.utcoffset()
#         dst_offset = dt.dst()
#         delta = utc_offset - dst_offset  # this is self's standard offset
# 
#         if delta:
#             dt += delta  # convert to standard local time
#             dst_offset = dt.dst()
# 
#         if dst_offset:
#             return dt + dst_offset
#         else:
#             return dt
# 
#     def utcoffset(self, dt):
#         if self._is_dst(dt):
#             return self._offset + self._dst_offset
#         else:
#             return self._offset
# 
#     def dst(self, dt):
#         if self._dst_offset and self._is_dst(dt):
#             return self._dst_offset
#         else:
#             return ZERO_DELTA
# 
#     def __unicode__(self):
#         off = self._offset
#         return '%s%.2d:%.2d%s' % (
#             '+' if off.total_seconds() >= 0 else '-',
#             int(off.total_seconds() / 3600),
#             int((off.total_seconds() % 3600) / 60),
#             (' dst:%d' % (self._dst_offset.total_seconds() / 60)) if self._dst_offset else ''
#         )
# 
#     __repr__ = force_encoded_string_output(__unicode__)
# 
#     def tzname(self, dt):
#         if self._name:
#             return self._name
#         else:
#             return repr(self)
# 
#     def _is_dst(self, dt):
#         if self._dst_checker:
#             return self._dst_checker(dt)
#         return False
# 
#     def __hash__(self):
#         return hash(self._offset) ^ hash(self._dst_offset)


# Path: khayyam/formatting/directives/tz.py
import re
from .base import Directive
from .persian import PersianNumberDirective, persian_to_eng
from datetime import timedelta
from khayyam.timezones import Timezone

    """

    def format(self, d):
        if not d.tzinfo:
            return ''
        seconds = d.utcoffset().total_seconds()
        return '%s%.2d:%.2d' % (
            '+' if seconds >= 0 else '-',
            int(seconds / 3600),
            int((seconds % 3600) / 60),
        )

    def post_parser(self, ctx, formatter):
        exp = ctx[self.name]
        if exp.strip() == '':
            return
        regex = '(?P<posneg>[-+]?)(?P<hour>\d{2}):(?P<minute>\d{2})'
        match = re.match(regex, exp)
        d = match.groupdict()
        posneg = lambda i: 0 - i if d['posneg'] == '-' else i
        hours = int(d['hour'])
        minutes = int(d['minute'])
        if not hours and not minutes:
            return
        ctx.update(dict(tzinfo=Timezone(timedelta(
            hours = posneg(hours),
            minutes = posneg(minutes)
        ))))



class PersianUTCOffsetDirective(PersianNumberDirective):