# Path: KPC/classes.py
# class Error:
#     '''An individual error from a check against an entry. One check
#     usually returns list of errors or empty list if there's no error.
#     '''
#     SUCCESS = 0
#     DEPRECATED = 1
#     WARNING = 2
#     ERROR = 3
# 
#     def __init__(self, message):
#         self.pos = 0
#         self.level = Error.ERROR
#         self.message = message
# 
# class BaseCheck:
#     '''Base class to check an entry from PO files. Subclasses should
#     implement check() function. check() returns list of errors if any.
#     '''
#     def _get_context(self, entry):
#         if not hasattr(self, 'get_context'):
#             return {}
#         fields = {}
#         # parse msgstr
#         for line in entry.msgstr.split('\n'):
#             try:
#                 k, v = line.split(': ', 1)
#                 fields[k] = v
#             except ValueError:
#                 pass
#         return self.get_context(entry, fields)
# 
#     def _check(self, entry, context):
#         return self.check(entry, context)


import re
from KPC.classes import Error, BaseCheck
              'States License',
     'msgstr': '크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0 미합중국 라이선스'},
    {'msgid': 'Creative ?Commons Attribution-Share ?Alike 3\.0 Unported ' +
              'License',
     'msgstr': '크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0 Unported 라이선스'},
    {'msgid': '<em>To share</em>',
     'msgstr': '<em>공유</em>'},
    {'msgid': '<em>To remix</em>',
     'msgstr': '<em>변경</em>'},
    {'msgid': '<em>Attribution</em>',
     'msgstr': '<em>저작자 표시</em>'},
    {'msgid': '<em>Share Alike</em>',
     'msgstr': '<em>동일 조건</em>'},
]


class HelpLicenseCheck(BaseCheck):
    errstr = '일관성을 위해 다음과 같이 번역합니다: %s'

    def check(self, entry, context):
        for p in entry.references:
            if '.page' in p or '.xml' in p:
                break
        else:
             return []
        for d in data:
            if not re.match(d['msgid'], entry.msgid, re.IGNORECASE):
                continue
            if entry.msgstr != d['msgstr']:
                return [Error(self.errstr % d['msgstr'])]

# Path: KPC/classes.py
# class Error:
#     '''An individual error from a check against an entry. One check
#     usually returns list of errors or empty list if there's no error.
#     '''
#     SUCCESS = 0
#     DEPRECATED = 1
#     WARNING = 2
#     ERROR = 3
# 
#     def __init__(self, message):
#         self.pos = 0
#         self.level = Error.ERROR
#         self.message = message
# 
# class BaseCheck:
#     '''Base class to check an entry from PO files. Subclasses should
#     implement check() function. check() returns list of errors if any.
#     '''
#     def _get_context(self, entry):
#         if not hasattr(self, 'get_context'):
#             return {}
#         fields = {}
#         # parse msgstr
#         for line in entry.msgstr.split('\n'):
#             try:
#                 k, v = line.split(': ', 1)
#                 fields[k] = v
#             except ValueError:
#                 pass
#         return self.get_context(entry, fields)
# 
#     def _check(self, entry, context):
#         return self.check(entry, context)


# Path: KPC/checks/terminology/help-license.py
import re
from KPC.classes import Error, BaseCheck

              'States License',
     'msgstr': '크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0 미합중국 라이선스'},
    {'msgid': 'Creative ?Commons Attribution-Share ?Alike 3\.0 Unported ' +
              'License',
     'msgstr': '크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0 Unported 라이선스'},
    {'msgid': '<em>To share</em>',
     'msgstr': '<em>공유</em>'},
    {'msgid': '<em>To remix</em>',
     'msgstr': '<em>변경</em>'},
    {'msgid': '<em>Attribution</em>',
     'msgstr': '<em>저작자 표시</em>'},
    {'msgid': '<em>Share Alike</em>',
     'msgstr': '<em>동일 조건</em>'},
]


class HelpLicenseCheck(BaseCheck):
    errstr = '일관성을 위해 다음과 같이 번역합니다: %s'

    def check(self, entry, context):
        for p in entry.references:
            if '.page' in p or '.xml' in p:
                break
        else:
             return []
        for d in data:
            if not re.match(d['msgid'], entry.msgid, re.IGNORECASE):
                continue
            if entry.msgstr != d['msgstr']:
                return [Error(self.errstr % d['msgstr'])]

        return []