def test_acl_quoting(self): """Test the acl_quote and acl_unquote functions""" assert C.acl_quote(b'foo') == b'foo', C.acl_quote(b'foo') assert C.acl_quote(b'\n') == b'\\012', C.acl_quote(b'\n') assert C.acl_unquote(b'\\012') == b'\n' s = b'\\\n\t\145\n\01==' assert C.acl_unquote(C.acl_quote(s)) == s
def test_acl_quoting(self): """Test the acl_quote and acl_unquote functions""" assert C.acl_quote('foo') == 'foo', C.acl_quote('foo') assert C.acl_quote('\n') == '\\012', C.acl_quote('\n') assert C.acl_unquote('\\012') == '\n' s = '\\\n\t\145\n\01==' assert C.acl_unquote(C.acl_quote(s)) == s
def test_acl_quoting(self): """Test the acl_quote and acl_unquote functions""" self.assertEqual(C.acl_quote(b'foo'), b'foo') self.assertEqual(C.acl_quote(b'\n'), b'\\012') self.assertEqual(C.acl_unquote(b'\\012'), b'\n') s = b'\\\n\t\145\n\01==' self.assertEqual(C.acl_unquote(C.acl_quote(s)), s)
def _record_to_object(record): """Convert text record to ExtendedAttributes object""" lines = record.split(b'\n') first = lines.pop(0) if not first[:8] == b'# file: ': raise meta.ParsingError("Bad record beginning: %r" % first[:8]) filename = first[8:] if filename == b'.': index = () else: unquoted_filename = C.acl_unquote(filename) index = tuple(unquoted_filename.split(b'/')) ea = get_meta_object(index) for line in lines: line = line.strip() if not line: continue if line[0] == b'#': raise meta.ParsingError( "Only the first line of a record can start with a hash: {line}." .format(line=line)) eq_pos = line.find(b'=') if eq_pos == -1: ea.set(line) else: name = line[:eq_pos] if line[eq_pos + 1:eq_pos + 3] != b'0s': raise meta.ParsingError( "Currently only base64 encoding supported") encoded_val = line[eq_pos + 3:] ea.set(name, base64.b64decode(encoded_val)) return ea
def _record_to_object(record): """Convert text record to an AccessControlLists object""" newline_pos = record.find(b'\n') first_line = record[:newline_pos] if not first_line.startswith(b'# file: '): raise meta.ParsingError("Bad record beginning: %r" % first_line) filename = first_line[8:] if filename == b'.': index = () else: unquoted_filename = C.acl_unquote(filename) index = tuple(unquoted_filename.split(b'/')) return get_meta_object(index, os.fsdecode(record[newline_pos:]))
def from_string(self, acl_str): def _safe_str(cmd): """Transform bytes into string without risk of conversion error""" if isinstance(cmd, str): return cmd else: return str(cmd, errors='replace') lines = acl_str.splitlines() if len(lines) != 2 or not lines[0][:8] == b"# file: ": raise meta.ParsingError("Bad record beginning: %s" % _safe_str(lines[0][:8])) filename = lines[0][8:] if filename == b'.': self.index = () else: self.index = tuple(C.acl_unquote(filename).split(b'/')) self.__acl = lines[1]
def _filename_to_index(self, filename): """Convert possibly quoted filename to index tuple""" if filename == b'.': return () else: return tuple(C.acl_unquote(filename).split(b'/'))
def test_acl_quoting2(self): """This string used to segfault the quoting code, try now""" s = b'\xd8\xab\xb1Wb\xae\xc5]\x8a\xbb\x15v*\xf4\x0f!\xf9>\xe2Y\x86\xbb\xab\xdbp\xb0\x84\x13k\x1d\xc2\xf1\xf5e\xa5U\x82\x9aUV\xa0\xf4\xdf4\xba\xfdX\x03\x82\x07s\xce\x9e\x8b\xb34\x04\x9f\x17 \xf4\x8f\xa6\xfa\x97\xab\xd8\xac\xda\x85\xdcKvC\xfa#\x94\x92\x9e\xc9\xb7\xc3_\x0f\x84g\x9aB\x11<=^\xdbM\x13\x96c\x8b\xa7|*"\\\'^$@#!(){}?+ ~` ' quoted = C.acl_quote(s) assert C.acl_unquote(quoted) == s
def test_acl_quoting2(self): """This string used to segfault the quoting code, try now""" s = '\xd8\xab\xb1Wb\xae\xc5]\x8a\xbb\x15v*\xf4\x0f!\xf9>\xe2Y\x86\xbb\xab\xdbp\xb0\x84\x13k\x1d\xc2\xf1\xf5e\xa5U\x82\x9aUV\xa0\xf4\xdf4\xba\xfdX\x03\x82\x07s\xce\x9e\x8b\xb34\x04\x9f\x17 \xf4\x8f\xa6\xfa\x97\xab\xd8\xac\xda\x85\xdcKvC\xfa#\x94\x92\x9e\xc9\xb7\xc3_\x0f\x84g\x9aB\x11<=^\xdbM\x13\x96c\x8b\xa7|*"\\\'^$@#!(){}?+ ~` ' quoted = C.acl_quote(s) assert C.acl_unquote(quoted) == s