(string)
Make a 'C' string, checking for embedded NUL characters.
Make a 'C' string, checking for embedded NUL characters.
Make a C string checking for embedded NUL characters .
def _make_c_string_check(string):
    """Make a 'C' string, checking for embedded NUL characters."""
    if isinstance(string, bytes):
        if b"\x00" in string:
            raise InvalidDocument("BSON keys / regex patterns must not "
                                  "contain a NUL character")
        try:
            _utf_8_decode(string, None, True)
            return string + b"\x00"
        except UnicodeError:
            raise InvalidStringData("strings in documents must be valid "
                                    "UTF-8: %r" % string)
    else:
        if "\x00" in string:
            raise InvalidDocument("BSON keys / regex patterns must not "
                                  "contain a NUL character")
        return _utf_8_encode(string)[0] + b"\x00"
def _make_c_string_check ( string ) : if isinstance ( string , bytes ) : if b"\x00" in string : raise InvalidDocument ( "BSON keys / regex patterns must not " "contain a NUL character" ) try : _utf_8_decode ( string , None , True ) return string + b"\x00" except UnicodeError : raise InvalidStringData ( "strings in documents must be valid " "UTF-8: %r" % string ) else : if "\x00" in string : raise InvalidDocument ( "BSON keys / regex patterns must not " "contain a NUL character" ) return _utf_8_encode ( string ) [ 0 ] + b"\x00"