|
49 | 49 | import urllib.parse
|
50 | 50 | import urllib.request
|
51 | 51 | import uuid # used for attachment upload
|
| 52 | +import xml.etree.ElementTree |
52 | 53 |
|
53 | 54 | # Import Error and ResponseError (even though they're unused in this file) since they need
|
54 | 55 | # to be exposed as part of the API.
|
@@ -328,7 +329,7 @@ class ClientCapabilities(object):
|
328 | 329 | ``windows``, or ``None`` (if the current platform couldn't be determined).
|
329 | 330 | :ivar str local_path_field: The PTR field used for local file paths. This is calculated using
|
330 | 331 | 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``. |
332 | 333 | :ivar str ssl_version: Version of OpenSSL installed. Eg. ``OpenSSL 1.0.2g 1 Mar 2016``. This
|
333 | 334 | info is only available in Python 2.7+ if the ssl module was imported successfully.
|
334 | 335 | Defaults to ``unknown``
|
@@ -566,18 +567,6 @@ def __init__(
|
566 | 567 | :class:`~shotgun_api3.MissingTwoFactorAuthenticationFault` will be raised if the
|
567 | 568 | ``auth_token`` is invalid.
|
568 | 569 | .. 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. |
581 | 570 | """
|
582 | 571 |
|
583 | 572 | # verify authentication arguments
|
@@ -616,13 +605,7 @@ def __init__(
|
616 | 605 | if script_name is not None or api_key is not None:
|
617 | 606 | raise ValueError("cannot provide an auth_code with script_name/api_key")
|
618 | 607 |
|
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]): |
626 | 609 | if connect:
|
627 | 610 | raise ValueError(
|
628 | 611 | "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
|
2878 | 2861 | This parameter exists only for backwards compatibility for scripts specifying
|
2879 | 2862 | the parameter with keywords.
|
2880 | 2863 | :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. |
2883 | 2865 | :rtype: str | bytes
|
2884 | 2866 | """
|
2885 | 2867 | # backwards compatibility when passed via keyword argument
|
@@ -2940,12 +2922,13 @@ def download_attachment(self, attachment=False, file_path=None, attachment_id=No
|
2940 | 2922 | ]
|
2941 | 2923 |
|
2942 | 2924 | 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) |
2949 | 2932 | elif e.code == 409 or e.code == 410:
|
2950 | 2933 | # we may be dealing with a file that is pending/failed a malware scan, e.g:
|
2951 | 2934 | # 409: This file is undergoing a malware scan, please try again in a few minutes
|
|
0 commit comments