diff options
author | Nick Tarleton <nick@quixey.com> | 2011-04-02 00:00:31 -0700 |
---|---|---|
committer | garnaat <mitch@garnaat.com> | 2011-04-02 17:48:59 -0400 |
commit | 63bf4e8a6fb61bd83ded14d3c3796d502076ef23 (patch) | |
tree | cc46b116dd24a97d785e97c9ee11271f7007219d | |
parent | 3c7d7cfd6440a458112e810e7153e50f6403e633 (diff) | |
download | boto-63bf4e8a6fb61bd83ded14d3c3796d502076ef23.tar.gz |
More Unicode fixes
-rw-r--r-- | boto/ec2/elb/loadbalancer.py | 12 | ||||
-rw-r--r-- | boto/manage/server.py | 10 | ||||
-rw-r--r-- | boto/mturk/connection.py | 4 | ||||
-rw-r--r-- | boto/rds/parametergroup.py | 10 | ||||
-rw-r--r-- | boto/sdb/db/manager/pgmanager.py | 6 | ||||
-rw-r--r-- | boto/sdb/db/manager/sdbmanager.py | 12 | ||||
-rw-r--r-- | boto/sdb/db/manager/xmlmanager.py | 10 | ||||
-rw-r--r-- | boto/sdb/db/property.py | 24 |
8 files changed, 60 insertions, 28 deletions
diff --git a/boto/ec2/elb/loadbalancer.py b/boto/ec2/elb/loadbalancer.py index 9759952e..b359ae3b 100644 --- a/boto/ec2/elb/loadbalancer.py +++ b/boto/ec2/elb/loadbalancer.py @@ -26,6 +26,10 @@ from boto.ec2.elb.policies import Policies from boto.ec2.instanceinfo import InstanceInfo from boto.resultset import ResultSet +import sys +if sys.version_info.major >= 3: + basestring = str + class LoadBalancer(object): """ Represents an EC2 Load Balancer @@ -84,7 +88,7 @@ class LoadBalancer(object): :param zones: The name of the zone(s) to add. """ - if isinstance(zones, str) or isinstance(zones, unicode): + if isinstance(zones, basestring): zones = [zones] new_zones = self.connection.enable_availability_zones(self.name, zones) self.availability_zones = new_zones @@ -97,7 +101,7 @@ class LoadBalancer(object): :param zones: The name of the zone(s) to add. """ - if isinstance(zones, str) or isinstance(zones, unicode): + if isinstance(zones, basestring): zones = [zones] new_zones = self.connection.disable_availability_zones(self.name, zones) self.availability_zones = new_zones @@ -113,7 +117,7 @@ class LoadBalancer(object): :param zones: The name of the endpoint(s) to add. """ - if isinstance(instances, str) or isinstance(instances, unicode): + if isinstance(instances, basestring): instances = [instances] new_instances = self.connection.register_instances(self.name, instances) self.instances = new_instances @@ -128,7 +132,7 @@ class LoadBalancer(object): :param zones: The name of the endpoint(s) to add. """ - if isinstance(instances, str) or isinstance(instances, unicode): + if isinstance(instances, basestring): instances = [instances] new_instances = self.connection.deregister_instances(self.name, instances) self.instances = new_instances diff --git a/boto/manage/server.py b/boto/manage/server.py index bb4f5a19..9c0d3941 100644 --- a/boto/manage/server.py +++ b/boto/manage/server.py @@ -36,6 +36,10 @@ import os, time, StringIO from contextlib import closing from boto.exception import EC2ResponseError +import sys +if sys.version_info.major >= 3: + basestring = str + InstanceTypes = ['m1.small', 'm1.large', 'm1.xlarge', 'c1.medium', 'c1.xlarge', 'm2.2xlarge', 'm2.4xlarge'] @@ -137,7 +141,7 @@ class CommandLineGetter(object): def get_region(self, params): region = params.get('region', None) - if isinstance(region, str) or isinstance(region, unicode): + if isinstance(region, basestring): region = boto.ec2.get_region(region) params['region'] = region if not region: @@ -189,7 +193,7 @@ class CommandLineGetter(object): def get_group(self, params): group = params.get('group', None) - if isinstance(group, str) or isinstance(group, unicode): + if isinstance(group, basestring): group_list = self.ec2.get_all_security_groups() for g in group_list: if g.name == group: @@ -202,7 +206,7 @@ class CommandLineGetter(object): def get_key(self, params): keypair = params.get('keypair', None) - if isinstance(keypair, str) or isinstance(keypair, unicode): + if isinstance(keypair, basestring): key_list = self.ec2.get_all_key_pairs() for k in key_list: if k.name == keypair: diff --git a/boto/mturk/connection.py b/boto/mturk/connection.py index f036d4ca..b88d3a64 100644 --- a/boto/mturk/connection.py +++ b/boto/mturk/connection.py @@ -32,6 +32,10 @@ from boto.exception import EC2ResponseError from boto.resultset import ResultSet from boto.mturk.question import QuestionForm, ExternalQuestion +import sys +if sys.version_info.major >= 3: + unicode = str + class MTurkRequestError(EC2ResponseError): "Error for MTurk Requests" # todo: subclass from an abstract parent of EC2ResponseError diff --git a/boto/rds/parametergroup.py b/boto/rds/parametergroup.py index d68c1c5f..335c28e9 100644 --- a/boto/rds/parametergroup.py +++ b/boto/rds/parametergroup.py @@ -19,6 +19,10 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. +import sys +if sys.version_info.major >= 3: + basestring = str + class ParameterGroup(dict): def __init__(self, connection=None): @@ -133,7 +137,7 @@ class Parameter(object): d[prefix+'ApplyMethod'] = self.apply_method def _set_string_value(self, value): - if not isinstance(value, str) or isinstance(value, unicode): + if not isinstance(value, basestring): raise ValueError( 'value must be of type str' ) if self.allowed_values: choices = self.allowed_values.split(',') @@ -142,7 +146,7 @@ class Parameter(object): self._value = value def _set_integer_value(self, value): - if isinstance(value, str) or isinstance(value, unicode): + if isinstance(value, basestring): value = int(value) if isinstance(value, int) or isinstance(value, long): if self.allowed_values: @@ -156,7 +160,7 @@ class Parameter(object): def _set_boolean_value(self, value): if isinstance(value, bool): self._value = value - elif isinstance(value, str) or isinstance(value, unicode): + elif isinstance(value, basestring): if value.lower() == 'true': self._value = True else: diff --git a/boto/sdb/db/manager/pgmanager.py b/boto/sdb/db/manager/pgmanager.py index 19f9eb0b..e737b2b3 100644 --- a/boto/sdb/db/manager/pgmanager.py +++ b/boto/sdb/db/manager/pgmanager.py @@ -27,6 +27,10 @@ import os import string from boto.exception import SDBPersistenceError +import sys +if sys.version_info.major >= 3: + basestring = str + psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) class PGConverter: @@ -92,7 +96,7 @@ class PGConverter: return self.decode(prop.data_type, value) def encode_reference(self, value): - if isinstance(value, str) or isinstance(value, unicode): + if isinstance(value, basestring): return value if value == None: return '' diff --git a/boto/sdb/db/manager/sdbmanager.py b/boto/sdb/db/manager/sdbmanager.py index 2bbfcb6d..ae0e6ee2 100644 --- a/boto/sdb/db/manager/sdbmanager.py +++ b/boto/sdb/db/manager/sdbmanager.py @@ -30,6 +30,10 @@ from boto.sdb.db.property import ListProperty, MapProperty from datetime import datetime, date, time from boto.exception import SDBPersistenceError +import sys +if sys.version_info.major >= 3: + basestring = str + ISO8601 = '%Y-%m-%dT%H:%M:%SZ' class TimeDecodeError(Exception): @@ -252,7 +256,7 @@ class SDBConverter(object): return float(mantissa + 'e' + exponent) def encode_datetime(self, value): - if isinstance(value, str) or isinstance(value, unicode): + if isinstance(value, basestring): return value return value.strftime(ISO8601) @@ -263,7 +267,7 @@ class SDBConverter(object): return None def encode_date(self, value): - if isinstance(value, str) or isinstance(value, unicode): + if isinstance(value, basestring): return value return value.isoformat() @@ -296,7 +300,7 @@ class SDBConverter(object): def encode_reference(self, value): if value in (None, 'None', '', ' '): return None - if isinstance(value, str) or isinstance(value, unicode): + if isinstance(value, basestring): return value else: return value.id @@ -533,7 +537,7 @@ class SDBManager(object): order_by = order_by[1:] else: order_by_method = "ASC"; - if isinstance(filters, str) or isinstance(filters, unicode): + if isinstance(filters, basestring): query = "WHERE `__type__` = '%s' AND %s" % (cls.__name__, filters) if order_by != None: query += " ORDER BY `%s` %s" % (order_by, order_by_method) diff --git a/boto/sdb/db/manager/xmlmanager.py b/boto/sdb/db/manager/xmlmanager.py index 1310602d..666eef7f 100644 --- a/boto/sdb/db/manager/xmlmanager.py +++ b/boto/sdb/db/manager/xmlmanager.py @@ -25,6 +25,10 @@ from boto.sdb.db.model import Model from datetime import datetime from xml.dom.minidom import getDOMImplementation, parse, parseString, Node +import sys +if sys.version_info.major >= 3: + basestring = str + ISO8601 = '%Y-%m-%dT%H:%M:%SZ' class XMLConverter: @@ -145,7 +149,7 @@ class XMLConverter: return None def encode_reference(self, value): - if isinstance(value, str) or isinstance(value, unicode): + if isinstance(value, basestring): return value if value == None: return '' @@ -466,7 +470,7 @@ class XMLManager(object): return doc def unmarshal_object(self, fp, cls=None, id=None): - if isinstance(fp, str) or isinstance(fp, unicode): + if isinstance(fp, basestring): doc = parseString(fp) else: doc = parse(fp) @@ -477,7 +481,7 @@ class XMLManager(object): Same as unmarshalling an object, except it returns from "get_props_from_doc" """ - if isinstance(fp, str) or isinstance(fp, unicode): + if isinstance(fp, basestring): doc = parseString(fp) else: doc = parse(fp) diff --git a/boto/sdb/db/property.py b/boto/sdb/db/property.py index abc2e458..a73fdfde 100644 --- a/boto/sdb/db/property.py +++ b/boto/sdb/db/property.py @@ -28,6 +28,10 @@ import boto import boto.s3.key from boto.sdb.db.blob import Blob +import sys +if sys.version_info.major >= 3: + basestring = str + class Property(object): data_type = str @@ -111,7 +115,7 @@ class Property(object): def validate_string(value): if value == None: return - elif isinstance(value, str) or isinstance(value, unicode): + elif isinstance(value, basestring): if len(value) > 1024: raise ValueError( 'Length of value greater than maxlength' ) else: @@ -135,7 +139,7 @@ class TextProperty(Property): self.max_length = max_length def validate(self, value): - if not isinstance(value, str) and not isinstance(value, unicode): + if not isinstance(value, basestring): raise TypeError( 'Expecting Text, got %s' % type(value) ) if self.max_length and len(value) > self.max_length: raise ValueError( 'Length of value greater than maxlength %s' % self.max_length ) @@ -421,7 +425,7 @@ class ReferenceProperty(Property): # If the value is still the UUID for the referenced object, we need to create # the object now that is the attribute has actually been accessed. This lazy # instantiation saves unnecessary roundtrips to SimpleDB - if isinstance(value, str) or isinstance(value, unicode): + if isinstance(value, basestring): value = self.reference_class(value) setattr(obj, self.name, value) return value @@ -463,7 +467,7 @@ class ReferenceProperty(Property): raise ValueError( '%s is a required property' % self.name ) if value == self.default_value(): return - if not isinstance(value, str) and not isinstance(value, unicode): + if not isinstance(value, basestring): self.check_instance(value) class _ReverseReferenceProperty(Property): @@ -550,8 +554,8 @@ class ListProperty(Property): if self.item_type in (int, long): item_type = (int, long) - elif self.item_type in (str, unicode): - item_type = (str, unicode) + elif issubclass(self.item_type, basestring): + item_type = basestring else: item_type = self.item_type @@ -574,8 +578,8 @@ class ListProperty(Property): """Override the set method to allow them to set the property to an instance of the item_type instead of requiring a list to be passed in""" if self.item_type in (int, long): item_type = (int, long) - elif self.item_type in (str, unicode): - item_type = (str, unicode) + elif issubclass(self.item_type, basestring): + item_type = basestring else: item_type = self.item_type if isinstance(value, item_type): @@ -603,8 +607,8 @@ class MapProperty(Property): if self.item_type in (int, long): item_type = (int, long) - elif self.item_type in (str, unicode): - item_type = (str, unicode) + elif issubclass(self.item_type, basestring): + item_type = basestring else: item_type = self.item_type |