Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: localeTools.py

Issue 29560569: Issue 5815 - Fixed Crowdin upload with non-ASCII characters (Closed)
Patch Set: Created Oct. 1, 2017, 2:37 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This Source Code Form is subject to the terms of the Mozilla Public 1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 4
5 import re 5 import re
6 import os 6 import os
7 import sys 7 import sys
8 import codecs 8 import codecs
9 import json 9 import json
10 import urlparse 10 import urlparse
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 params = urllib.urlencode([('languages[]', locale) for locale in locales]) 337 params = urllib.urlencode([('languages[]', locale) for locale in locales])
338 338
339 crowdin_request(projectName, 'edit-project', key, post_data=params) 339 crowdin_request(projectName, 'edit-project', key, post_data=params)
340 340
341 341
342 def crowdin_prepare_upload(files): 342 def crowdin_prepare_upload(files):
343 """Create a post body and matching headers, which Crowdin can handle.""" 343 """Create a post body and matching headers, which Crowdin can handle."""
344 boundary = '----------ThIs_Is_tHe_bouNdaRY_$' 344 boundary = '----------ThIs_Is_tHe_bouNdaRY_$'
345 body = '' 345 body = ''
346 for name, data in files: 346 for name, data in files:
347 mimetype = mimetypes.guess_type(name)[0]
348 body += ( 347 body += (
349 '--{boundary}\r\n' 348 '--{boundary}\r\n'
350 'Content-Disposition: form-data; name="files[{name}]"; ' 349 'Content-Disposition: form-data; name="files[{name}]"; '
351 'filename="{name}"\r\n' 350 'filename="{name}"\r\n'
352 'Content-Type: {mimetype}; charset=utf-8\r\n' 351 'Content-Type: {mimetype}; charset=utf-8\r\n'
353 'Content-Transfer-Encoding: binary\r\n' 352 'Content-Transfer-Encoding: binary\r\n'
354 '\r\n{data}\r\n' 353 '\r\n{data}\r\n'
355 '--{boundary}--\r\n' 354 '--{boundary}--\r\n'
356 ).format(boundary=boundary, name=name, data=data, mimetype=mimetype) 355 ).format(boundary=boundary, name=name,
Vasily Kuznetsov 2017/10/01 09:54:28 I would put `name` on a separate line as well, it'
Sebastian Noack 2017/10/01 14:20:54 Done.
356 data=data.encode('utf-8'),
Sebastian Noack 2017/10/01 02:42:07 data is a unicode object. When passing any unicode
357 mimetype=mimetypes.guess_type(name)[0])
Sebastian Noack 2017/10/01 02:42:07 Kinda unrelated, but since this line has to be wra
357 358
358 body = body.encode('utf-8')
359 return ( 359 return (
360 StringIO(body), 360 StringIO(body),
361 { 361 {
362 'Content-Type': ('multipart/form-data; boundary=' + boundary), 362 'Content-Type': ('multipart/form-data; boundary=' + boundary),
363 'Content-Length': len(body) 363 'Content-Length': len(body)
364 }, 364 },
365 ) 365 )
366 366
367 367
368 def updateTranslationMaster(localeConfig, metadata, dir, projectName, key): 368 def updateTranslationMaster(localeConfig, metadata, dir, projectName, key):
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 504
505 # Remove any extra files 505 # Remove any extra files
506 for dir, files in dirs.iteritems(): 506 for dir, files in dirs.iteritems():
507 baseDir = os.path.join(localeConfig['base_path'], dir) 507 baseDir = os.path.join(localeConfig['base_path'], dir)
508 if not os.path.exists(baseDir): 508 if not os.path.exists(baseDir):
509 continue 509 continue
510 for file in os.listdir(baseDir): 510 for file in os.listdir(baseDir):
511 path = os.path.join(baseDir, file) 511 path = os.path.join(baseDir, file)
512 if os.path.isfile(path) and (file.endswith('.json') or file.endswith ('.properties') or file.endswith('.dtd')) and not file in files: 512 if os.path.isfile(path) and (file.endswith('.json') or file.endswith ('.properties') or file.endswith('.dtd')) and not file in files:
513 os.remove(path) 513 os.remove(path)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld