|
30 | 30 | import sys
|
31 | 31 | from xml.etree import ElementTree
|
32 | 32 |
|
| 33 | +if platform.system().lower() == 'windows': |
| 34 | + import ctypes.wintypes # pylint: disable=g-import-not-at-top |
| 35 | + |
| 36 | +# Map Python 2's unicode method to encode a string as bytes in python 3. |
| 37 | +try: |
| 38 | + unicode('') # See whether unicode class is available (Python < 3) |
| 39 | +except NameError: |
| 40 | + unicode = str # pylint: disable=redefined-builtin,invalid-name |
| 41 | + |
33 | 42 | # Input filename if it isn't set.
|
34 | 43 | DEFAULT_INPUT_FILENAME = 'app/google-services.json'
|
35 | 44 | # Output filename if it isn't set.
|
@@ -231,12 +240,12 @@ def argv_as_unicode_win32():
|
231 | 240 | command_line_to_argv_w = ctypes.windll.shell32.CommandLineToArgvW
|
232 | 241 | command_line_to_argv_w.argtypes = [
|
233 | 242 | ctypes.wintypes.LPCWSTR,
|
234 |
| - ctypes.wintypes.POINTER(ctypes.wintypes.c_int) |
| 243 | + ctypes.POINTER(ctypes.c_int) |
235 | 244 | ]
|
236 |
| - command_line_to_argv_w.restype = ctypes.wintypes.POINTER( |
| 245 | + command_line_to_argv_w.restype = ctypes.POINTER( |
237 | 246 | ctypes.wintypes.LPWSTR)
|
238 | 247 |
|
239 |
| - argc = ctypes.wintypes.c_int(0) |
| 248 | + argc = ctypes.c_int(0) |
240 | 249 | argv = command_line_to_argv_w(get_command_line_w(), argc)
|
241 | 250 |
|
242 | 251 | # Strip the python executable from the arguments if it exists
|
@@ -298,18 +307,18 @@ def main():
|
298 | 307 | output_filename = DEFAULT_OUTPUT_FILENAME
|
299 | 308 |
|
300 | 309 | if args.i:
|
301 |
| - input_filename_raw = args.i |
302 | 310 | # Encode the input string (type unicode) as a normal string (type str)
|
303 | 311 | # using the 'utf-8' encoding so that it can be worked with the same as
|
304 | 312 | # input names from other sources (like the defaults).
|
305 |
| - input_filename = input_filename_raw.encode('utf-8') |
| 313 | + input_filename_raw = args.i.encode('utf-8') |
| 314 | + # Decode the filename to a unicode string using the 'utf-8' encoding to |
| 315 | + # properly handle filepaths with unicode characters in them. |
| 316 | + input_filename = input_filename_raw.decode('utf-8') |
306 | 317 |
|
307 | 318 | if args.o:
|
308 | 319 | output_filename = args.o
|
309 | 320 |
|
310 |
| - # Decode the filename to a unicode string using the 'utf-8' encoding to |
311 |
| - # properly handle filepaths with unicode characters in them. |
312 |
| - with open(input_filename.decode('utf-8'), 'r') as ifile: |
| 321 | + with open(input_filename, 'r') as ifile: |
313 | 322 | file_string = ifile.read()
|
314 | 323 |
|
315 | 324 | json_string = None
|
|
0 commit comments