Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing a reference to ParseError in ElementTree that only works in Py…

…thon 2.7.
  • Loading branch information...
commit 34783053d1f0ce90822664b52bee1a2ca3654cd8 1 parent 924095d
@garnaat garnaat authored
View
16 boto/connection.py
@@ -65,7 +65,8 @@
import boto.cacerts
from boto import config, UserAgent
-from boto.exception import AWSConnectionError, BotoClientError, BotoServerError
+from boto.exception import AWSConnectionError, BotoClientError
+from boto.exception import BotoServerError, XMLParseError
from boto.provider import Provider
from boto.resultset import ResultSet
@@ -128,7 +129,7 @@ def size(self):
ready to be returned by get().
"""
return len(self.queue)
-
+
def put(self, conn):
"""
Adds a connection to the pool, along with the time it was
@@ -210,7 +211,7 @@ class ConnectionPool(object):
#
# The amout of time between calls to clean.
#
-
+
CLEAN_INTERVAL = 5.0
#
@@ -274,7 +275,7 @@ def clean(self):
get rid of empty pools. Pools clean themselves every time a
connection is fetched; this cleaning takes care of pools that
aren't being used any more, so nothing is being gotten from
- them.
+ them.
"""
with self.mutex:
now = time.time()
@@ -454,7 +455,7 @@ def __init__(self, host, aws_access_key_id=None, aws_secret_access_key=None,
self.protocol = 'http'
self.host = host
self.path = path
- # if the value passed in for debug
+ # if the value passed in for debug
if not isinstance(debug, (int, long)):
debug = 0
self.debug = config.getint('Boto', 'debug', debug)
@@ -838,11 +839,12 @@ def _credentials_expired(self, response):
if response.status != 403:
return False
try:
- for event, node in ElementTree.iterparse(response, events=['start']):
+ for event, node in ElementTree.iterparse(response,
+ events=['start']):
if node.tag.endswith('Code'):
if node.text == 'ExpiredToken':
return True
- except ElementTree.ParseError:
+ except XMLParseError:
return False
return False
View
10 boto/exception.py
@@ -16,7 +16,7 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
@@ -29,6 +29,12 @@
from boto import handler
from boto.resultset import ResultSet
+try:
+ from xml.etree.ElementTree import ParseError as XMLParseError
+except ImportError:
+ # In python2.6/5, xml.etree.ElementTree.ParseError does not exist.
+ from xml.parsers.expat import ExpatError as XMLParseError
+
class BotoClientError(StandardError):
"""
@@ -455,7 +461,7 @@ class ResumableTransferDisposition(object):
ABORT_CUR_PROCESS = 'ABORT_CUR_PROCESS'
# ABORT means the resumable transfer failed in a way that it does not
- # make sense to continue in the current process, and further that the
+ # make sense to continue in the current process, and further that the
# current tracker ID should not be preserved (in a tracker file if one
# was specified at resumable upload start time). If the user tries again
# later (e.g., a separate run of gsutil) it will get a new resumable
View
6 boto/route53/connection.py
@@ -28,6 +28,7 @@
import boto
from boto.connection import AWSAuthConnection
+from boto.exception import XMLParseError
from boto import handler
from boto.resultset import ResultSet
import boto.jsonresponse
@@ -71,11 +72,12 @@ def _credentials_expired(self, response):
if response.status != 403:
return False
try:
- for event, node in ElementTree.iterparse(response, events=['start']):
+ for event, node in ElementTree.iterparse(response,
+ events=['start']):
if node.tag.endswith('Code'):
if node.text == 'InvalidClientTokenId':
return True
- except ElementTree.ParseError:
+ except XMLParseError:
return False
return False
View
7 boto/s3/connection.py
@@ -32,7 +32,7 @@
from boto.s3.bucket import Bucket
from boto.s3.key import Key
from boto.resultset import ResultSet
-from boto.exception import BotoClientError
+from boto.exception import BotoClientError, XMLParseError
def check_lowercase_bucketname(n):
@@ -176,11 +176,12 @@ def _credentials_expired(self, response):
if response.status != 400:
return False
try:
- for event, node in ElementTree.iterparse(response, events=['start']):
+ for event, node in ElementTree.iterparse(response,
+ events=['start']):
if node.tag.endswith('Code'):
if node.text == 'ExpiredToken':
return True
- except ElementTree.ParseError:
+ except XMLParseError:
return False
return False
View
35 boto/sqs/connection.py
@@ -14,7 +14,7 @@
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
-# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
@@ -26,7 +26,7 @@
from boto.sqs.message import Message
from boto.sqs.attributes import Attributes
from boto.sqs.batchresults import BatchResults
-from boto.exception import SQSError
+from boto.exception import SQSError, XMLParseError
class SQSConnection(AWSQueryConnection):
@@ -64,11 +64,12 @@ def _credentials_expired(self, response):
if response.status != 401:
return False
try:
- for event, node in ElementTree.iterparse(response, events=['start']):
+ for event, node in ElementTree.iterparse(response,
+ events=['start']):
if node.tag.endswith('Code'):
if node.text == 'InvalidAccessKeyId':
return True
- except ElementTree.ParseError:
+ except XMLParseError:
return False
return False
@@ -108,7 +109,7 @@ def delete_queue(self, queue, force_deletion=False):
:type queue: A Queue object
:param queue: The SQS queue to be deleted
-
+
:type force_deletion: Boolean
:param force_deletion: Normally, SQS will not delete a queue
that contains messages. However, if the force_deletion
@@ -116,7 +117,7 @@ def delete_queue(self, queue, force_deletion=False):
whether there are messages in the queue or not. USE WITH
CAUTION. This will delete all messages in the queue as
well.
-
+
:rtype: bool
:return: True if the command succeeded, False otherwise
"""
@@ -125,7 +126,7 @@ def delete_queue(self, queue, force_deletion=False):
def get_queue_attributes(self, queue, attribute='All'):
"""
Gets one or all attributes of a Queue
-
+
:type queue: A Queue object
:param queue: The SQS queue to be deleted
@@ -140,7 +141,7 @@ def get_queue_attributes(self, queue, attribute='All'):
* CreatedTimestamp|
* LastModifiedTimestamp|
* Policy
-
+
:rtype: :class:`boto.sqs.attributes.Attributes`
:return: An Attributes object containing request value(s).
"""
@@ -159,11 +160,11 @@ def receive_message(self, queue, number_messages=1,
:type queue: A Queue object
:param queue: The Queue from which messages are read.
-
+
:type number_messages: int
:param number_messages: The maximum number of messages to read
(default=1)
-
+
:type visibility_timeout: int
:param visibility_timeout: The number of seconds the message should
remain invisible to other queue readers
@@ -179,7 +180,7 @@ def receive_message(self, queue, number_messages=1,
* SentTimestamp
* ApproximateReceiveCount
* ApproximateFirstReceiveTimestamp
-
+
:rtype: list
:return: A list of :class:`boto.sqs.message.Message` objects.
"""
@@ -198,10 +199,10 @@ def delete_message(self, queue, message):
:type queue: A :class:`boto.sqs.queue.Queue` object
:param queue: The Queue from which messages are read.
-
+
:type message: A :class:`boto.sqs.message.Message` object
:param message: The Message to be deleted
-
+
:rtype: bool
:return: True if successful, False otherwise.
"""
@@ -234,10 +235,10 @@ def delete_message_from_handle(self, queue, receipt_handle):
:type queue: A :class:`boto.sqs.queue.Queue` object
:param queue: The Queue from which messages are read.
-
+
:type receipt_handle: str
:param receipt_handle: The receipt handle for the message
-
+
:rtype: bool
:return: True if successful, False otherwise.
"""
@@ -287,11 +288,11 @@ def change_message_visibility(self, queue, receipt_handle,
:type queue: A :class:`boto.sqs.queue.Queue` object
:param queue: The Queue from which messages are read.
-
+
:type receipt_handle: str
:param queue: The receipt handle associated with the message whose
visibility timeout will be changed.
-
+
:type visibility_timeout: int
:param visibility_timeout: The new value of the message's visibility
timeout in seconds.
Please sign in to comment.
Something went wrong with that request. Please try again.