# 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/compat.py
# def get_unicode(s):
#     if _py3:  # pragma: no cover
#         return str(s)
#     else:  # pragma: no cover
#         # noinspection PyCompatibility
#         return unicode(s)
# 
# Path: khayyam/formatting/constants.py
# PERSIAN_DIGIT_MAPPING = [
#     (('\u06f0', '\u0660'), '0'),
#     (('\u06f1', '\u0661'), '1'),
#     (('\u06f2', '\u0662'), '2'),
#     (('\u06f3', '\u0663'), '3'),
#     (('\u06f4', '\u0664'), '4'),
#     (('\u06f5', '\u0665'), '5'),
#     (('\u06f6', '\u0666'), '6'),
#     (('\u06f7', '\u0667'), '7'),
#     (('\u06f8', '\u0668'), '8'),
#     (('\u06f9', '\u0669'), '9'),
# ]


from .base import Directive
from khayyam.compat import get_unicode
from khayyam.formatting.constants import PERSIAN_DIGIT_MAPPING
# -*- coding: utf-8 -*-

__author__ = 'vahid'


eng_to_persian_dict = {e: p[0] for p, e in PERSIAN_DIGIT_MAPPING}
persian_to_eng_dict = {p[0]: e for p, e in PERSIAN_DIGIT_MAPPING}

eng_to_persian = lambda s: ''.join([eng_to_persian_dict[c] if c in eng_to_persian_dict else c for c in s])
persian_to_eng = lambda s: ''.join([persian_to_eng_dict[c] if c in persian_to_eng_dict else c for c in s])



# 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/compat.py
# def get_unicode(s):
#     if _py3:  # pragma: no cover
#         return str(s)
#     else:  # pragma: no cover
#         # noinspection PyCompatibility
#         return unicode(s)
# 
# Path: khayyam/formatting/constants.py
# PERSIAN_DIGIT_MAPPING = [
#     (('\u06f0', '\u0660'), '0'),
#     (('\u06f1', '\u0661'), '1'),
#     (('\u06f2', '\u0662'), '2'),
#     (('\u06f3', '\u0663'), '3'),
#     (('\u06f4', '\u0664'), '4'),
#     (('\u06f5', '\u0665'), '5'),
#     (('\u06f6', '\u0666'), '6'),
#     (('\u06f7', '\u0667'), '7'),
#     (('\u06f8', '\u0668'), '8'),
#     (('\u06f9', '\u0669'), '9'),
# ]


# Path: khayyam/formatting/directives/persian.py
from .base import Directive
from khayyam.compat import get_unicode
from khayyam.formatting.constants import PERSIAN_DIGIT_MAPPING

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

__author__ = 'vahid'


eng_to_persian_dict = {e: p[0] for p, e in PERSIAN_DIGIT_MAPPING}
persian_to_eng_dict = {p[0]: e for p, e in PERSIAN_DIGIT_MAPPING}

eng_to_persian = lambda s: ''.join([eng_to_persian_dict[c] if c in eng_to_persian_dict else c for c in s])
persian_to_eng = lambda s: ''.join([persian_to_eng_dict[c] if c in persian_to_eng_dict else c for c in s])



class PersianNumberDirective(Directive):