Next / Previous / Contents / Shipman's homepage

6.13. UniData._readBlocks(): Extract code block data

unidata.py
# - - -   U n i D a t a . _ r e a d B l o c k s

    def _readBlocks(self, root):
        '''Set up ._blockMap.

          [ self._blockMap  :=  as invariant from root ]
        '''
        #-- 1
        self._blockMap = {}

Here are the relevant parts of charlist.rnc.

unicodeblocks = element unicodeblocks { block* }
block = element block
{ attribute start { text },  # E.g., "002200"
  attribute end { text },    # E.g., "022FF"
  attribute name { text }    # E.g., "Mathematical Operators"
}
unidata.py
        #-- 2
        # [ unicodeBlocks  :=  the UNICODEBLOCKS_N child of root
        #   blockNodeList  :=  the BLOCK_N children of those children ]
        unicodeBlocks = root.find(UNICODEBLOCKS_N)
        blockNodeList = unicodeBlocks.findall(BLOCK_N)

The processing of the block subtree is done by Section 6.17, “UniBlock.__init__().

unidata.py
        #-- 3
        # [ self._blockMap  +:=  entries whose keys are the block names
        #       in blockNodeList, and each related value is a UniBlock
        #       instance representing that block ]
        for blockNode in blockNodeList:
            block = UniBlock(blockNode)
            self._blockMap[block.name] = block