# 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
# -*- coding: utf-8 -*-


err_fmt = '검색어 번역은 \';\'으로 끝나야 합니다'
err_org = '%s: 검색어 번역에는 원문 키워드를 포함해야 합니다'
err_dup = '%s: 검색어가 중복되어 있습니다'

re_keyword = re.compile(r'^(?:[\w ]+;)+$')


class DesktopKeywordCheck(BaseCheck):
    def is_keyword(self, entry):
        if True not in [('.desktop' in p) for p in entry.references]:
            return False
        return re_keyword.match(entry.msgid)

    def check(self, entry, context):
        if not self.is_keyword(entry):
            return []
        msgid_keywords = entry.msgid[:-1].split(';')
        if entry.msgstr[-1] != ';':
            return [Error(err_fmt)]
        msgstr_keywords = entry.msgstr[:-1].split(';')
        for k in msgid_keywords:
            if k not in msgstr_keywords:
                return [Error(err_org % k)]
        s = set()
        for k in msgstr_keywords:
            if k in s:

# 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/convention/desktop-keyword.py
import re
from KPC.classes import Error, BaseCheck

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


err_fmt = '검색어 번역은 \';\'으로 끝나야 합니다'
err_org = '%s: 검색어 번역에는 원문 키워드를 포함해야 합니다'
err_dup = '%s: 검색어가 중복되어 있습니다'

re_keyword = re.compile(r'^(?:[\w ]+;)+$')


class DesktopKeywordCheck(BaseCheck):
    def is_keyword(self, entry):
        if True not in [('.desktop' in p) for p in entry.references]:
            return False
        return re_keyword.match(entry.msgid)

    def check(self, entry, context):
        if not self.is_keyword(entry):
            return []
        msgid_keywords = entry.msgid[:-1].split(';')
        if entry.msgstr[-1] != ';':
            return [Error(err_fmt)]
        msgstr_keywords = entry.msgstr[:-1].split(';')
        for k in msgid_keywords:
            if k not in msgstr_keywords:
                return [Error(err_org % k)]
        s = set()
        for k in msgstr_keywords:
            if k in s:

                return [Error(err_dup % k)]