def advance(self):
        """Get the next byte in the input stream.

        Will read as many input bytes as needed from Base64 or hex areas.
        """
        while True:
            self.last = self.char
            self.char = self.buf.read(1)
            if not self.char:
                self.bytesize = 8
                self.char = None
                return self.char

            if self.char is None:
                return self.char
            elif (self.bytesize == 6 and self.char in b"|}") \
                or (self.bytesize == 4 and self.char == b"#"):
                if self.nBits and (1 << self.nBits)-1 & self.bits:
                    raise IOError("%d-bit region ended with %d unused bits at %d" %
                        (self.bytesize, self.nBits, self.pos))
                self.bytesize = 8
                return self.char
            elif self.bytesize != 8 and self.char in WHITESPACE:
                # ignore whitespace in hex/base64 regions
                pass
            elif self.bytesize == 6 and self.char == b"=":
                # Base64 padding
                self.nBits -= 2
            elif self.bytesize == 8:
                return self.char
            elif self.bytesize < 8:
                self.bits <<= self.bytesize
                self.nBits += self.bytesize
                if self.bytesize == 6 and self.char in B64_DIGITS:
                    self.bits |= B64_DIGITS.index(self.char)
                elif self.bytesize == 4 and self.char in HEX_DIGITS:
                    self.bits |= int(self.char, 16)
                else:
                    raise IOError("char %r found in %d-bit region" %
                        (self.char, self.bytesize))

                if self.nBits >= 8:
                    self.nBits -= 8
                    byte = (self.bits >> self.nBits) & 0xFF
                    self.bits &= (1 << self.nBits)-1
                    self.char = bytes([byte])
                    return self.char
dataset/ETHPy150Open grawity/hacks/lib/python/nullroute/sexp.py/SexpParser.advance/original