示例#1
0
    def _parseMeta(self, metaLine):
        """Parse a line from the document starting with the characters
        %%~ that may contain meta data.
        """
        if metaLine.startswith("%%~name:"):
            self._docMeta["name"] = metaLine[8:].strip()

        elif metaLine.startswith("%%~path:"):
            metaVal = metaLine[8:].strip()
            metaBits = metaVal.split("/")
            if len(metaBits) == 2:
                if isHandle(metaBits[0]):
                    self._docMeta["parent"] = metaBits[0]
                if isHandle(metaBits[1]):
                    self._docMeta["handle"] = metaBits[1]

        elif metaLine.startswith("%%~kind:"):
            metaVal = metaLine[8:].strip()
            metaBits = metaVal.split("/")
            if len(metaBits) == 2:
                if metaBits[0] in nwItemClass.__members__:
                    self._docMeta["class"] = nwItemClass[metaBits[0]]
                if metaBits[1] in nwItemLayout.__members__:
                    self._docMeta["layout"] = nwItemLayout[metaBits[1]]

        else:
            logger.debug("Ignoring meta data: '%s'", metaLine.strip())

        return
示例#2
0
    def _checkRefIndex(self):
        """Scan the reference index for errors.
        Warning: This function raises exceptions.
        """
        for tHandle in self._refIndex:
            if not isHandle(tHandle):
                raise KeyError("refIndex key is not a handle")

            hEntry = self._refIndex[tHandle]
            for sTitle in hEntry:
                if not isTitleTag(sTitle):
                    raise KeyError("refIndex[a] key is not a title tag")

                sEntry = hEntry[sTitle]
                for tEntry in sEntry:
                    if len(tEntry) != 3:
                        raise IndexError("refIndex[a][b][i] expected 3 values")
                    if not isinstance(tEntry[0], int):
                        raise ValueError("refIndex[a][b][i][0] is not an integer")
                    if not tEntry[1] in nwKeyWords.VALID_KEYS:
                        raise ValueError("refIndex[a][b][i][1] is not a keyword")
                    if not isinstance(tEntry[2], str):
                        raise ValueError("refIndex[a][b][i][2] is not a string")

        return
示例#3
0
    def unpackData(self, data):
        """Iterate through the tagsIndex loaded from cache and check
        that it's valid.
        """
        self._tags = {}
        if not isinstance(data, dict):
            raise ValueError("tagsIndex is not a dict")

        for tagKey, tagData in data.items():
            if not isinstance(tagKey, str):
                raise ValueError("tagsIndex keys must be a strings")
            if "handle" not in tagData:
                raise KeyError("A tagIndex item is missing a handle entry")
            if "heading" not in tagData:
                raise KeyError("A tagIndex item is missing a heading entry")
            if "class" not in tagData:
                raise KeyError("A tagIndex item is missing a class entry")
            if not isHandle(tagData["handle"]):
                raise ValueError("tagsIndex handle must be a handle")
            if not isTitleTag(tagData["heading"]):
                raise ValueError("tagsIndex heading must be a title tag")
            if not isItemClass(tagData["class"]):
                raise ValueError("tagsIndex handle must be an nwItemClass")

        self._tags = data

        return
示例#4
0
 def setHandle(self, handle):
     """Set the item handle, and ensure it is valid.
     """
     if isHandle(handle):
         self._handle = handle
     else:
         self._handle = None
     return
示例#5
0
 def setRoot(self, handle):
     """Set the root handle, and ensure it is valid.
     """
     if handle is None:
         self._root = None
     elif isHandle(handle):
         self._root = handle
     else:
         self._root = None
     return
示例#6
0
 def setParent(self, handle):
     """Set the parent handle, and ensure it is valid.
     """
     if handle is None:
         self._parent = None
     elif isHandle(handle):
         self._parent = handle
     else:
         self._parent = None
     return
示例#7
0
 def setParent(self, theParent):
     """Set the parent handle, and ensure it is valid.
     """
     if theParent is None:
         self._parent = None
     elif isHandle(theParent):
         self._parent = theParent
     else:
         self._parent = None
     return
示例#8
0
def testBaseCommon_IsHandle():
    """Test the isHandle function.
    """
    assert isHandle("47666c91c7ccf") is True
    assert isHandle("47666C91C7CCF") is False
    assert isHandle("h7666c91c7ccf") is False
    assert isHandle("None") is False
    assert isHandle(None) is False
    assert isHandle("STUFF") is False
示例#9
0
    def _checkFileIndex(self):
        """Scan the file index for errors.
        Warning: This function raises exceptions.
        """
        for tHandle in self._fileIndex:
            if not isHandle(tHandle):
                raise KeyError("fileIndex key is not a handle")

            hEntry = self._fileIndex[tHandle]
            for sTitle in self._fileIndex[tHandle]:
                if not isTitleTag(sTitle):
                    raise KeyError("fileIndex[a] key is not a title tag")

                sEntry = hEntry[sTitle]
                if len(sEntry) != 7:
                    raise IndexError("fileIndex[a][b] expected 7 values")

                if "level" not in sEntry:
                    raise KeyError("fileIndex[a][b] has no 'level' key")
                if "title" not in sEntry:
                    raise KeyError("fileIndex[a][b] has no 'title' key")
                if "layout" not in sEntry:
                    raise KeyError("fileIndex[a][b] has no 'layout' key")
                if "cCount" not in sEntry:
                    raise KeyError("fileIndex[a][b] has no 'cCount' key")
                if "wCount" not in sEntry:
                    raise KeyError("fileIndex[a][b] has no 'wCount' key")
                if "pCount" not in sEntry:
                    raise KeyError("fileIndex[a][b] has no 'pCount' key")
                if "synopsis" not in sEntry:
                    raise KeyError("fileIndex[a][b] has no 'synopsis' key")

                if not sEntry["level"] in H_VALID:
                    raise ValueError("fileIndex[a][b][level] is not a header level")
                if not isinstance(sEntry["title"], str):
                    raise ValueError("fileIndex[a][b][title] is not a string")
                if not isItemLayout(sEntry["layout"]):
                    raise ValueError("fileIndex[a][b][layout] is not an nwItemLayout")
                if not isinstance(sEntry["cCount"], int):
                    raise ValueError("fileIndex[a][b][cCount] is not an integer")
                if not isinstance(sEntry["wCount"], int):
                    raise ValueError("fileIndex[a][b][wCount] is not an integer")
                if not isinstance(sEntry["pCount"], int):
                    raise ValueError("fileIndex[a][b][pCount] is not an integer")
                if not isinstance(sEntry["synopsis"], str):
                    raise ValueError("fileIndex[a][b][synopsis] is not a string")

        return
示例#10
0
    def unpackData(self, data):
        """Iterate through the itemIndex loaded from cache and check
        that it's valid. This will raise errors if there is a problem.
        """
        self._items = {}
        if not isinstance(data, dict):
            raise ValueError("itemIndex is not a dict")

        for tHandle, tData in data.items():
            if not isHandle(tHandle):
                raise ValueError("itemIndex keys must be handles")

            nwItem = self.theProject.tree[tHandle]
            if nwItem is not None:
                tItem = IndexItem(tHandle, nwItem)
                tItem.unpackData(tData)
                self._items[tHandle] = tItem

        return
示例#11
0
    def __init__(self, theProject, theHandle):

        self.theProject = theProject

        # Internal Variables
        self._theItem   = None  # The currently open item
        self._docHandle = None  # The handle of the currently open item
        self._fileLoc   = None  # The file location of the currently open item
        self._docMeta   = {}    # The meta data of the currently open item
        self._docError  = ""    # The latest encountered IO error
        self._prevHash  = None  # Previous sha256sum of the document file
        self._currHash  = None  # Latest sha256sum of the document file

        if isHandle(theHandle):
            self._docHandle = theHandle

        if self._docHandle is not None:
            self._theItem = self.theProject.tree[theHandle]

        return
示例#12
0
    def _checkFileMeta(self):
        """Scan the text counts index for errors.
        Warning: This function raises exceptions.
        """
        for tHandle in self._fileMeta:
            if not isHandle(tHandle):
                raise KeyError("fileMeta key is not a handle")

            tEntry = self._fileMeta[tHandle]
            if len(tEntry) != 4:
                raise IndexError("fileMeta[a] expected 4 values")
            if not tEntry[0] in H_VALID:
                raise ValueError("fileMeta[a][0] is not a header level")
            if not isinstance(tEntry[1], int):
                raise ValueError("fileMeta[a][1] is not an integer")
            if not isinstance(tEntry[2], int):
                raise ValueError("fileMeta[a][2] is not an integer")
            if not isinstance(tEntry[3], int):
                raise ValueError("fileMeta[a][3] is not an integer")

        return
示例#13
0
    def _checkTagIndex(self):
        """Scan the tag index for errors.
        Warning: This function raises exceptions.
        """
        for tTag in self._tagIndex:
            if not isinstance(tTag, str):
                raise KeyError("tagIndex key is not a string")

            tEntry = self._tagIndex[tTag]
            if len(tEntry) != 4:
                raise IndexError("tagIndex[a] expected 4 values")
            if not isinstance(tEntry[0], int):
                raise ValueError("tagIndex[a][0] is not an integer")
            if not isHandle(tEntry[1]):
                raise ValueError("tagIndex[a][1] is not a handle")
            if not isItemClass(tEntry[2]):
                raise ValueError("tagIndex[a][2] is not an nwItemClass")
            if not isTitleTag(tEntry[3]):
                raise ValueError("tagIndex[a][3] is not a title tag")

        return