Changeset 6e24def in trunk
- Timestamp:
- 2020-08-13T19:53:02Z (5 years ago)
- Branches:
- master
- Children:
- af61571
- Parents:
- 1037854 (diff), 942c5d52 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 5 added
- 2 deleted
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified .circleci/Dockerfile.centos ¶
r1037854 r6e24def 1 1 ARG TAG 2 2 FROM centos:${TAG} 3 ARG PYTHON_VERSION 3 4 4 5 ENV WHEELHOUSE_PATH /tmp/wheelhouse … … 12 13 sudo \ 13 14 make automake gcc gcc-c++ \ 14 python 2\15 python 2-devel \15 python${PYTHON_VERSION} \ 16 python${PYTHON_VERSION}-devel \ 16 17 libffi-devel \ 17 18 openssl-devel \ … … 24 25 COPY . ${BUILD_SRC_ROOT} 25 26 26 RUN "${BUILD_SRC_ROOT}"/.circleci/prepare-image.sh "${WHEELHOUSE_PATH}" "${VIRTUALENV_PATH}" "${BUILD_SRC_ROOT}" "python 2.7"27 RUN "${BUILD_SRC_ROOT}"/.circleci/prepare-image.sh "${WHEELHOUSE_PATH}" "${VIRTUALENV_PATH}" "${BUILD_SRC_ROOT}" "python${PYTHON_VERSION}" -
TabularUnified .circleci/Dockerfile.debian ¶
r1037854 r6e24def 1 1 ARG TAG 2 2 FROM debian:${TAG} 3 ARG PYTHON_VERSION 3 4 4 5 ENV WHEELHOUSE_PATH /tmp/wheelhouse … … 9 10 RUN apt-get --quiet update && \ 10 11 apt-get --quiet --yes install \ 11 12 12 git \ 13 lsb-release \ 13 14 sudo \ 14 15 python2.7\16 python2.7-dev \17 18 19 20 15 build-essential \ 16 python${PYTHON_VERSION} \ 17 python${PYTHON_VERSION}-dev \ 18 libffi-dev \ 19 libssl-dev \ 20 libyaml-dev \ 21 virtualenv 21 22 22 23 # Get the project source. This is better than it seems. CircleCI will … … 24 25 COPY . ${BUILD_SRC_ROOT} 25 26 26 RUN "${BUILD_SRC_ROOT}"/.circleci/prepare-image.sh "${WHEELHOUSE_PATH}" "${VIRTUALENV_PATH}" "${BUILD_SRC_ROOT}" "python 2.7"27 RUN "${BUILD_SRC_ROOT}"/.circleci/prepare-image.sh "${WHEELHOUSE_PATH}" "${VIRTUALENV_PATH}" "${BUILD_SRC_ROOT}" "python${PYTHON_VERSION}" 27 28 28 29 # Only the integration tests currently need this but it doesn't hurt to always -
TabularUnified .circleci/Dockerfile.fedora ¶
r1037854 r6e24def 1 1 ARG TAG 2 2 FROM fedora:${TAG} 3 ARG PYTHON_VERSION 3 4 4 5 ENV WHEELHOUSE_PATH /tmp/wheelhouse … … 12 13 sudo \ 13 14 make automake gcc gcc-c++ \ 14 python \15 python -devel \15 python${PYTHON_VERSION} \ 16 python${PYTHON_VERSION}-devel \ 16 17 libffi-devel \ 17 18 openssl-devel \ … … 24 25 COPY . ${BUILD_SRC_ROOT} 25 26 26 RUN "${BUILD_SRC_ROOT}"/.circleci/prepare-image.sh "${WHEELHOUSE_PATH}" "${VIRTUALENV_PATH}" "${BUILD_SRC_ROOT}" "python 2.7"27 RUN "${BUILD_SRC_ROOT}"/.circleci/prepare-image.sh "${WHEELHOUSE_PATH}" "${VIRTUALENV_PATH}" "${BUILD_SRC_ROOT}" "python${PYTHON_VERSION}" -
TabularUnified .circleci/Dockerfile.ubuntu ¶
r1037854 r6e24def 1 1 ARG TAG 2 2 FROM ubuntu:${TAG} 3 ARG PYTHON_VERSION 3 4 4 5 ENV WHEELHOUSE_PATH /tmp/wheelhouse … … 14 15 sudo \ 15 16 build-essential \ 16 python 2.7\17 python 2.7-dev \17 python${PYTHON_VERSION} \ 18 python${PYTHON_VERSION}-dev \ 18 19 libffi-dev \ 19 20 libssl-dev \ … … 27 28 COPY . ${BUILD_SRC_ROOT} 28 29 29 RUN "${BUILD_SRC_ROOT}"/.circleci/prepare-image.sh "${WHEELHOUSE_PATH}" "${VIRTUALENV_PATH}" "${BUILD_SRC_ROOT}" "python 2.7"30 RUN "${BUILD_SRC_ROOT}"/.circleci/prepare-image.sh "${WHEELHOUSE_PATH}" "${VIRTUALENV_PATH}" "${BUILD_SRC_ROOT}" "python${PYTHON_VERSION}" -
TabularUnified .circleci/config.yml ¶
r1037854 r6e24def 27 27 - "centos-8" 28 28 29 - "slackware-14.2"30 31 29 - "nixos-19.09" 32 30 33 31 # Test against PyPy 2.7 34 32 - "pypy2.7-buster" 33 34 # Just one Python 3.6 configuration while the port is in-progress. 35 - "python3.6" 35 36 36 37 # Other assorted tasks and configurations … … 73 74 - "build-image-fedora-29" 74 75 - "build-image-centos-8" 75 - "build-image-slackware-14.2"76 76 - "build-image-pypy-2.7-buster" 77 - "build-image-python36-ubuntu" 77 78 78 79 … … 122 123 debian-9: &DEBIAN 123 124 docker: 124 - image: "tahoelafsci/debian:9 "125 - image: "tahoelafsci/debian:9-py2.7" 125 126 user: "nobody" 126 127 … … 199 200 <<: *DEBIAN 200 201 docker: 201 - image: "tahoelafsci/debian:8 "202 - image: "tahoelafsci/debian:8-py2.7" 202 203 user: "nobody" 203 204 … … 206 207 <<: *DEBIAN 207 208 docker: 208 - image: "tahoelafsci/pypy: 2.7-buster"209 - image: "tahoelafsci/pypy:buster-py2" 209 210 user: "nobody" 210 211 … … 262 263 <<: *DEBIAN 263 264 docker: 264 - image: "tahoelafsci/ubuntu:16.04" 265 user: "nobody" 266 267 268 ubuntu-18.04: 269 <<: *DEBIAN 270 docker: 271 - image: "tahoelafsci/ubuntu:18.04" 272 user: "nobody" 265 - image: "tahoelafsci/ubuntu:16.04-py2.7" 266 user: "nobody" 267 268 269 ubuntu-18.04: &UBUNTU_18_04 270 <<: *DEBIAN 271 docker: 272 - image: "tahoelafsci/ubuntu:18.04-py2.7" 273 user: "nobody" 274 275 276 python3.6: 277 <<: *UBUNTU_18_04 278 docker: 279 - image: "tahoelafsci/ubuntu:18.04-py3" 280 user: "nobody" 281 282 environment: 283 <<: *UTF_8_ENVIRONMENT 284 TAHOE_LAFS_TOX_ENVIRONMENT: "py36" 273 285 274 286 … … 282 294 centos-8: &RHEL_DERIV 283 295 docker: 284 - image: "tahoelafsci/centos:8 "296 - image: "tahoelafsci/centos:8-py2" 285 297 user: "nobody" 286 298 … … 304 316 <<: *RHEL_DERIV 305 317 docker: 306 - image: "tahoelafsci/fedora:28 "318 - image: "tahoelafsci/fedora:28-py" 307 319 user: "nobody" 308 320 … … 311 323 <<: *RHEL_DERIV 312 324 docker: 313 - image: "tahoelafsci/fedora:29" 314 user: "nobody" 315 316 317 slackware-14.2: 318 docker: 319 - image: "tahoelafsci/slackware:14.2" 320 user: "nobody" 321 322 environment: *UTF_8_ENVIRONMENT 323 324 # pip cannot install packages if the working directory is not readable. 325 # We want to run a lot of steps as nobody instead of as root. 326 working_directory: "/tmp/project" 327 328 steps: 329 - "checkout" 330 - run: *SETUP_VIRTUALENV 331 - run: *RUN_TESTS 332 - store_test_results: *STORE_TEST_RESULTS 333 - store_artifacts: *STORE_TEST_LOG 334 - store_artifacts: *STORE_OTHER_ARTIFACTS 335 - run: *SUBMIT_COVERAGE 325 - image: "tahoelafsci/fedora:29-py" 326 user: "nobody" 327 336 328 337 329 nixos-19.09: … … 398 390 399 391 environment: 400 DISTRO: "tahoelafsci/<DISTRO>:foo" 401 TAG: "tahoelafsci/distro:<TAG>" 392 DISTRO: "tahoelafsci/<DISTRO>:foo-py2" 393 TAG: "tahoelafsci/distro:<TAG>-py2" 394 PYTHON_VERSION: "tahoelafsci/distro:tag-py<PYTHON_VERSION}" 402 395 403 396 steps: … … 451 444 build \ 452 445 --build-arg TAG=${TAG} \ 453 -t tahoelafsci/${DISTRO}:${TAG} \ 446 --build-arg PYTHON_VERSION=${PYTHON_VERSION} \ 447 -t tahoelafsci/${DISTRO}:${TAG}-py${PYTHON_VERSION} \ 454 448 -f ~/project/.circleci/Dockerfile.${DISTRO} \ 455 449 ~/project/ … … 457 451 name: "Push image" 458 452 command: | 459 docker push tahoelafsci/${DISTRO}:${TAG} 453 docker push tahoelafsci/${DISTRO}:${TAG}-py${PYTHON_VERSION} 460 454 461 455 … … 466 460 DISTRO: "debian" 467 461 TAG: "8" 462 PYTHON_VERSION: "2.7" 468 463 469 464 … … 474 469 DISTRO: "debian" 475 470 TAG: "9" 471 PYTHON_VERSION: "2.7" 476 472 477 473 … … 482 478 DISTRO: "ubuntu" 483 479 TAG: "16.04" 480 PYTHON_VERSION: "2.7" 484 481 485 482 … … 490 487 DISTRO: "ubuntu" 491 488 TAG: "18.04" 489 PYTHON_VERSION: "2.7" 490 491 492 build-image-python36-ubuntu: 493 <<: *BUILD_IMAGE 494 495 environment: 496 DISTRO: "ubuntu" 497 TAG: "18.04" 498 PYTHON_VERSION: "3" 492 499 493 500 … … 506 513 DISTRO: "centos" 507 514 TAG: "8" 515 PYTHON_VERSION: "2" 508 516 509 517 … … 514 522 DISTRO: "fedora" 515 523 TAG: "28" 524 # The default on Fedora (this version anyway) is still Python 2. 525 PYTHON_VERSION: "" 516 526 517 527 … … 524 534 525 535 526 build-image-slackware-14.2:527 <<: *BUILD_IMAGE528 529 environment:530 DISTRO: "slackware"531 TAG: "14.2"532 533 534 536 build-image-pypy-2.7-buster: 535 537 <<: *BUILD_IMAGE … … 537 539 environment: 538 540 DISTRO: "pypy" 539 TAG: "2.7-buster" 541 TAG: "buster" 542 # We only have Python 2 for PyPy right now so there's no support for 543 # setting up PyPy 3 in the image building toolchain. This value is just 544 # for constructing the right Docker image tag. 545 PYTHON_VERSION: "2" -
TabularUnified .circleci/populate-wheelhouse.sh ¶
r1037854 r6e24def 37 37 export PIP_FIND_LINKS="file://${WHEELHOUSE_PATH}" 38 38 39 # Populate the wheelhouse, if necessary. 40 "${PIP}" \ 39 # Populate the wheelhouse, if necessary. zfec 1.5.3 can only be built with a 40 # UTF-8 environment so make sure we have one, at least for this invocation. 41 LANG="en_US.UTF-8" "${PIP}" \ 41 42 wheel \ 42 43 --wheel-dir "${WHEELHOUSE_PATH}" \ -
TabularUnified .circleci/run-tests.sh ¶
r1037854 r6e24def 82 82 83 83 if [ -n "${ARTIFACTS}" ]; then 84 if [ ! -e "${SUBUNIT2}" ]; then 85 echo "subunitv2 output file does not exist: ${SUBUNIT2}" 86 exit 1 87 fi 88 84 89 # Create a junitxml results area. 85 90 mkdir -p "$(dirname "${JUNITXML}")" 86 ${BOOTSTRAP_VENV}/bin/subunit2junitxml < "${SUBUNIT2}" > "${JUNITXML}" || "${alternative}" 91 # Always succeed even if subunit2junitxml fails. subunit2junitxml signals 92 # failure if the stream it is processing contains test failures. This is 93 # not what we care about. If we cared about it, the test command above 94 # would have signalled failure already and we wouldn't be here. 95 "${BOOTSTRAP_VENV}"/bin/subunit2junitxml < "${SUBUNIT2}" > "${JUNITXML}" || true 87 96 fi -
TabularUnified misc/python3/ratchet-passing ¶
r1037854 r6e24def 10 10 allmydata.test.test_abbreviate.Abbreviate.test_space 11 11 allmydata.test.test_abbreviate.Abbreviate.test_time 12 allmydata.test.test_backupdb.BackupDB.test_basic 13 allmydata.test.test_backupdb.BackupDB.test_upgrade_v1_v2 14 allmydata.test.test_backupdb.BackupDB.test_wrong_version 12 15 allmydata.test.test_base32.Base32.test_a2b 13 16 allmydata.test.test_base32.Base32.test_a2b_b2a_match_Pythons … … 71 74 allmydata.test.test_dictutil.DictUtil.test_auxdict 72 75 allmydata.test.test_dictutil.DictUtil.test_dict_of_sets 76 allmydata.test.test_encodingutil.EncodingUtilErrors.test_argv_to_unicode 77 allmydata.test.test_encodingutil.EncodingUtilErrors.test_get_io_encoding 78 allmydata.test.test_encodingutil.EncodingUtilErrors.test_get_io_encoding_not_from_stdout 79 allmydata.test.test_encodingutil.EncodingUtilErrors.test_no_unicode_normalization 80 allmydata.test.test_encodingutil.EncodingUtilErrors.test_unicode_to_output 81 allmydata.test.test_encodingutil.FilePaths.test_extend_filepath 82 allmydata.test.test_encodingutil.FilePaths.test_to_filepath 83 allmydata.test.test_encodingutil.FilePaths.test_unicode_from_filepath 84 allmydata.test.test_encodingutil.FilePaths.test_unicode_segments_from 85 allmydata.test.test_encodingutil.MacOSXLeopard.test_argv_to_unicode 86 allmydata.test.test_encodingutil.MacOSXLeopard.test_listdir_unicode 87 allmydata.test.test_encodingutil.MacOSXLeopard.test_unicode_platform_py3 88 allmydata.test.test_encodingutil.MacOSXLeopard.test_unicode_to_argv_py3 89 allmydata.test.test_encodingutil.MacOSXLeopard.test_unicode_to_output 90 allmydata.test.test_encodingutil.MacOSXLeopard.test_unicode_to_url 91 allmydata.test.test_encodingutil.MacOSXLeopard7bit.test_argv_to_unicode 92 allmydata.test.test_encodingutil.MacOSXLeopard7bit.test_listdir_unicode 93 allmydata.test.test_encodingutil.MacOSXLeopard7bit.test_unicode_platform_py3 94 allmydata.test.test_encodingutil.MacOSXLeopard7bit.test_unicode_to_argv_py3 95 allmydata.test.test_encodingutil.MacOSXLeopard7bit.test_unicode_to_output 96 allmydata.test.test_encodingutil.MacOSXLeopard7bit.test_unicode_to_url 97 allmydata.test.test_encodingutil.OpenBSD.test_argv_to_unicode 98 allmydata.test.test_encodingutil.OpenBSD.test_listdir_unicode 99 allmydata.test.test_encodingutil.OpenBSD.test_unicode_platform_py3 100 allmydata.test.test_encodingutil.OpenBSD.test_unicode_to_argv_py3 101 allmydata.test.test_encodingutil.OpenBSD.test_unicode_to_output 102 allmydata.test.test_encodingutil.OpenBSD.test_unicode_to_url 103 allmydata.test.test_encodingutil.QuoteOutput.test_quote_output_ascii 104 allmydata.test.test_encodingutil.QuoteOutput.test_quote_output_default 105 allmydata.test.test_encodingutil.QuoteOutput.test_quote_output_latin1 106 allmydata.test.test_encodingutil.QuoteOutput.test_quote_output_utf8 107 allmydata.test.test_encodingutil.QuotePaths.test_quote_filepath 108 allmydata.test.test_encodingutil.QuotePaths.test_quote_path 109 allmydata.test.test_encodingutil.StdlibUnicode.test_mkdir_open_exists_abspath_listdir_expanduser 110 allmydata.test.test_encodingutil.TestToFromStr.test_from_utf8_or_none 111 allmydata.test.test_encodingutil.TestToFromStr.test_to_str 112 allmydata.test.test_encodingutil.UbuntuKarmicLatin1.test_argv_to_unicode 113 allmydata.test.test_encodingutil.UbuntuKarmicLatin1.test_listdir_unicode 114 allmydata.test.test_encodingutil.UbuntuKarmicLatin1.test_unicode_platform_py3 115 allmydata.test.test_encodingutil.UbuntuKarmicLatin1.test_unicode_to_argv_py3 116 allmydata.test.test_encodingutil.UbuntuKarmicLatin1.test_unicode_to_output 117 allmydata.test.test_encodingutil.UbuntuKarmicLatin1.test_unicode_to_url 118 allmydata.test.test_encodingutil.UbuntuKarmicUTF8.test_argv_to_unicode 119 allmydata.test.test_encodingutil.UbuntuKarmicUTF8.test_listdir_unicode 120 allmydata.test.test_encodingutil.UbuntuKarmicUTF8.test_unicode_platform_py3 121 allmydata.test.test_encodingutil.UbuntuKarmicUTF8.test_unicode_to_argv_py3 122 allmydata.test.test_encodingutil.UbuntuKarmicUTF8.test_unicode_to_output 123 allmydata.test.test_encodingutil.UbuntuKarmicUTF8.test_unicode_to_url 124 allmydata.test.test_encodingutil.Windows.test_argv_to_unicode 125 allmydata.test.test_encodingutil.Windows.test_unicode_platform_py3 126 allmydata.test.test_encodingutil.Windows.test_unicode_to_argv_py3 127 allmydata.test.test_encodingutil.Windows.test_unicode_to_output 128 allmydata.test.test_encodingutil.Windows.test_unicode_to_url 129 allmydata.test.test_happiness.Happiness.test_100 130 allmydata.test.test_happiness.Happiness.test_calc_happy 131 allmydata.test.test_happiness.Happiness.test_everything_broken 132 allmydata.test.test_happiness.Happiness.test_hypothesis0 133 allmydata.test.test_happiness.Happiness.test_hypothesis_0 134 allmydata.test.test_happiness.Happiness.test_hypothesis_1 135 allmydata.test.test_happiness.Happiness.test_placement_1 136 allmydata.test.test_happiness.Happiness.test_placement_simple 137 allmydata.test.test_happiness.Happiness.test_redistribute 138 allmydata.test.test_happiness.Happiness.test_unhappy 139 allmydata.test.test_happiness.HappinessUtils.test_residual_0 140 allmydata.test.test_happiness.HappinessUtils.test_trivial_flow_graph 141 allmydata.test.test_happiness.HappinessUtils.test_trivial_maximum_graph 142 allmydata.test.test_happiness.PlacementTests.test_hypothesis_unhappy 143 allmydata.test.test_happiness.PlacementTests.test_more_hypothesis 73 144 allmydata.test.test_hashtree.Complete.test_create 74 145 allmydata.test.test_hashtree.Complete.test_dump … … 144 215 allmydata.test.test_time_format.TimeFormat.test_parse_date 145 216 allmydata.test.test_time_format.TimeFormat.test_parse_duration 217 allmydata.test.test_util.FileUtil.test_abspath_expanduser_unicode 218 allmydata.test.test_util.FileUtil.test_create_long_path 219 allmydata.test.test_util.FileUtil.test_disk_stats 220 allmydata.test.test_util.FileUtil.test_disk_stats_avail_nonnegative 221 allmydata.test.test_util.FileUtil.test_du 222 allmydata.test.test_util.FileUtil.test_encrypted_tempfile 223 allmydata.test.test_util.FileUtil.test_get_pathinfo 224 allmydata.test.test_util.FileUtil.test_get_pathinfo_symlink 225 allmydata.test.test_util.FileUtil.test_make_dirs_with_absolute_mode 226 allmydata.test.test_util.FileUtil.test_remove_if_possible 227 allmydata.test.test_util.FileUtil.test_rename 228 allmydata.test.test_util.FileUtil.test_rename_no_overwrite 229 allmydata.test.test_util.FileUtil.test_replace_file 230 allmydata.test.test_util.FileUtil.test_rm_dir 231 allmydata.test.test_util.FileUtil.test_windows_expanduser_win7 232 allmydata.test.test_util.FileUtil.test_windows_expanduser_xp 233 allmydata.test.test_util.FileUtil.test_write_atomically 234 allmydata.test.test_util.IDLib.test_nodeid_b2a 235 allmydata.test.test_util.Math.test_round_sigfigs 236 allmydata.test.test_util.PollMixinTests.test_PollMixin_False_then_True 237 allmydata.test.test_util.PollMixinTests.test_PollMixin_True 238 allmydata.test.test_util.PollMixinTests.test_timeout 239 allmydata.test.test_util.YAML.test_convert 146 240 allmydata.test.test_version.CheckRequirement.test_cross_check 147 241 allmydata.test.test_version.CheckRequirement.test_cross_check_unparseable_versions -
TabularUnified misc/python3/ratchet.sh ¶
r1037854 r6e24def 10 10 cd "../.." 11 11 12 # Since both of the next calls are expected to exit non-0, relax our guard. 13 set +e 14 SUBUNITREPORTER_OUTPUT_PATH="$base/results.subunit2" trial --reporter subunitv2-file allmydata 15 subunit2junitxml < "$base/results.subunit2" > "$base/results.xml" 16 set -e 12 export SUBUNITREPORTER_OUTPUT_PATH="$base/results.subunit2" 13 # Since the next two calls are expected to exit non-0, relax our guard. 14 trial --reporter=subunitv2-file allmydata || true 15 subunit2junitxml < "${SUBUNITREPORTER_OUTPUT_PATH}" > "$base/results.xml" || true 17 16 18 17 # Okay, now we're clear. … … 33 32 export TERM=ansi 34 33 fi 35 git diff "$tracking_filename"36 34 37 exit $code 35 echo "The ${tracking_filename} diff is:" 36 echo "=================================" 37 # "git diff" gets pretty confused in this execution context when trying to 38 # write to stdout. Somehow it fails with SIGTTOU. 39 git diff -- "${tracking_filename}" > tracking.diff 40 cat tracking.diff 41 echo "=================================" 42 43 echo "Exiting with code ${code} from ratchet.py." 44 exit ${code} -
TabularUnified src/allmydata/client.py ¶
r1037854 r6e24def 742 742 private_key, public_key = ed25519.signing_keypair_from_string(private_key_str) 743 743 public_key_str = ed25519.string_from_verifying_key(public_key) 744 self.config.write_config_file("node.pubkey", public_key_str + "\n" )744 self.config.write_config_file("node.pubkey", public_key_str + "\n", "w") 745 745 self._node_private_key = private_key 746 746 self._node_public_key = public_key -
TabularUnified src/allmydata/dirnode.py ¶
r1037854 r6e24def 1 1 """Directory Node implementation.""" 2 import time , unicodedata2 import time 3 3 4 4 from zope.interface import implementer … … 19 19 from allmydata.monitor import Monitor 20 20 from allmydata.util import hashutil, base32, log 21 from allmydata.util.encodingutil import quote_output 21 from allmydata.util.encodingutil import quote_output, normalize 22 22 from allmydata.util.assertutil import precondition 23 23 from allmydata.util.netstring import netstring, split_netstring … … 101 101 return metadata 102 102 103 104 # 'x' at the end of a variable name indicates that it holds a Unicode string that may not105 # be NFC-normalized.106 107 def normalize(namex):108 return unicodedata.normalize('NFC', namex)109 103 110 104 # TODO: {Deleter,MetadataSetter,Adder}.modify all start by unpacking the -
TabularUnified src/allmydata/immutable/happiness_upload.py ¶
r1037854 r6e24def 1 2 from Queue import PriorityQueue 1 """ 2 Algorithms for figuring out happiness, the number of unique nodes the data is 3 on. 4 5 Ported to Python 3. 6 """ 7 from __future__ import absolute_import 8 from __future__ import division 9 from __future__ import print_function 10 from __future__ import unicode_literals 11 12 from future.utils import PY2 13 if PY2: 14 # We omit dict, just in case newdict breaks things for external Python 2 code. 15 from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, list, object, range, str, max, min # noqa: F401 16 17 from queue import PriorityQueue 3 18 4 19 … … 36 51 # BLACK vertices are those we have seen and explored 37 52 BLACK = 2 38 color = [WHITE for i in xrange(len(graph))]39 predecessor = [None for i in xrange(len(graph))]40 distance = [-1 for i in xrange(len(graph))]53 color = [WHITE for i in range(len(graph))] 54 predecessor = [None for i in range(len(graph))] 55 distance = [-1 for i in range(len(graph))] 41 56 queue = [s] # vertices that we haven't explored yet. 42 57 color[s] = GRAY … … 59 74 flow network in adjacency-list form, and f is a flow in graph. 60 75 """ 61 new_graph = [[] for i in xrange(len(graph))]62 cf = [[0 for s in xrange(len(graph))] for sh in xrange(len(graph))]63 for i in xrange(len(graph)):76 new_graph = [[] for i in range(len(graph))] 77 cf = [[0 for s in range(len(graph))] for sh in range(len(graph))] 78 for i in range(len(graph)): 64 79 for v in graph[i]: 65 80 if f[i][v] == 1: … … 136 151 137 152 dim = len(graph) 138 flow_function = [[0 for sh in xrange(dim)] for s in xrange(dim)]153 flow_function = [[0 for sh in range(dim)] for s in range(dim)] 139 154 residual_graph, residual_function = residual_network(graph, flow_function) 140 155 … … 261 276 #print "servermap %s" % servermap 262 277 for peer in peers: 263 if servermap.has_key(peer):278 if peer in servermap: 264 279 for s in servermap[peer]: 265 if s hare_to_index.has_key(s):280 if s in share_to_index: 266 281 indexedShares.append(share_to_index[s]) 267 282 graph.insert(peer_to_index[peer], indexedShares) … … 374 389 #print "new_peers %s" % new_peers 375 390 #print "new_mappings %s" % new_mappings 376 mappings = dict( readonly_mappings.items() + existing_mappings.items() + new_mappings.items())391 mappings = dict(list(readonly_mappings.items()) + list(existing_mappings.items()) + list(new_mappings.items())) 377 392 homeless_shares = set() 378 393 for share in mappings: … … 385 400 { 386 401 k: v 387 for k, v in peers_to_shares.items()402 for k, v in list(peers_to_shares.items()) 388 403 if k not in readonly_peers 389 404 } … … 402 417 return { 403 418 k: v.pop() if v else next(peer_iter) 404 for k, v in mappings.items()419 for k, v in list(mappings.items()) 405 420 } -
TabularUnified src/allmydata/test/common_py3.py ¶
r1037854 r6e24def 14 14 from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401 15 15 16 from past.builtins import unicode 17 16 18 import os 17 19 import time … … 19 21 20 22 from twisted.internet import reactor 23 from twisted.trial import unittest 24 25 from ..util.assertutil import precondition 26 from ..util.encodingutil import unicode_platform, get_filesystem_encoding 21 27 22 28 … … 66 72 signal.signal(signal.SIGCHLD, self.sigchldHandler) 67 73 return super(SignalMixin, self).tearDown() 74 75 76 class ReallyEqualMixin(object): 77 def failUnlessReallyEqual(self, a, b, msg=None): 78 self.assertEqual(a, b, msg) 79 self.assertEqual(type(a), type(b), "a :: %r, b :: %r, %r" % (a, b, msg)) 80 81 82 def skip_if_cannot_represent_filename(u): 83 precondition(isinstance(u, unicode)) 84 85 enc = get_filesystem_encoding() 86 if not unicode_platform(): 87 try: 88 u.encode(enc) 89 except UnicodeEncodeError: 90 raise unittest.SkipTest("A non-ASCII filename could not be encoded on this platform.") -
TabularUnified src/allmydata/test/common_util.py ¶
r1037854 r6e24def 10 10 11 11 from ..util.assertutil import precondition 12 from allmydata.util.encodingutil import (unicode_platform, get_filesystem_encoding, 13 get_io_encoding) 14 from ..scripts import runner 15 from .common_py3 import SignalMixin 12 from allmydata.util.encodingutil import get_io_encoding 13 from future.utils import PY2 14 if PY2: # XXX this is a hack that makes some tests pass on Python3, remove 15 # in the future 16 from ..scripts import runner 17 # Imported for backwards compatibility: 18 from .common_py3 import ( 19 SignalMixin, skip_if_cannot_represent_filename, ReallyEqualMixin, 20 ) 16 21 17 18 def skip_if_cannot_represent_filename(u):19 precondition(isinstance(u, unicode))20 21 enc = get_filesystem_encoding()22 if not unicode_platform():23 try:24 u.encode(enc)25 except UnicodeEncodeError:26 raise unittest.SkipTest("A non-ASCII filename could not be encoded on this platform.")27 22 28 23 def skip_if_cannot_represent_argv(u): … … 83 78 assert result != s, "Internal error -- flip_one_bit() produced the same string as its input: %s == %s" % (result, s) 84 79 return result 85 86 87 class ReallyEqualMixin(object):88 def failUnlessReallyEqual(self, a, b, msg=None):89 self.assertEqual(a, b, msg)90 self.assertEqual(type(a), type(b), "a :: %r, b :: %r, %r" % (a, b, msg))91 80 92 81 … … 184 173 make_readonly = _make_readonly 185 174 make_accessible = _make_accessible 175 176 177 __all__ = [ 178 "make_readonly", "make_accessible", "TestMixin", "ShouldFailMixin", 179 "StallMixin", "skip_if_cannot_represent_argv", "run_cli", "parse_cli", 180 "DevNullDictionary", "insecurerandstr", "flip_bit", "flip_one_bit", 181 "SignalMixin", "skip_if_cannot_represent_filename", "ReallyEqualMixin" 182 ] -
TabularUnified src/allmydata/test/test_encodingutil.py ¶
r1037854 r6e24def 1 1 from __future__ import print_function 2 from __future__ import absolute_import 3 from __future__ import division 4 from __future__ import unicode_literals 5 6 from future.utils import PY2, PY3 7 if PY2: 8 # We don't import str because omg way too ambiguous in this context. 9 from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, max, min # noqa: F401 10 11 from past.builtins import unicode 2 12 3 13 lumiere_nfc = u"lumi\u00E8re" … … 44 54 open(os.path.join(tmpdir, fname), 'w').close() 45 55 46 # Use Unicode API under Windows or MacOS X 47 if sys.platform in ('win32', 'darwin'): 56 # On Python 2, listing directories returns unicode under Windows or 57 # MacOS X if the input is unicode. On Python 3, it always returns 58 # Unicode. 59 if PY2 and sys.platform in ('win32', 'darwin'): 48 60 dirlist = os.listdir(unicode(tmpdir)) 49 61 else: … … 60 72 61 73 import os, sys, locale 74 from unittest import skipIf 62 75 63 76 from twisted.trial import unittest … … 65 78 from twisted.python.filepath import FilePath 66 79 67 from allmydata.test.common_util import ReallyEqualMixin 80 from allmydata.test.common_py3 import ( 81 ReallyEqualMixin, skip_if_cannot_represent_filename, 82 ) 68 83 from allmydata.util import encodingutil, fileutil 69 84 from allmydata.util.encodingutil import argv_to_unicode, unicode_to_url, \ … … 71 86 quote_filepath, unicode_platform, listdir_unicode, FilenameEncodingError, \ 72 87 get_io_encoding, get_filesystem_encoding, to_str, from_utf8_or_none, _reload, \ 73 to_filepath, extend_filepath, unicode_from_filepath, unicode_segments_from 74 from allmydata.dirnode import normalize 75 from .common_util import skip_if_cannot_represent_filename 88 to_filepath, extend_filepath, unicode_from_filepath, unicode_segments_from, \ 89 unicode_to_argv 76 90 from twisted.python import usage 77 91 … … 91 105 mock_stdout.encoding = 'cp65001' 92 106 _reload() 93 self. failUnlessReallyEqual(get_io_encoding(), 'utf-8')107 self.assertEqual(get_io_encoding(), 'utf-8') 94 108 95 109 mock_stdout.encoding = 'koi8-r' … … 123 137 preferredencoding = None 124 138 _reload() 125 self. failUnlessReallyEqual(get_io_encoding(), 'utf-8')139 self.assertEqual(get_io_encoding(), 'utf-8') 126 140 127 141 def test_argv_to_unicode(self): … … 151 165 # Unicode entities on the filesystem. 152 166 class EncodingUtilNonUnicodePlatform(unittest.TestCase): 167 @skipIf(PY3, "Python 3 is always Unicode, regardless of OS.") 153 168 def setUp(self): 154 169 # Mock sys.platform because unicode_platform() uses it … … 212 227 213 228 def test_unicode_to_url(self): 214 self.failUnless(unicode_to_url(lumiere_nfc), "lumi\xc3\xa8re")229 self.failUnless(unicode_to_url(lumiere_nfc), b"lumi\xc3\xa8re") 215 230 216 231 def test_unicode_to_output(self): … … 225 240 self.failUnlessReallyEqual(unicode_to_output(lumiere_nfc), self.argv) 226 241 227 def test_unicode_platform(self): 242 @skipIf(PY3, "Python 2 only.") 243 def test_unicode_to_argv_py2(self): 244 """unicode_to_argv() converts to bytes on Python 2.""" 245 self.assertEqual(unicode_to_argv("abc"), u"abc".encode(self.io_encoding)) 246 247 @skipIf(PY2, "Python 3 only.") 248 def test_unicode_to_argv_py3(self): 249 """unicode_to_argv() is noop on Python 3.""" 250 self.assertEqual(unicode_to_argv("abc"), "abc") 251 252 @skipIf(PY3, "Python 3 only.") 253 def test_unicode_platform_py2(self): 228 254 matrix = { 229 255 'linux2': False, … … 237 263 self.failUnlessReallyEqual(unicode_platform(), matrix[self.platform]) 238 264 265 @skipIf(PY2, "Python 3 isn't Python 2.") 266 def test_unicode_platform_py3(self): 267 _reload() 268 self.failUnlessReallyEqual(unicode_platform(), True) 269 239 270 def test_listdir_unicode(self): 240 271 if 'dirlist' not in dir(self): … … 249 280 250 281 def call_os_listdir(path): 251 return self.dirlist 282 if PY2: 283 return self.dirlist 284 else: 285 # Python 3 always lists unicode filenames: 286 return [d.decode(self.filesystem_encoding) if isinstance(d, bytes) 287 else d 288 for d in self.dirlist] 289 252 290 self.patch(os, 'listdir', call_os_listdir) 253 291 … … 259 297 filenames = listdir_unicode(u'/dummy') 260 298 261 self.failUnlessEqual(set([ normalize(fname) for fname in filenames]),299 self.failUnlessEqual(set([encodingutil.normalize(fname) for fname in filenames]), 262 300 set(TEST_FILENAMES)) 263 301 … … 279 317 open(fn, 'wb').close() 280 318 self.failUnless(os.path.exists(fn)) 281 self.failUnless(os.path.exists(os.path.join(os.getcwdu(), fn))) 319 if PY2: 320 getcwdu = os.getcwdu 321 else: 322 getcwdu = os.getcwd 323 self.failUnless(os.path.exists(os.path.join(getcwdu(), fn))) 282 324 filenames = listdir_unicode(lumiere_nfc) 283 325 284 326 # We only require that the listing includes a filename that is canonically equivalent 285 327 # to lumiere_nfc (on Mac OS X, it will be the NFD equivalent). 286 self.failUnlessIn(lumiere_nfc + ".txt", set([normalize(fname) for fname in filenames]))328 self.failUnlessIn(lumiere_nfc + u".txt", set([encodingutil.normalize(fname) for fname in filenames])) 287 329 288 330 expanded = fileutil.expanduser(u"~/" + lumiere_nfc) … … 315 357 if out[0:2] == 'b"': 316 358 pass 317 elif isinstance(inp, str): 318 self.failUnlessReallyEqual(quote_output(unicode(inp), encoding=enc, quote_newlines=quote_newlines), out) 319 self.failUnlessReallyEqual(quote_output(unicode(inp), encoding=enc, quotemarks=False, quote_newlines=quote_newlines), out2) 359 elif isinstance(inp, bytes): 360 try: 361 unicode_inp = inp.decode("utf-8") 362 except UnicodeDecodeError: 363 # Some things decode on Python 2, but not Python 3... 364 return 365 self.failUnlessReallyEqual(quote_output(unicode_inp, encoding=enc, quote_newlines=quote_newlines), out) 366 self.failUnlessReallyEqual(quote_output(unicode_inp, encoding=enc, quotemarks=False, quote_newlines=quote_newlines), out2) 320 367 else: 321 self.failUnlessReallyEqual(quote_output(inp.encode('utf-8'), encoding=enc, quote_newlines=quote_newlines), out) 322 self.failUnlessReallyEqual(quote_output(inp.encode('utf-8'), encoding=enc, quotemarks=False, quote_newlines=quote_newlines), out2) 368 try: 369 bytes_inp = inp.encode('utf-8') 370 except UnicodeEncodeError: 371 # Some things encode on Python 2, but not Python 3, e.g. 372 # surrogates like u"\uDC00\uD800"... 373 return 374 self.failUnlessReallyEqual(quote_output(bytes_inp, encoding=enc, quote_newlines=quote_newlines), out) 375 self.failUnlessReallyEqual(quote_output(bytes_inp, encoding=enc, quotemarks=False, quote_newlines=quote_newlines), out2) 323 376 324 377 def _test_quote_output_all(self, enc): … … 327 380 328 381 # optional single quotes 329 check( "foo","'foo'", True)330 check( "\\","'\\'", True)331 check( "$\"`","'$\"`'", True)332 check( "\n","'\n'", True, quote_newlines=False)382 check(b"foo", b"'foo'", True) 383 check(b"\\", b"'\\'", True) 384 check(b"$\"`", b"'$\"`'", True) 385 check(b"\n", b"'\n'", True, quote_newlines=False) 333 386 334 387 # mandatory single quotes 335 check( "\"","'\"'")388 check(b"\"", b"'\"'") 336 389 337 390 # double quotes 338 check( "'","\"'\"")339 check( "\n","\"\\x0a\"", quote_newlines=True)340 check( "\x00","\"\\x00\"")391 check(b"'", b"\"'\"") 392 check(b"\n", b"\"\\x0a\"", quote_newlines=True) 393 check(b"\x00", b"\"\\x00\"") 341 394 342 395 # invalid Unicode and astral planes 343 check(u"\uFDD0\uFDEF", "\"\\ufdd0\\ufdef\"")344 check(u"\uDC00\uD800", "\"\\udc00\\ud800\"")345 check(u"\uDC00\uD800\uDC00", "\"\\udc00\\U00010000\"")346 check(u"\uD800\uDC00", "\"\\U00010000\"")347 check(u"\uD800\uDC01", "\"\\U00010001\"")348 check(u"\uD801\uDC00", "\"\\U00010400\"")349 check(u"\uDBFF\uDFFF", "\"\\U0010ffff\"")350 check(u"'\uDBFF\uDFFF", "\"'\\U0010ffff\"")351 check(u"\"\uDBFF\uDFFF", "\"\\\"\\U0010ffff\"")396 check(u"\uFDD0\uFDEF", b"\"\\ufdd0\\ufdef\"") 397 check(u"\uDC00\uD800", b"\"\\udc00\\ud800\"") 398 check(u"\uDC00\uD800\uDC00", b"\"\\udc00\\U00010000\"") 399 check(u"\uD800\uDC00", b"\"\\U00010000\"") 400 check(u"\uD800\uDC01", b"\"\\U00010001\"") 401 check(u"\uD801\uDC00", b"\"\\U00010400\"") 402 check(u"\uDBFF\uDFFF", b"\"\\U0010ffff\"") 403 check(u"'\uDBFF\uDFFF", b"\"'\\U0010ffff\"") 404 check(u"\"\uDBFF\uDFFF", b"\"\\\"\\U0010ffff\"") 352 405 353 406 # invalid UTF-8 354 check( "\xFF","b\"\\xff\"")355 check( "\x00\"$\\`\x80\xFF","b\"\\x00\\\"\\$\\\\\\`\\x80\\xff\"")407 check(b"\xFF", b"b\"\\xff\"") 408 check(b"\x00\"$\\`\x80\xFF", b"b\"\\x00\\\"\\$\\\\\\`\\x80\\xff\"") 356 409 357 410 def test_quote_output_ascii(self, enc='ascii'): … … 360 413 361 414 self._test_quote_output_all(enc) 362 check(u"\u00D7", "\"\\xd7\"")363 check(u"'\u00D7", "\"'\\xd7\"")364 check(u"\"\u00D7", "\"\\\"\\xd7\"")365 check(u"\u2621", "\"\\u2621\"")366 check(u"'\u2621", "\"'\\u2621\"")367 check(u"\"\u2621", "\"\\\"\\u2621\"")368 check(u"\n", "'\n'", True, quote_newlines=False)369 check(u"\n", "\"\\x0a\"", quote_newlines=True)415 check(u"\u00D7", b"\"\\xd7\"") 416 check(u"'\u00D7", b"\"'\\xd7\"") 417 check(u"\"\u00D7", b"\"\\\"\\xd7\"") 418 check(u"\u2621", b"\"\\u2621\"") 419 check(u"'\u2621", b"\"'\\u2621\"") 420 check(u"\"\u2621", b"\"\\\"\\u2621\"") 421 check(u"\n", b"'\n'", True, quote_newlines=False) 422 check(u"\n", b"\"\\x0a\"", quote_newlines=True) 370 423 371 424 def test_quote_output_latin1(self, enc='latin1'): … … 412 465 class QuotePaths(ReallyEqualMixin, unittest.TestCase): 413 466 def test_quote_path(self): 414 self.failUnlessReallyEqual(quote_path([u'foo', u'bar']), "'foo/bar'")415 self.failUnlessReallyEqual(quote_path([u'foo', u'bar'], quotemarks=True), "'foo/bar'")416 self.failUnlessReallyEqual(quote_path([u'foo', u'bar'], quotemarks=False), "foo/bar")417 self.failUnlessReallyEqual(quote_path([u'foo', u'\nbar']), '"foo/\\x0abar"')418 self.failUnlessReallyEqual(quote_path([u'foo', u'\nbar'], quotemarks=True), '"foo/\\x0abar"')419 self.failUnlessReallyEqual(quote_path([u'foo', u'\nbar'], quotemarks=False), '"foo/\\x0abar"')467 self.failUnlessReallyEqual(quote_path([u'foo', u'bar']), b"'foo/bar'") 468 self.failUnlessReallyEqual(quote_path([u'foo', u'bar'], quotemarks=True), b"'foo/bar'") 469 self.failUnlessReallyEqual(quote_path([u'foo', u'bar'], quotemarks=False), b"foo/bar") 470 self.failUnlessReallyEqual(quote_path([u'foo', u'\nbar']), b'"foo/\\x0abar"') 471 self.failUnlessReallyEqual(quote_path([u'foo', u'\nbar'], quotemarks=True), b'"foo/\\x0abar"') 472 self.failUnlessReallyEqual(quote_path([u'foo', u'\nbar'], quotemarks=False), b'"foo/\\x0abar"') 420 473 421 474 self.failUnlessReallyEqual(quote_local_unicode_path(u"\\\\?\\C:\\foo"), 422 win32_other( "'C:\\foo'","'\\\\?\\C:\\foo'"))475 win32_other(b"'C:\\foo'", b"'\\\\?\\C:\\foo'")) 423 476 self.failUnlessReallyEqual(quote_local_unicode_path(u"\\\\?\\C:\\foo", quotemarks=True), 424 win32_other( "'C:\\foo'","'\\\\?\\C:\\foo'"))477 win32_other(b"'C:\\foo'", b"'\\\\?\\C:\\foo'")) 425 478 self.failUnlessReallyEqual(quote_local_unicode_path(u"\\\\?\\C:\\foo", quotemarks=False), 426 win32_other( "C:\\foo","\\\\?\\C:\\foo"))479 win32_other(b"C:\\foo", b"\\\\?\\C:\\foo")) 427 480 self.failUnlessReallyEqual(quote_local_unicode_path(u"\\\\?\\UNC\\foo\\bar"), 428 win32_other( "'\\\\foo\\bar'","'\\\\?\\UNC\\foo\\bar'"))481 win32_other(b"'\\\\foo\\bar'", b"'\\\\?\\UNC\\foo\\bar'")) 429 482 self.failUnlessReallyEqual(quote_local_unicode_path(u"\\\\?\\UNC\\foo\\bar", quotemarks=True), 430 win32_other( "'\\\\foo\\bar'","'\\\\?\\UNC\\foo\\bar'"))483 win32_other(b"'\\\\foo\\bar'", b"'\\\\?\\UNC\\foo\\bar'")) 431 484 self.failUnlessReallyEqual(quote_local_unicode_path(u"\\\\?\\UNC\\foo\\bar", quotemarks=False), 432 win32_other( "\\\\foo\\bar","\\\\?\\UNC\\foo\\bar"))485 win32_other(b"\\\\foo\\bar", b"\\\\?\\UNC\\foo\\bar")) 433 486 434 487 def test_quote_filepath(self): 435 488 foo_bar_fp = FilePath(win32_other(u'C:\\foo\\bar', u'/foo/bar')) 436 489 self.failUnlessReallyEqual(quote_filepath(foo_bar_fp), 437 win32_other( "'C:\\foo\\bar'","'/foo/bar'"))490 win32_other(b"'C:\\foo\\bar'", b"'/foo/bar'")) 438 491 self.failUnlessReallyEqual(quote_filepath(foo_bar_fp, quotemarks=True), 439 win32_other( "'C:\\foo\\bar'","'/foo/bar'"))492 win32_other(b"'C:\\foo\\bar'", b"'/foo/bar'")) 440 493 self.failUnlessReallyEqual(quote_filepath(foo_bar_fp, quotemarks=False), 441 win32_other( "C:\\foo\\bar","/foo/bar"))494 win32_other(b"C:\\foo\\bar", b"/foo/bar")) 442 495 443 496 if sys.platform == "win32": 444 497 foo_longfp = FilePath(u'\\\\?\\C:\\foo') 445 498 self.failUnlessReallyEqual(quote_filepath(foo_longfp), 446 "'C:\\foo'")499 b"'C:\\foo'") 447 500 self.failUnlessReallyEqual(quote_filepath(foo_longfp, quotemarks=True), 448 "'C:\\foo'")501 b"'C:\\foo'") 449 502 self.failUnlessReallyEqual(quote_filepath(foo_longfp, quotemarks=False), 450 "C:\\foo")503 b"C:\\foo") 451 504 452 505 … … 502 555 class UbuntuKarmicUTF8(EncodingUtil, unittest.TestCase): 503 556 uname = 'Linux korn 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:05:01 UTC 2009 x86_64' 504 argv = 'lumi\xc3\xa8re'557 argv = b'lumi\xc3\xa8re' 505 558 platform = 'linux2' 506 559 filesystem_encoding = 'UTF-8' 507 560 io_encoding = 'UTF-8' 508 dirlist = [ 'test_file', '\xc3\x84rtonwall.mp3','Blah blah.txt']561 dirlist = [b'test_file', b'\xc3\x84rtonwall.mp3', b'Blah blah.txt'] 509 562 510 563 class UbuntuKarmicLatin1(EncodingUtil, unittest.TestCase): 511 564 uname = 'Linux korn 2.6.31-14-generic #48-Ubuntu SMP Fri Oct 16 14:05:01 UTC 2009 x86_64' 512 argv = 'lumi\xe8re'565 argv = b'lumi\xe8re' 513 566 platform = 'linux2' 514 567 filesystem_encoding = 'ISO-8859-1' 515 568 io_encoding = 'ISO-8859-1' 516 dirlist = [ 'test_file', 'Blah blah.txt','\xc4rtonwall.mp3']569 dirlist = [b'test_file', b'Blah blah.txt', b'\xc4rtonwall.mp3'] 517 570 518 571 class Windows(EncodingUtil, unittest.TestCase): 519 572 uname = 'Windows XP 5.1.2600 x86 x86 Family 15 Model 75 Step ping 2, AuthenticAMD' 520 argv = 'lumi\xc3\xa8re'573 argv = b'lumi\xc3\xa8re' 521 574 platform = 'win32' 522 575 filesystem_encoding = 'mbcs' … … 526 579 class MacOSXLeopard(EncodingUtil, unittest.TestCase): 527 580 uname = 'Darwin g5.local 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:57:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_PPC Power Macintosh powerpc' 528 output = 'lumi\xc3\xa8re'581 output = b'lumi\xc3\xa8re' 529 582 platform = 'darwin' 530 583 filesystem_encoding = 'utf-8' … … 549 602 class TestToFromStr(ReallyEqualMixin, unittest.TestCase): 550 603 def test_to_str(self): 551 self.failUnlessReallyEqual(to_str( "foo"),"foo")552 self.failUnlessReallyEqual(to_str( "lumi\xc3\xa8re"),"lumi\xc3\xa8re")553 self.failUnlessReallyEqual(to_str( "\xFF"),"\xFF") # passes through invalid UTF-8 -- is this what we want?554 self.failUnlessReallyEqual(to_str(u"lumi\u00E8re"), "lumi\xc3\xa8re")604 self.failUnlessReallyEqual(to_str(b"foo"), b"foo") 605 self.failUnlessReallyEqual(to_str(b"lumi\xc3\xa8re"), b"lumi\xc3\xa8re") 606 self.failUnlessReallyEqual(to_str(b"\xFF"), b"\xFF") # passes through invalid UTF-8 -- is this what we want? 607 self.failUnlessReallyEqual(to_str(u"lumi\u00E8re"), b"lumi\xc3\xa8re") 555 608 self.failUnlessReallyEqual(to_str(None), None) 556 609 557 610 def test_from_utf8_or_none(self): 558 611 self.failUnlessRaises(AssertionError, from_utf8_or_none, u"foo") 559 self.failUnlessReallyEqual(from_utf8_or_none( "lumi\xc3\xa8re"), u"lumi\u00E8re")612 self.failUnlessReallyEqual(from_utf8_or_none(b"lumi\xc3\xa8re"), u"lumi\u00E8re") 560 613 self.failUnlessReallyEqual(from_utf8_or_none(None), None) 561 self.failUnlessRaises(UnicodeDecodeError, from_utf8_or_none, "\xFF")614 self.failUnlessRaises(UnicodeDecodeError, from_utf8_or_none, b"\xFF") -
TabularUnified src/allmydata/test/test_happiness.py ¶
r1037854 r6e24def 1 1 # -*- coding: utf-8 -*- 2 3 from __future__ import absolute_import 4 from __future__ import division 5 from __future__ import print_function 6 from __future__ import unicode_literals 7 8 from future.utils import PY2 9 if PY2: 10 # We omit dict, just in case newdict breaks things. 11 from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, list, object, range, str, max, min # noqa: F401 2 12 3 13 from twisted.trial import unittest -
TabularUnified src/allmydata/test/test_util.py ¶
r1037854 r6e24def 1 """ 2 Ported to Python3. 3 """ 4 1 5 from __future__ import print_function 2 6 from __future__ import absolute_import 7 from __future__ import division 8 from __future__ import unicode_literals 9 10 from future.utils import PY2 11 if PY2: 12 from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401 3 13 import six 4 14 import os, time, sys … … 20 30 class IDLib(unittest.TestCase): 21 31 def test_nodeid_b2a(self): 22 self.failUnlessEqual(idlib.nodeid_b2a( "\x00"*20), "a"*32)32 self.failUnlessEqual(idlib.nodeid_b2a(b"\x00"*20), "a"*32) 23 33 24 34 … … 86 96 fileutil.make_dirs(basedir) 87 97 fn = os.path.join(basedir, "here") 88 fileutil.write_atomically(fn, "one")89 self.failUnlessEqual(fileutil.read(fn), "one")90 fileutil.write_atomically(fn, "two", mode="") # non-binary91 self.failUnlessEqual(fileutil.read(fn), "two")98 fileutil.write_atomically(fn, b"one", "b") 99 self.failUnlessEqual(fileutil.read(fn), b"one") 100 fileutil.write_atomically(fn, u"two", mode="") # non-binary 101 self.failUnlessEqual(fileutil.read(fn), b"two") 92 102 93 103 def test_rename(self): … … 112 122 113 123 # when only dest exists 114 fileutil.write(dest_path, "dest")124 fileutil.write(dest_path, b"dest") 115 125 self.failUnlessRaises(OSError, fileutil.rename_no_overwrite, source_path, dest_path) 116 self.failUnlessEqual(fileutil.read(dest_path), "dest")126 self.failUnlessEqual(fileutil.read(dest_path), b"dest") 117 127 118 128 # when both exist 119 fileutil.write(source_path, "source")129 fileutil.write(source_path, b"source") 120 130 self.failUnlessRaises(OSError, fileutil.rename_no_overwrite, source_path, dest_path) 121 self.failUnlessEqual(fileutil.read(source_path), "source")122 self.failUnlessEqual(fileutil.read(dest_path), "dest")131 self.failUnlessEqual(fileutil.read(source_path), b"source") 132 self.failUnlessEqual(fileutil.read(dest_path), b"dest") 123 133 124 134 # when only source exists 125 135 os.remove(dest_path) 126 136 fileutil.rename_no_overwrite(source_path, dest_path) 127 self.failUnlessEqual(fileutil.read(dest_path), "source")137 self.failUnlessEqual(fileutil.read(dest_path), b"source") 128 138 self.failIf(os.path.exists(source_path)) 129 139 … … 139 149 140 150 # when only replaced exists 141 fileutil.write(replaced_path, 151 fileutil.write(replaced_path, b"foo") 142 152 self.failUnlessRaises(fileutil.ConflictError, fileutil.replace_file, replaced_path, replacement_path) 143 self.failUnlessEqual(fileutil.read(replaced_path), "foo")153 self.failUnlessEqual(fileutil.read(replaced_path), b"foo") 144 154 145 155 # when both replaced and replacement exist 146 fileutil.write(replacement_path, "bar")156 fileutil.write(replacement_path, b"bar") 147 157 fileutil.replace_file(replaced_path, replacement_path) 148 self.failUnlessEqual(fileutil.read(replaced_path), "bar")158 self.failUnlessEqual(fileutil.read(replaced_path), b"bar") 149 159 self.failIf(os.path.exists(replacement_path)) 150 160 151 161 # when only replacement exists 152 162 os.remove(replaced_path) 153 fileutil.write(replacement_path, "bar")163 fileutil.write(replacement_path, b"bar") 154 164 fileutil.replace_file(replaced_path, replacement_path) 155 self.failUnlessEqual(fileutil.read(replaced_path), "bar")165 self.failUnlessEqual(fileutil.read(replaced_path), b"bar") 156 166 self.failIf(os.path.exists(replacement_path)) 157 167 … … 171 181 172 182 def test_abspath_expanduser_unicode(self): 173 self.failUnlessRaises(AssertionError, fileutil.abspath_expanduser_unicode, "bytestring") 174 175 saved_cwd = os.path.normpath(os.getcwdu()) 183 self.failUnlessRaises(AssertionError, fileutil.abspath_expanduser_unicode, b"bytestring") 184 185 saved_cwd = os.path.normpath(os.getcwd()) 186 if PY2: 187 saved_cwd = saved_cwd.decode("utf8") 176 188 abspath_cwd = fileutil.abspath_expanduser_unicode(u".") 177 189 abspath_cwd_notlong = fileutil.abspath_expanduser_unicode(u".", long_path=False) 178 self.failUnless(isinstance(saved_cwd, unicode), saved_cwd)179 self.failUnless(isinstance(abspath_cwd, unicode), abspath_cwd)190 self.failUnless(isinstance(saved_cwd, str), saved_cwd) 191 self.failUnless(isinstance(abspath_cwd, str), abspath_cwd) 180 192 if sys.platform == "win32": 181 193 self.failUnlessReallyEqual(abspath_cwd, fileutil.to_windows_long_path(saved_cwd)) … … 238 250 for upath in (u'', u'fuu', u'f\xf9\xf9', u'/fuu', u'U:\\', u'~'): 239 251 uabspath = fileutil.abspath_expanduser_unicode(upath) 240 self.failUnless(isinstance(uabspath, unicode), uabspath)252 self.failUnless(isinstance(uabspath, str), uabspath) 241 253 242 254 uabspath_notlong = fileutil.abspath_expanduser_unicode(upath, long_path=False) 243 self.failUnless(isinstance(uabspath_notlong, unicode), uabspath_notlong)255 self.failUnless(isinstance(uabspath_notlong, str), uabspath_notlong) 244 256 finally: 245 257 os.chdir(saved_cwd) … … 294 306 self.addCleanup(_cleanup) 295 307 296 fileutil.write(long_path, "test")308 fileutil.write(long_path, b"test") 297 309 self.failUnless(os.path.exists(long_path)) 298 self.failUnlessEqual(fileutil.read(long_path), "test")310 self.failUnlessEqual(fileutil.read(long_path), b"test") 299 311 _cleanup() 300 312 self.failIf(os.path.exists(long_path)) … … 354 366 # create a file 355 367 f = os.path.join(basedir, "1.txt") 356 fileutil.write(f, "a"*10)368 fileutil.write(f, b"a"*10) 357 369 fileinfo = fileutil.get_pathinfo(f) 358 370 self.failUnlessTrue(fileinfo.isfile) … … 382 394 383 395 f = os.path.join(basedir, "1.txt") 384 fileutil.write(f, "a"*10)396 fileutil.write(f, b"a"*10) 385 397 386 398 # create a symlink pointing to 1.txt … … 395 407 def test_encrypted_tempfile(self): 396 408 f = EncryptedTemporaryFile() 397 f.write( "foobar")409 f.write(b"foobar") 398 410 f.close() 399 411 … … 410 422 def test_PollMixin_False_then_True(self): 411 423 i = iter([False, True]) 412 d = self.pm.poll(check_f= i.next,424 d = self.pm.poll(check_f=lambda: next(i), 413 425 pollinterval=0.1) 414 426 return d … … 455 467 data = yaml.safe_dump(["str", u"unicode", u"\u1234nicode"]) 456 468 back = yamlutil.safe_load(data) 457 self. failUnlessEqual(type(back[0]), unicode)458 self. failUnlessEqual(type(back[1]), unicode)459 self. failUnlessEqual(type(back[2]), unicode)469 self.assertIsInstance(back[0], str) 470 self.assertIsInstance(back[1], str) 471 self.assertIsInstance(back[2], str) -
TabularUnified src/allmydata/util/_python3.py ¶
r1037854 r6e24def 23 23 "allmydata.crypto.util", 24 24 "allmydata.hashtree", 25 "allmydata.immutable.happiness_upload", 25 26 "allmydata.test.common_py3", 26 27 "allmydata.util._python3", … … 32 33 "allmydata.util.connection_status", 33 34 "allmydata.util.deferredutil", 35 "allmydata.util.fileutil", 34 36 "allmydata.util.dictutil", 37 "allmydata.util.encodingutil", 35 38 "allmydata.util.gcutil", 36 39 "allmydata.util.hashutil", … … 58 61 "allmydata.test.test_deferredutil", 59 62 "allmydata.test.test_dictutil", 63 "allmydata.test.test_encodingutil", 64 "allmydata.test.test_happiness", 60 65 "allmydata.test.test_hashtree", 61 66 "allmydata.test.test_hashutil", … … 70 75 "allmydata.test.test_statistics", 71 76 "allmydata.test.test_time_format", 77 "allmydata.test.test_util", 72 78 "allmydata.test.test_version", 73 79 ] 74 75 80 76 81 if __name__ == '__main__': -
TabularUnified src/allmydata/util/encodingutil.py ¶
r1037854 r6e24def 2 2 Functions used to convert inputs from whatever encoding used in the system to 3 3 unicode and back. 4 5 Ported to Python 3. 6 7 Once Python 2 support is dropped, most of this module will obsolete, since 8 Unicode is the default everywhere in Python 3. 4 9 """ 10 from __future__ import absolute_import 11 from __future__ import division 12 from __future__ import print_function 13 from __future__ import unicode_literals 14 15 from future.utils import PY2, PY3, native_str 16 if PY2: 17 # We omit str() because that seems too tricky to get right. 18 from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, max, min # noqa: F401 19 20 from past.builtins import unicode 5 21 6 22 import sys, os, re, locale 23 import unicodedata 7 24 8 25 from allmydata.util.assertutil import precondition, _assert … … 63 80 check_encoding(io_encoding) 64 81 65 is_unicode_platform = sys.platform in ["win32", "darwin"]82 is_unicode_platform = PY3 or sys.platform in ["win32", "darwin"] 66 83 67 84 # Despite the Unicode-mode FilePath support added to Twisted in 68 85 # <https://twistedmatrix.com/trac/ticket/7805>, we can't yet use 69 86 # Unicode-mode FilePaths with INotify on non-Windows platforms 70 # due to <https://twistedmatrix.com/trac/ticket/7928>. 71 use_unicode_filepath = sys.platform == "win32" 87 # due to <https://twistedmatrix.com/trac/ticket/7928>. Supposedly 88 # 7928 is fixed, though... 89 use_unicode_filepath = PY3 or sys.platform == "win32" 72 90 73 91 _reload() … … 90 108 Decode given argv element to unicode. If this fails, raise a UsageError. 91 109 """ 92 precondition(isinstance(s, str), s) 110 if isinstance(s, unicode): 111 return s 112 113 precondition(isinstance(s, bytes), s) 93 114 94 115 try: … … 115 136 should be true; on Windows, this uses a mangled encoding that will be reversed by 116 137 code in runner.py. 138 139 On Python 3, just return the string unchanged, since argv is unicode. 117 140 """ 118 141 precondition(isinstance(s, unicode), s) 142 if PY3: 143 return s 119 144 120 145 if mangle and sys.platform == "win32": 121 146 # This must be the same as 'mangle' in bin/tahoe-script.template. 122 return str(re.sub(u'[^\\x20-\\x7F]', lambda m: u'\x7F%x;' % (ord(m.group(0)),), s))147 return bytes(re.sub(u'[^\\x20-\\x7F]', lambda m: u'\x7F%x;' % (ord(m.group(0)),), s), io_encoding) 123 148 else: 124 149 return s.encode(io_encoding) … … 126 151 def unicode_to_url(s): 127 152 """ 128 Encode an unicode object used in an URL .153 Encode an unicode object used in an URL to bytes. 129 154 """ 130 155 # According to RFC 2718, non-ascii characters in URLs must be UTF-8 encoded. … … 135 160 #return s.encode('utf-8') 136 161 137 def to_str(s): 138 if s is None or isinstance(s, str):162 def to_str(s): # TODO rename to to_bytes 163 if s is None or isinstance(s, bytes): 139 164 return s 140 165 return s.encode('utf-8') 141 166 142 167 def from_utf8_or_none(s): 143 precondition(isinstance(s, (NoneType, str)), s)168 precondition(isinstance(s, bytes) or s is None, s) 144 169 if s is None: 145 170 return s 146 171 return s.decode('utf-8') 147 172 148 PRINTABLE_ASCII = re.compile( r'^[\n\r\x20-\x7E]*$', re.DOTALL)149 PRINTABLE_8BIT = re.compile( r'^[\n\r\x20-\x7E\x80-\xFF]*$', re.DOTALL)173 PRINTABLE_ASCII = re.compile(br'^[\n\r\x20-\x7E]*$', re.DOTALL) 174 PRINTABLE_8BIT = re.compile(br'^[\n\r\x20-\x7E\x80-\xFF]*$', re.DOTALL) 150 175 151 176 def is_printable_ascii(s): … … 161 186 out = s.encode(io_encoding) 162 187 except (UnicodeEncodeError, UnicodeDecodeError): 163 raise UnicodeEncodeError( io_encoding, s, 0, 0,164 "A string could not be encoded as %s for output to the terminal:\n%r" %165 (io_encoding, repr(s))) 188 raise UnicodeEncodeError(native_str(io_encoding), s, 0, 0, 189 native_str("A string could not be encoded as %s for output to the terminal:\n%r" % 190 (io_encoding, repr(s)))) 166 191 167 192 if PRINTABLE_8BIT.search(out) is None: 168 raise UnicodeEncodeError( io_encoding, s, 0, 0,169 "A string encoded as %s for output to the terminal contained unsafe bytes:\n%r" %170 (io_encoding, repr(s))) 193 raise UnicodeEncodeError(native_str(io_encoding), s, 0, 0, 194 native_str("A string encoded as %s for output to the terminal contained unsafe bytes:\n%r" % 195 (io_encoding, repr(s)))) 171 196 return out 172 197 … … 189 214 return u'\\x%02x' % (codepoint,) 190 215 191 def _str_escape(m, quote_newlines): 216 def _str_escape(m, quote_newlines): # TODO rename to _bytes_escape 217 """ 218 Takes a re match on bytes, the result is escaped bytes of group(0). 219 """ 192 220 c = m.group(0) 193 if c == '"' or c == '$' or c == '`' or c =='\\':194 return '\\' + c195 elif c == '\n' and not quote_newlines:221 if c == b'"' or c == b'$' or c == b'`' or c == b'\\': 222 return b'\\' + c 223 elif c == b'\n' and not quote_newlines: 196 224 return c 197 225 else: 198 return '\\x%02x' % (ord(c),)226 return b'\\x%02x' % (ord(c),) 199 227 200 228 MUST_DOUBLE_QUOTE_NL = re.compile(u'[^\\x20-\\x26\\x28-\\x7E\u00A0-\uD7FF\uE000-\uFDCF\uFDF0-\uFFFC]', re.DOTALL) … … 206 234 re.DOTALL) 207 235 208 ESCAPABLE_8BIT = re.compile( r'[^ !#\x25-\x5B\x5D-\x5F\x61-\x7E]', re.DOTALL)236 ESCAPABLE_8BIT = re.compile( br'[^ !#\x25-\x5B\x5D-\x5F\x61-\x7E]', re.DOTALL) 209 237 210 238 def quote_output(s, quotemarks=True, quote_newlines=None, encoding=None): … … 222 250 If not explicitly given, quote_newlines is True when quotemarks is True. 223 251 """ 224 precondition(isinstance(s, ( str, unicode)), s)252 precondition(isinstance(s, (bytes, unicode)), s) 225 253 if quote_newlines is None: 226 254 quote_newlines = quotemarks 227 255 228 if isinstance(s, str):256 if isinstance(s, bytes): 229 257 try: 230 258 s = s.decode('utf-8') 231 259 except UnicodeDecodeError: 232 return 'b"%s"' % (ESCAPABLE_8BIT.sub(lambda m: _str_escape(m, quote_newlines), s),)260 return b'b"%s"' % (ESCAPABLE_8BIT.sub(lambda m: _str_escape(m, quote_newlines), s),) 233 261 234 262 must_double_quote = quote_newlines and MUST_DOUBLE_QUOTE_NL or MUST_DOUBLE_QUOTE … … 236 264 try: 237 265 out = s.encode(encoding or io_encoding) 238 if quotemarks or out.startswith( '"'):239 return "'%s'" % (out,)266 if quotemarks or out.startswith(b'"'): 267 return b"'%s'" % (out,) 240 268 else: 241 269 return out … … 244 272 245 273 escaped = ESCAPABLE_UNICODE.sub(lambda m: _unicode_escape(m, quote_newlines), s) 246 return '"%s"' % (escaped.encode(encoding or io_encoding, 'backslashreplace'),)274 return b'"%s"' % (escaped.encode(encoding or io_encoding, 'backslashreplace'),) 247 275 248 276 def quote_path(path, quotemarks=True): 249 return quote_output( "/".join(map(to_str, path)), quotemarks=quotemarks, quote_newlines=True)277 return quote_output(b"/".join(map(to_str, path)), quotemarks=quotemarks, quote_newlines=True) 250 278 251 279 def quote_local_unicode_path(path, quotemarks=True): … … 276 304 277 305 def to_filepath(path): 278 precondition(isinstance(path, unicode if use_unicode_filepath else basestring),306 precondition(isinstance(path, unicode if use_unicode_filepath else (bytes, unicode)), 279 307 path=path) 280 308 … … 291 319 292 320 def _decode(s): 293 precondition(isinstance(s, basestring), s=s)321 precondition(isinstance(s, (bytes, unicode)), s=s) 294 322 295 323 if isinstance(s, bytes): … … 357 385 def listdir_filepath(fp): 358 386 return listdir_unicode(unicode_from_filepath(fp)) 387 388 389 # 'x' at the end of a variable name indicates that it holds a Unicode string that may not 390 # be NFC-normalized. 391 def normalize(namex): 392 return unicodedata.normalize('NFC', namex) -
TabularUnified src/allmydata/util/fileutil.py ¶
r1037854 r6e24def 1 from __future__ import print_function2 3 1 """ 2 Ported to Python3. 3 4 4 Futz with files like a pro. 5 5 """ 6 7 from __future__ import print_function 8 from __future__ import absolute_import 9 from __future__ import division 10 from __future__ import unicode_literals 11 12 from future.utils import PY2 13 if PY2: 14 # open is not here because we want to use native strings on Py2 15 from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401 6 16 7 17 import sys, os, stat, tempfile, time, binascii … … 254 264 255 265 def write_atomically(target, contents, mode="b"): 266 assert ( 267 isinstance(contents, bytes) and "b" in mode or 268 isinstance(contents, str) and "t" in mode or mode == ""), (type(contents), mode) 256 269 with open(target+".tmp", "w"+mode) as f: 257 270 f.write(contents) … … 278 291 279 292 def precondition_abspath(path): 280 if not isinstance(path, unicode):293 if not isinstance(path, str): 281 294 raise AssertionError("an abspath must be a Unicode string") 282 295 … … 310 323 On Windows, the result will be a long path unless long_path is given as False. 311 324 """ 312 if not isinstance(path, unicode):325 if not isinstance(path, str): 313 326 raise AssertionError("paths must be Unicode strings") 314 327 if base is not None and long_path: … … 331 344 if not os.path.isabs(path): 332 345 if base is None: 333 path = os.path.join(os.getcwdu(), path) 346 cwd = os.getcwd() 347 if PY2: 348 cwd = cwd.decode('utf8') 349 path = os.path.join(cwd, path) 334 350 else: 335 351 path = os.path.join(base, path) … … 416 432 # Based on <http://stackoverflow.com/questions/2608200/problems-with-umlauts-in-python-appdata-environvent-variable/2608368#2608368>, 417 433 # with improved error handling. Returns None if there is no enivronment variable of the given name. 418 if not isinstance(name, unicode):434 if not isinstance(name, str): 419 435 raise AssertionError("name must be Unicode") 420 436 -
TabularUnified src/allmydata/util/statistics.py ¶
r1037854 r6e24def 21 21 from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401 22 22 23 from functools import reduce24 25 23 from allmydata.util.mathutil import round_sigfigs 26 24 import math 25 from functools import reduce 27 26 import sys 28 27 -
TabularUnified tox.ini ¶
r1037854 r6e24def 51 51 [testenv:py36] 52 52 # On macOS, git inside of ratchet.sh needs $HOME. 53 passenv = HOME53 passenv = {[testenv]passenv} HOME 54 54 commands = {toxinidir}/misc/python3/ratchet.sh 55 55
Note: See TracChangeset
for help on using the changeset viewer.