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