Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Side by Side Diff: Lib/packaging/util.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/packaging/tests/test_util.py ('k') | Lib/platform.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Miscellaneous utility functions.""" 1 """Miscellaneous utility functions."""
2 2
3 import os 3 import os
4 import re 4 import re
5 import csv 5 import csv
6 import sys 6 import sys
7 import errno 7 import errno
8 import shutil 8 import shutil
9 import string 9 import string
10 import hashlib 10 import hashlib
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 path = str(path) 750 path = str(path)
751 path = path.lstrip('/').lstrip('\\') 751 path = path.lstrip('/').lstrip('\\')
752 if '/' in path and (('\\' in path and path.find('/') < path.find('\\')) 752 if '/' in path and (('\\' in path and path.find('/') < path.find('\\'))
753 or '\\' not in path): 753 or '\\' not in path):
754 return path.split('/', 1) 754 return path.split('/', 1)
755 elif '\\' in path: 755 elif '\\' in path:
756 return path.split('\\', 1) 756 return path.split('\\', 1)
757 else: 757 else:
758 return path, '' 758 return path, ''
759 759
760 if sys.platform == 'darwin':
761 _cfg_target = None
762 _cfg_target_split = None
763 760
764 def spawn(cmd, search_path=True, verbose=0, dry_run=False, env=None): 761 def spawn(cmd, search_path=True, verbose=0, dry_run=False, env=None):
765 """Run another program specified as a command list 'cmd' in a new process. 762 """Run another program specified as a command list 'cmd' in a new process.
766 763
767 'cmd' is just the argument list for the new process, ie. 764 'cmd' is just the argument list for the new process, ie.
768 cmd[0] is the program to run and cmd[1:] are the rest of its arguments. 765 cmd[0] is the program to run and cmd[1:] are the rest of its arguments.
769 There is no way to run a program with a name different from that of its 766 There is no way to run a program with a name different from that of its
770 executable. 767 executable.
771 768
772 If 'search_path' is true (the default), the system's executable 769 If 'search_path' is true (the default), the system's executable
773 search path will be used to find the program; otherwise, cmd[0] 770 search path will be used to find the program; otherwise, cmd[0]
774 must be the exact path to the executable. If 'dry_run' is true, 771 must be the exact path to the executable. If 'dry_run' is true,
775 the command will not actually be run. 772 the command will not actually be run.
776 773
777 If 'env' is given, it's a environment dictionary used for the execution 774 If 'env' is given, it's a environment dictionary used for the execution
778 environment. 775 environment.
779 776
780 Raise PackagingExecError if running the program fails in any way; just 777 Raise PackagingExecError if running the program fails in any way; just
781 return on success. 778 return on success.
782 """ 779 """
783 logger.debug('spawn: running %r', cmd) 780 logger.debug('spawn: running %r', cmd)
784 if dry_run: 781 if dry_run:
785 logging.debug('dry run, no process actually spawned') 782 logging.debug('dry run, no process actually spawned')
786 return 783 return
787 if sys.platform == 'darwin':
788 global _cfg_target, _cfg_target_split
789 if _cfg_target is None:
790 _cfg_target = sysconfig.get_config_var(
791 'MACOSX_DEPLOYMENT_TARGET') or ''
792 if _cfg_target:
793 _cfg_target_split = [int(x) for x in _cfg_target.split('.')]
794 if _cfg_target:
795 # ensure that the deployment target of build process is not less
796 # than that used when the interpreter was built. This ensures
797 # extension modules are built with correct compatibility values
798 env = env or os.environ
799 cur_target = env.get('MACOSX_DEPLOYMENT_TARGET', _cfg_target)
800 if _cfg_target_split > [int(x) for x in cur_target.split('.')]:
801 my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: '
802 'now "%s" but "%s" during configure'
803 % (cur_target, _cfg_target))
804 raise PackagingPlatformError(my_msg)
805 env = dict(env, MACOSX_DEPLOYMENT_TARGET=cur_target)
806
807 exit_status = subprocess.call(cmd, env=env) 784 exit_status = subprocess.call(cmd, env=env)
808 if exit_status != 0: 785 if exit_status != 0:
809 msg = "command %r failed with exit status %d" 786 msg = "command %r failed with exit status %d"
810 raise PackagingExecError(msg % (cmd, exit_status)) 787 raise PackagingExecError(msg % (cmd, exit_status))
811 788
812 789
813 def find_executable(executable, path=None): 790 def find_executable(executable, path=None):
814 """Try to find 'executable' in the directories listed in 'path'. 791 """Try to find 'executable' in the directories listed in 'path'.
815 792
816 *path* is a string listing directories separated by 'os.pathsep' and 793 *path* is a string listing directories separated by 'os.pathsep' and
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
1480 try: 1457 try:
1481 os.mkdir(head, mode) 1458 os.mkdir(head, mode)
1482 except OSError as exc: 1459 except OSError as exc:
1483 if not (exc.errno == errno.EEXIST and os.path.isdir(head)): 1460 if not (exc.errno == errno.EEXIST and os.path.isdir(head)):
1484 raise PackagingFileError( 1461 raise PackagingFileError(
1485 "could not create '%s': %s" % (head, exc.args[-1])) 1462 "could not create '%s': %s" % (head, exc.args[-1]))
1486 created_dirs.append(head) 1463 created_dirs.append(head)
1487 1464
1488 _path_created.add(abs_head) 1465 _path_created.add(abs_head)
1489 return created_dirs 1466 return created_dirs
1490
1491
1492 def encode_multipart(fields, files, boundary=None):
1493 """Prepare a multipart HTTP request.
1494
1495 *fields* is a sequence of (name: str, value: str) elements for regular
1496 form fields, *files* is a sequence of (name: str, filename: str, value:
1497 bytes) elements for data to be uploaded as files.
1498
1499 Returns (content_type: bytes, body: bytes) ready for http.client.HTTP.
1500 """
1501 # Taken from
1502 # http://code.activestate.com/recipes/146306-http-client-to-post-using-multi partform-data/
1503
1504 if boundary is None:
1505 boundary = b'--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
1506 elif not isinstance(boundary, bytes):
1507 raise TypeError('boundary must be bytes, not %r' % type(boundary))
1508
1509 l = []
1510 for key, values in fields:
1511 # handle multiple entries for the same name
1512 if not isinstance(values, (tuple, list)):
1513 values=[values]
1514
1515 for value in values:
1516 l.extend((
1517 b'--' + boundary,
1518 ('Content-Disposition: form-data; name="%s"' %
1519 key).encode('utf-8'),
1520 b'',
1521 value.encode('utf-8')))
1522
1523 for key, filename, value in files:
1524 l.extend((
1525 b'--' + boundary,
1526 ('Content-Disposition: form-data; name="%s"; filename="%s"' %
1527 (key, filename)).encode('utf-8'),
1528 b'',
1529 value))
1530
1531 l.append(b'--' + boundary + b'--')
1532 l.append(b'')
1533
1534 body = b'\r\n'.join(l)
1535 content_type = b'multipart/form-data; boundary=' + boundary
1536 return content_type, body
OLDNEW
« no previous file with comments | « Lib/packaging/tests/test_util.py ('k') | Lib/platform.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+