Belle II Software development
MmapByteArray Class Reference
Inheritance diagram for MmapByteArray:

Public Member Functions

def __init__ (self, source, bytelength=None, byteoffset=None)
 
def __getitem__ (self, key)
 
def __len__ (self)
 

Public Attributes

 source
 
 filelength
 
 byteoffset
 
 bytelength
 
 filemap
 

Static Private Attributes

tuple __slots__ = ('filemap', 'filelength', 'source', 'byteoffset', 'bytelength')
 

Detailed Description

Looks like a bytearray, but from an mmap.

Not part of public interface.

Definition at line 396 of file bitstring.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  source,
  bytelength = None,
  byteoffset = None 
)

Definition at line 404 of file bitstring.py.

404 def __init__(self, source, bytelength=None, byteoffset=None):
405 self.source = source
406 source.seek(0, os.SEEK_END)
407 self.filelength = source.tell()
408 if byteoffset is None:
409 byteoffset = 0
410 if bytelength is None:
411 bytelength = self.filelength - byteoffset
412 self.byteoffset = byteoffset
413 self.bytelength = bytelength
414 self.filemap = mmap.mmap(source.fileno(), 0, access=mmap.ACCESS_READ)
415

Member Function Documentation

◆ __getitem__()

def __getitem__ (   self,
  key 
)

Definition at line 416 of file bitstring.py.

416 def __getitem__(self, key):
417 try:
418 start = key.start
419 stop = key.stop
420 except AttributeError:
421 try:
422 assert 0 <= key < self.bytelength
423 return ord(self.filemap[key + self.byteoffset])
424 except TypeError:
425 # for Python 3
426 return self.filemap[key + self.byteoffset]
427 else:
428 if start is None:
429 start = 0
430 if stop is None:
431 stop = self.bytelength
432 assert key.step is None
433 assert 0 <= start < self.bytelength
434 assert 0 <= stop <= self.bytelength
435 s = slice(start + self.byteoffset, stop + self.byteoffset)
436 return bytearray(self.filemap.__getitem__(s))
437

◆ __len__()

def __len__ (   self)

Definition at line 438 of file bitstring.py.

438 def __len__(self):
439 return self.bytelength
440
441
442# This creates a dictionary for every possible byte with the value being
443# the key with its bits reversed.

Member Data Documentation

◆ __slots__

tuple __slots__ = ('filemap', 'filelength', 'source', 'byteoffset', 'bytelength')
staticprivate

Definition at line 402 of file bitstring.py.

◆ bytelength

bytelength

Definition at line 413 of file bitstring.py.

◆ byteoffset

byteoffset

Definition at line 412 of file bitstring.py.

◆ filelength

filelength

Definition at line 407 of file bitstring.py.

◆ filemap

filemap

Definition at line 414 of file bitstring.py.

◆ source

source

Definition at line 405 of file bitstring.py.


The documentation for this class was generated from the following file: