def read(port): # This method should either return a valid Metadata object, # return None if there was no information at all (just a # _rec_tag_end), throw EOFError if there was nothing at all to # read, or throw an Exception if a valid object could not be # read completely. tag = vint.read_vuint(port) if tag == _rec_tag_end: return None try: # From here on, EOF is an error. result = Metadata() while True: # only exit is error (exception) or _rec_tag_end if tag == _rec_tag_path: result._load_path_rec(port) elif tag == _rec_tag_common_v2: result._load_common_rec(port) elif tag == _rec_tag_symlink_target: result._load_symlink_target_rec(port) elif tag == _rec_tag_hardlink_target: result._load_hardlink_target_rec(port) elif tag == _rec_tag_posix1e_acl: result._load_posix1e_acl_rec(port) elif tag == _rec_tag_linux_attr: result._load_linux_attr_rec(port) elif tag == _rec_tag_linux_xattr: result._load_linux_xattr_rec(port) elif tag == _rec_tag_end: return result elif tag == _rec_tag_common: # Should be very rare. result._load_common_rec(port, legacy_format=True) else: # unknown record vint.skip_bvec(port) tag = vint.read_vuint(port) except EOFError: raise Exception("EOF while reading Metadata")
def read(port): # This method should either return a valid Metadata object, # return None if there was no information at all (just a # _rec_tag_end), throw EOFError if there was nothing at all to # read, or throw an Exception if a valid object could not be # read completely. tag = vint.read_vuint(port) if tag == _rec_tag_end: return None try: # From here on, EOF is an error. result = Metadata() while True: # only exit is error (exception) or _rec_tag_end if tag == _rec_tag_path: result._load_path_rec(port) elif tag == _rec_tag_common: result._load_common_rec(port) elif tag == _rec_tag_symlink_target: result._load_symlink_target_rec(port) elif tag == _rec_tag_hardlink_target: result._load_hardlink_target_rec(port) elif tag == _rec_tag_posix1e_acl: result._load_posix1e_acl_rec(port) elif tag ==_rec_tag_nfsv4_acl: result._load_nfsv4_acl_rec(port) elif tag == _rec_tag_linux_attr: result._load_linux_attr_rec(port) elif tag == _rec_tag_linux_xattr: result._load_linux_xattr_rec(port) elif tag == _rec_tag_end: return result else: # unknown record vint.skip_bvec(port) tag = vint.read_vuint(port) except EOFError: raise Exception("EOF while reading Metadata")
def read(port): # This method should either: return a valid Metadata object; # throw EOFError if there was nothing at all to read; throw an # Exception if a valid object could not be read completely. tag = vint.read_vuint(port) try: # From here on, EOF is an error. result = Metadata() while True: # only exit is error (exception) or _rec_tag_end if tag == _rec_tag_path: result._load_path_rec(port) elif tag == _rec_tag_common: result._load_common_rec(port) elif tag == _rec_tag_symlink_target: result._load_symlink_target_rec(port) elif tag == _rec_tag_posix1e_acl: result._load_posix1e_acl_rec(port) elif tag ==_rec_tag_nfsv4_acl: result._load_nfsv4_acl_rec(port) elif tag == _rec_tag_linux_attr: result._load_linux_attr_rec(port) elif tag == _rec_tag_linux_xattr: result._load_linux_xattr_rec(port) elif tag == _rec_tag_end: return result else: # unknown record vint.skip_bvec(port) tag = vint.read_vuint(port) except EOFError: raise Exception("EOF while reading Metadata")
def test_bvec(): values = ('', 'x', 'foo', '\0', '\0foo', 'foo\0bar\0') for x in values: WVPASSEQ(encode_and_decode_bvec(x), x) WVEXCEPT(EOFError, vint.read_bvec, BytesIO()) outf = BytesIO() for x in ('foo', 'bar', 'baz', 'bax'): vint.write_bvec(outf, x) inf = BytesIO(outf.getvalue()) WVPASSEQ(vint.read_bvec(inf), 'foo') WVPASSEQ(vint.read_bvec(inf), 'bar') vint.skip_bvec(inf) WVPASSEQ(vint.read_bvec(inf), 'bax')
def test_bvec(): values = ('', 'x', 'foo', '\0', '\0foo', 'foo\0bar\0') for x in values: WVPASSEQ(encode_and_decode_bvec(x), x) WVEXCEPT(EOFError, vint.read_bvec, StringIO()) outf = StringIO() for x in ('foo', 'bar', 'baz', 'bax'): vint.write_bvec(outf, x) inf = StringIO(outf.getvalue()) WVPASSEQ(vint.read_bvec(inf), 'foo') WVPASSEQ(vint.read_bvec(inf), 'bar') vint.skip_bvec(inf) WVPASSEQ(vint.read_bvec(inf), 'bax')
def test_bvec(): with no_lingering_errors(): values = (b'', b'x', b'foo', b'\0', b'\0foo', b'foo\0bar\0') for x in values: WVPASSEQ(encode_and_decode_bvec(x), x) WVEXCEPT(EOFError, vint.read_bvec, BytesIO()) outf = BytesIO() for x in (b'foo', b'bar', b'baz', b'bax'): vint.write_bvec(outf, x) inf = BytesIO(outf.getvalue()) WVPASSEQ(vint.read_bvec(inf), b'foo') WVPASSEQ(vint.read_bvec(inf), b'bar') vint.skip_bvec(inf) WVPASSEQ(vint.read_bvec(inf), b'bax')