Files
third_party_rust_rust-url/make_encode_sets.py
T
2014-07-14 00:04:48 +01:00

41 lines
1.4 KiB
Python

# Copyright 2013-2014 Simon Sapin.
#
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
# option. This file may not be copied, modified, or distributed
# except according to those terms.
# Run as: python make_encode_sets.py > src/encode_sets.rs
print('''\
// Copyright 2013-2014 Simon Sapin.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Generated by make_encode_sets.py
''')
for name, encoded in [
('SIMPLE_ENCODE_SET', ''),
('QUERY_ENCODE_SET', ' "#<>`'),
('DEFAULT_ENCODE_SET', ' "#<>`?'),
('USERINFO_ENCODE_SET', ' "#<>`?@'),
('PASSWORD_ENCODE_SET', ' "#<>`?@/\\'),
('USERNAME_ENCODE_SET', ' "#<>`?@/\\:'),
]:
print(
"pub static %s: [&'static str, ..256] = [\n%s\n];\n\n"
% (name, '\n'.join(
' ' + ' '.join(
'"%s%s",' % ("\\" if chr(b) in '\\"' else "", chr(b))
if 0x20 <= b <= 0x7E and chr(b) not in encoded
else '"%%%02X",' % b
for b in range(s, s + 8)
) for s in range(0, 256, 8))))