Skip to content

Commit 5d8b18d

Browse files
committed
Cleanup Python-2 related comments and workarounds
1 parent 3cbc5ff commit 5d8b18d

File tree

3 files changed

+17
-34
lines changed

3 files changed

+17
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Integration and unit tests are provided.
4343
- (Note: Running `pip install -r tests/ci_requirements.txt` will install this package)
4444
- A `tests/config` file (you can copy an example from `tests/example_config`).
4545
- Tests can be run individually like this: `nosetests --config="nose.cfg" tests/test_client.py`
46-
- Make sure to not forget the `--config="nose.cfg"` option. This option tells nose to use our config file. This will exclude python 2- and 3-specific files in the `/lib` directory, preventing a failure from being reported by nose for compilation due to incompatible syntax in those files.
46+
- Make sure to not forget the `--config="nose.cfg"` option. This option tells nose to use our config file.
4747
- `test_client` and `tests_unit` use mock server interaction and do not require a Flow Production Tracking instance to be available (no modifications to `tests/config` are necessary).
4848
- `test_api` and `test_api_long` *do* require a Flow Production Tracking instance, with a script key available for the tests. The server and script user values must be supplied in the `tests/config` file. The tests will add test data to your server based on information in your config. This data will be manipulated by the tests, and should not be used for other purposes.
4949
- To run all of the tests, use the shell script `run-tests`.

azure-pipelines-templates/run-tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ parameters:
3333

3434
jobs:
3535
# The job will be named after the OS and Azure will suffix the strategy to make it unique
36-
# so we'll have a job name "Windows Python 2.7" for example. What's a strategy? Strategies are the
37-
# name of the keys under the strategy.matrix scope. So for each OS we'll have "<OS> Python 2.7" and
38-
# "<OS> Python 3.7".
36+
# so we'll have a job name "Windows Python 3.9" for example. What's a strategy? Strategies are the
37+
# name of the keys under the strategy.matrix scope. So for each OS we'll have "<OS> Python 3.9" and
38+
# "<OS> Python 3.10".
3939
- job: ${{ parameters.name }}
4040
pool:
4141
vmImage: ${{ parameters.vm_image }}
@@ -68,8 +68,8 @@ jobs:
6868
versionSpec: '$(python.version)'
6969
addToPath: True
7070

71-
# Install all dependencies needed for running the tests. This command is good for
72-
# Python 2 and 3, but also for all OSes
71+
# Install all dependencies needed for running the tests. This command is good
72+
# for all OSes
7373
- script: |
7474
python -m pip install --upgrade pip setuptools wheel
7575
python -m pip install -r tests/ci_requirements.txt

shotgun_api3/shotgun.py

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import urllib.parse
5050
import urllib.request
5151
import uuid # used for attachment upload
52+
import xml.etree.ElementTree
5253

5354
# Import Error and ResponseError (even though they're unused in this file) since they need
5455
# to be exposed as part of the API.
@@ -328,7 +329,7 @@ class ClientCapabilities(object):
328329
``windows``, or ``None`` (if the current platform couldn't be determined).
329330
:ivar str local_path_field: The PTR field used for local file paths. This is calculated using
330331
the value of ``platform``. Ex. ``local_path_mac``.
331-
:ivar str py_version: Simple version of Python executable as a string. Eg. ``2.7``.
332+
:ivar str py_version: Simple version of Python executable as a string. Eg. ``3.9``.
332333
:ivar str ssl_version: Version of OpenSSL installed. Eg. ``OpenSSL 1.0.2g 1 Mar 2016``. This
333334
info is only available in Python 2.7+ if the ssl module was imported successfully.
334335
Defaults to ``unknown``
@@ -566,18 +567,6 @@ def __init__(
566567
:class:`~shotgun_api3.MissingTwoFactorAuthenticationFault` will be raised if the
567568
``auth_token`` is invalid.
568569
.. todo: Add this info to the Authentication section of the docs
569-
570-
.. note:: A note about proxy connections: If you are using Python <= v2.6.2, HTTPS
571-
connections through a proxy server will not work due to a bug in the :mod:`urllib2`
572-
library (see http://bugs.python.org/issue1424152). This will affect upload and
573-
download-related methods in the Shotgun API (eg. :meth:`~shotgun_api3.Shotgun.upload`,
574-
:meth:`~shotgun_api3.Shotgun.upload_thumbnail`,
575-
:meth:`~shotgun_api3.Shotgun.upload_filmstrip_thumbnail`,
576-
:meth:`~shotgun_api3.Shotgun.download_attachment`. Normal CRUD methods for passing JSON
577-
data should still work fine. If you cannot upgrade your Python installation, you can see
578-
the patch merged into Python v2.6.3 (http://hg.python.org/cpython/rev/0f57b30a152f/) and
579-
try and hack it into your installation but YMMV. For older versions of Python there
580-
are other patches that were proposed in the bug report that may help you as well.
581570
"""
582571

583572
# verify authentication arguments
@@ -616,13 +605,7 @@ def __init__(
616605
if script_name is not None or api_key is not None:
617606
raise ValueError("cannot provide an auth_code with script_name/api_key")
618607

619-
# Can't use 'all' with python 2.4
620-
if (
621-
len(
622-
[x for x in [session_token, script_name, api_key, login, password] if x]
623-
)
624-
== 0
625-
):
608+
if not any([session_token, script_name, api_key, login, password]):
626609
if connect:
627610
raise ValueError(
628611
"must provide login/password, session_token or script_name/api_key"
@@ -2878,8 +2861,7 @@ def download_attachment(self, attachment=False, file_path=None, attachment_id=No
28782861
This parameter exists only for backwards compatibility for scripts specifying
28792862
the parameter with keywords.
28802863
:returns: If ``file_path`` is provided, returns the path to the file on disk. If
2881-
``file_path`` is ``None``, returns the actual data of the file, as str in Python 2 or
2882-
bytes in Python 3.
2864+
``file_path`` is ``None``, returns the actual data of the file, as bytes.
28832865
:rtype: str | bytes
28842866
"""
28852867
# backwards compatibility when passed via keyword argument
@@ -2940,12 +2922,13 @@ def download_attachment(self, attachment=False, file_path=None, attachment_id=No
29402922
]
29412923

29422924
if body:
2943-
xml = "".join(body)
2944-
# Once python 2.4 support is not needed we can think about using
2945-
# elementtree. The doc is pretty small so this shouldn't be an issue.
2946-
match = re.search("<Message>(.*)</Message>", xml)
2947-
if match:
2948-
err += " - %s" % (match.group(1))
2925+
try:
2926+
root = xml.etree.ElementTree.fromstring("".join(body))
2927+
message_elem = root.find(".//Message")
2928+
if message_elem is not None and message_elem.text:
2929+
err += f" - {message_elem.text}"
2930+
except xml.etree.ElementTree.ParseError:
2931+
err += "\n%s\n" % "".join(body)
29492932
elif e.code == 409 or e.code == 410:
29502933
# we may be dealing with a file that is pending/failed a malware scan, e.g:
29512934
# 409: This file is undergoing a malware scan, please try again in a few minutes

0 commit comments

Comments
 (0)