Skip to content

Commit

Permalink
Fixing a reference to ParseError in ElementTree that only works in Py…
Browse files Browse the repository at this point in the history
…thon 2.7.
  • Loading branch information
garnaat committed Jun 13, 2012
1 parent 924095d commit 3478305
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 31 deletions.
16 changes: 9 additions & 7 deletions boto/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -210,7 +211,7 @@ class ConnectionPool(object):
#
# The amout of time between calls to clean.
#

CLEAN_INTERVAL = 5.0

#
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions boto/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions boto/route53/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions boto/s3/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down
35 changes: 18 additions & 17 deletions boto/sqs/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -108,15 +109,15 @@ 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
argument is True, the queue will be deleted regardless of
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
"""
Expand All @@ -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
Expand All @@ -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).
"""
Expand All @@ -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
Expand All @@ -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.
"""
Expand All @@ -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.
"""
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 3478305

Please sign in to comment.