コード例 #1
0
 def _entry_check(self, word):
     ok = True
     if set(word["entry"]) != {"id", "form"}:
         raise NotOTMJson("Entry is broken: {}.".format(word))
     if not isinstance(word["entry"]["id"], int):
         ok = False
     if not isinstance(word["entry"]["form"], str):
         ok = False
     if not ok:
         raise NotOTMJson("Entry is broken: {}.".format(word))
コード例 #2
0
 def _tags_check(self, word):
     name = "tags"
     err_message = "{} is broken: {}.".format(name, word)
     if not isinstance(word[name], list):
         raise NotOTMJson(err_message)
     for component in word[name]:
         ok = True
         err_message_2 = ("name is broken: {} in {}.".format(
             component, word))
         if not isinstance(component, str):
             ok = False
         if not ok:
             raise NotOTMJson(err_message_2)
コード例 #3
0
 def __word_components_check(self, word, name, component_attrs, attr_type):
     err_message = "{} is broken: {}.".format(name, word)
     if not isinstance(word[name], list):
         raise NotOTMJson(err_message)
     for component in word[name]:
         err_message_2 = ("{} is broken: {} in {}.".format(
             name[:-1], component, word))
         ok = True
         if set(component) != set(component_attrs):
             raise NotOTMJson(err_message)
         if not isinstance(component["title"], str):
             ok = False
         attr = [x for x in component_attrs if x != "title"][0]
         if not isinstance(component[attr], attr_type):
             ok = False
         if not ok:
             raise NotOTMJson(err_message_2)
コード例 #4
0
 def _translations_check(self, word):
     self.__word_components_check(word, "translations", {"title", "forms"},
                                  list)
     for component in word["translations"]:
         ok = True
         for form in component["forms"]:
             if not isinstance(form, str):
                 ok = False
         if not ok:
             raise NotOTMJson("form is broken: {} in {}.".format(
                 form, word))
コード例 #5
0
 def _relations_check(self, word):
     self.__word_components_check(word, "relations", {"title", "entry"},
                                  dict)
     for component in word["relations"]:
         ok = True
         try:
             self._entry_check(component)
         except NotOTMJson:
             ok = False
         if not ok:
             raise NotOTMJson(
                 "entry in relation is broken: {} in {}".format(
                     component, word))
コード例 #6
0
    def _word_check(self, word):
        component_types = {
            "entry", "translations", "tags", "contents", "variations",
            "relations"
        }
        if set(word) != component_types:
            lacks = [
                comp_type for comp_type in component_types
                if comp_type not in list(word)
            ]
            raise NotOTMJson("Attributes lack: {}.".format(word))

        self._entry_check(word)
        self._translations_check(word)
        self._tags_check(word)
        self._contents_check(word)
        self._variations_check(word)
        self._relations_check(word)
コード例 #7
0
 def _words_check(self):
     if 'words' not in self.json.keys():
         raise NotOTMJson("Not have words attribute.")
     if not isinstance(self.json["words"], list):
         raise NotOTMJson("words must be list")