skia2/experimental/tools/gerrit_percent_encode
Hal Canary 71c34240f4 experimental/tools/gerrit_percent_encode
NoTry: true
Change-Id: I448b4791911dd1b87104ca809b2b41c62ce0ee3d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/231480
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
2019-08-05 16:11:45 +00:00

18 lines
758 B
Python
Executable File

#! /usr/bin/env python
# Copyright 2019 Google LLC.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import re
import sys
def gerrit_percent_encode(value):
'''
https://gerrit-review.googlesource.com/Documentation/user-upload.html
"To avoid confusion in parsing the git ref, at least the following characters
must be percent-encoded: " %^@.~-+_:/!". Note that some of the reserved
characters (like tilde) are not escaped in the standard URL encoding rules..."
'''
good = re.compile('^[A-Za-z0-9]$')
return ''.join(c if good.match(c) else '%%%02X' % ord(c) for c in value)
if __name__ == '__main__':
sys.stdout.write(gerrit_percent_encode(' '.join(sys.argv[1:])) + '\n')