original_docstring: Reads a dbf header. Xbase-related code borrows heavily from ActiveState Python Cookbook Recipe 362715 by Raymond Hettinger
docstring: Reads a dbf header. Xbase-related code borrows heavily from ActiveState Python Cookbook Recipe 362715 by Raymond Hettinger
docstring_tokens: Reads a dbf header . Xbase - related code borrows heavily from ActiveState Python Cookbook Recipe 362715 by Raymond Hettinger
code: def __dbfHeader(self):
          """Reads a dbf header. Xbase-related code borrows heavily from ActiveState Python Cookbook Recipe 362715 by Raymond Hettinger"""
          if not self.dbf:
              raise ShapefileException("Shapefile Reader requires a shapefile or file-like object. (no dbf file found)")
          dbf = self.dbf
          # read relevant header parts
          self.numRecords, self.__dbfHdrLength, self.__recordLength = \
                  unpack("<xxxxLHH20x", dbf.read(32))
          # read fields
          numFields = (self.__dbfHdrLength - 33) // 32
          for field in range(numFields):
              fieldDesc = list(unpack("<11sc4xBB14x", dbf.read(32)))
              name = 0
              idx = 0
              if b"\x00" in fieldDesc[name]:
                  idx = fieldDesc[name].index(b"\x00")
              else:
                  idx = len(fieldDesc[name]) - 1
              fieldDesc[name] = fieldDesc[name][:idx]
              fieldDesc[name] = u(fieldDesc[name], self.encoding, self.encodingErrors)
              fieldDesc[name] = fieldDesc[name].lstrip()
              fieldDesc[1] = u(fieldDesc[1], 'ascii')
              self.fields.append(fieldDesc)
          terminator = dbf.read(1)
          if terminator != b"\r":
              raise ShapefileException("Shapefile dbf header lacks expected terminator. (likely corrupt?)")
          self.fields.insert(0, ('DeletionFlag', 'C', 1, 0))
          fmt,fmtSize = self.__recordFmt()
          self.__recStruct = Struct(fmt)
  
          # Store the field positions
          self.__fieldposition_lookup = dict((f[0], i) for i, f in enumerate(self.fields[1:]))
code_tokens: def __dbfHeader ( self ) : if not self . dbf : raise ShapefileException ( "Shapefile Reader requires a shapefile or file-like object. (no dbf file found)" ) dbf = self . dbf self . numRecords , self . __dbfHdrLength , self . __recordLength = unpack ( "<xxxxLHH20x" , dbf . read ( 32 ) ) numFields = ( self . __dbfHdrLength - 33 ) // 32 for field in range ( numFields ) : fieldDesc = list ( unpack ( "<11sc4xBB14x" , dbf . read ( 32 ) ) ) name = 0 idx = 0 if b"\x00" in fieldDesc [ name ] : idx = fieldDesc [ name ] . index ( b"\x00" ) else : idx = len ( fieldDesc [ name ] ) - 1 fieldDesc [ name ] = fieldDesc [ name ] [ : idx ] fieldDesc [ name ] = u ( fieldDesc [ name ] , self . encoding , self . encodingErrors ) fieldDesc [ name ] = fieldDesc [ name ] . lstrip ( ) fieldDesc [ 1 ] = u ( fieldDesc [ 1 ] , 'ascii' ) self . fields . append ( fieldDesc ) terminator = dbf . read ( 1 ) if terminator != b"\r" : raise ShapefileException ( "Shapefile dbf header lacks expected terminator. (likely corrupt?)" ) self . fields . insert ( 0 , ( 'DeletionFlag' , 'C' , 1 , 0 ) ) fmt , fmtSize = self . __recordFmt ( ) self . __recStruct = Struct ( fmt ) self . __fieldposition_lookup = dict ( ( f [ 0 ] , i ) for i , f in enumerate ( self . fields [ 1 : ] ) )
short_docstring: Reads a dbf header.
short_docstring_tokens: Reads a dbf header .
comment: """Reads a dbf header. Xbase-related code borrows heavily from ActiveState Python Cookbook Recipe 362715 by Raymond Hettinger"""$SEP$# read relevant header parts
  $SEP$# read fields
  $SEP$# Store the field positions
  