Line | |
---|
1 | """ |
---|
2 | Utilities used by allmydata.crypto modules |
---|
3 | |
---|
4 | Ported to Python 3. |
---|
5 | """ |
---|
6 | |
---|
7 | from allmydata.crypto.error import BadPrefixError |
---|
8 | |
---|
9 | |
---|
10 | def remove_prefix(s_bytes, prefix): |
---|
11 | """ |
---|
12 | :param bytes s_bytes: a string of bytes whose prefix is removed |
---|
13 | |
---|
14 | :param bytes prefix: the bytes to remove from the beginning of `s_bytes` |
---|
15 | |
---|
16 | Removes `prefix` from `s_bytes` and returns the new bytes or |
---|
17 | raises `BadPrefixError` if `s_bytes` did not start with the |
---|
18 | `prefix` specified. |
---|
19 | |
---|
20 | :returns: `s_bytes` with `prefix` removed from the front. |
---|
21 | """ |
---|
22 | if s_bytes.startswith(prefix): |
---|
23 | return s_bytes[len(prefix):] |
---|
24 | raise BadPrefixError( |
---|
25 | "did not see expected '{!r}' prefix".format(prefix) |
---|
26 | ) |
---|
Note: See
TracBrowser
for help on using the repository browser.