Permalink
Browse files

Resolved merge conflict and a bit more PEP8 cleanup.

  • Loading branch information...
2 parents d409c0c + b55feff commit 761e5a081a142f65383ab7e835dd4bfd9d7dcc25 @garnaat garnaat committed Jun 11, 2012
View
2 boto/manage/cmdshell.py
@@ -173,7 +173,7 @@ def exists(self, path):
return os.path.exists(path)
def shell(self):
- raise NotImplementedError, 'shell not supported with LocalClient'
+ raise NotImplementedError('shell not supported with LocalClient')
def run(self):
boto.log.info('running:%s' % self.command)
View
6 boto/manage/server.py
@@ -489,19 +489,19 @@ def put(self):
def delete(self):
if self.production:
- raise ValueError, "Can't delete a production server"
+ raise ValueError("Can't delete a production server")
#self.stop()
Model.delete(self)
def stop(self):
if self.production:
- raise ValueError, "Can't delete a production server"
+ raise ValueError("Can't delete a production server")
if self._instance:
self._instance.stop()
def terminate(self):
if self.production:
- raise ValueError, "Can't delete a production server"
+ raise ValueError("Can't delete a production server")
if self._instance:
self._instance.terminate()
View
8 boto/manage/volume.py
@@ -219,7 +219,7 @@ def detach(self, force=False):
def checkfs(self, use_cmd=None):
if self.server == None:
- raise ValueError, 'server attribute must be set to run this command'
+ raise ValueError('server attribute must be set to run this command')
# detemine state of file system on volume, only works if attached
if use_cmd:
cmd = use_cmd
@@ -234,7 +234,7 @@ def checkfs(self, use_cmd=None):
def wait(self):
if self.server == None:
- raise ValueError, 'server attribute must be set to run this command'
+ raise ValueError('server attribute must be set to run this command')
with closing(self.server.get_cmdshell()) as cmd:
# wait for the volume device to appear
cmd = self.server.get_cmdshell()
@@ -244,7 +244,7 @@ def wait(self):
def format(self):
if self.server == None:
- raise ValueError, 'server attribute must be set to run this command'
+ raise ValueError('server attribute must be set to run this command')
status = None
with closing(self.server.get_cmdshell()) as cmd:
if not self.checkfs(cmd):
@@ -254,7 +254,7 @@ def format(self):
def mount(self):
if self.server == None:
- raise ValueError, 'server attribute must be set to run this command'
+ raise ValueError('server attribute must be set to run this command')
boto.log.info('handle_mount_point')
with closing(self.server.get_cmdshell()) as cmd:
cmd = self.server.get_cmdshell()
View
14 boto/rds/parametergroup.py
@@ -134,11 +134,11 @@ def merge(self, d, i):
def _set_string_value(self, value):
if not isinstance(value, str) or isinstance(value, unicode):
- raise ValueError, 'value must be of type str'
+ raise ValueError('value must be of type str')
if self.allowed_values:
choices = self.allowed_values.split(',')
if value not in choices:
- raise ValueError, 'value must be in %s' % self.allowed_values
+ raise ValueError('value must be in %s' % self.allowed_values)
self._value = value
def _set_integer_value(self, value):
@@ -148,10 +148,10 @@ def _set_integer_value(self, value):
if self.allowed_values:
min, max = self.allowed_values.split('-')
if value < int(min) or value > int(max):
- raise ValueError, 'range is %s' % self.allowed_values
+ raise ValueError('range is %s' % self.allowed_values)
self._value = value
else:
- raise ValueError, 'value must be integer'
+ raise ValueError('value must be integer')
def _set_boolean_value(self, value):
if isinstance(value, bool):
@@ -162,7 +162,7 @@ def _set_boolean_value(self, value):
else:
self._value = False
else:
- raise ValueError, 'value must be boolean'
+ raise ValueError('value must be boolean')
def set_value(self, value):
if self.type == 'string':
@@ -172,7 +172,7 @@ def set_value(self, value):
elif self.type == 'boolean':
self._set_boolean_value(value)
else:
- raise TypeError, 'unknown type (%s)' % self.type
+ raise TypeError('unknown type (%s)' % self.type)
def get_value(self):
if self._value == None:
@@ -188,7 +188,7 @@ def get_value(self):
self._set_boolean_value(self._value)
return self._value
else:
- raise TypeError, 'unknown type (%s)' % self.type
+ raise TypeError('unknown type (%s)' % self.type)
value = property(get_value, set_value, 'The value of the parameter')
View
2 boto/roboto/awsqueryrequest.py
@@ -223,7 +223,7 @@ def process_filters(self):
filter_names = [f['name'] for f in self.Filters]
unknown_filters = [f for f in filters if f not in filter_names]
if unknown_filters:
- raise FilterError, 'Unknown filters: %s' % unknown_filters
+ raise FilterError('Unknown filters: %s' % unknown_filters)
for i, filter in enumerate(self.Filters):
name = filter['name']
if name in filters:
View
8 boto/sdb/db/key.py
@@ -23,7 +23,7 @@ class Key(object):
@classmethod
def from_path(cls, *args, **kwds):
- raise NotImplementedError, "Paths are not currently supported"
+ raise NotImplementedError("Paths are not currently supported")
def __init__(self, encoded=None, obj=None):
self.name = None
@@ -35,7 +35,7 @@ def __init__(self, encoded=None, obj=None):
self.kind = None
def app(self):
- raise NotImplementedError, "Applications are not currently supported"
+ raise NotImplementedError("Applications are not currently supported")
def kind(self):
return self.kind
@@ -44,7 +44,7 @@ def id(self):
return self.id
def name(self):
- raise NotImplementedError, "Key Names are not currently supported"
+ raise NotImplementedError("Key Names are not currently supported")
def id_or_name(self):
return self.id
@@ -53,7 +53,7 @@ def has_id_or_name(self):
return self.id != None
def parent(self):
- raise NotImplementedError, "Key parents are not currently supported"
+ raise NotImplementedError("Key parents are not currently supported")
def __str__(self):
return self.id_or_name()
View
2 boto/sdb/db/manager/__init__.py
@@ -87,5 +87,5 @@ def get_manager(cls):
return XMLManager(cls, db_name, db_user, db_passwd,
db_host, db_port, db_table, sql_dir, enable_ssl)
else:
- raise ValueError, 'Unknown db_type: %s' % db_type
+ raise ValueError('Unknown db_type: %s' % db_type)
View
8 boto/sdb/db/manager/pgmanager.py
@@ -105,7 +105,7 @@ def decode_reference(self, value):
try:
return self.manager.get_object_from_id(value)
except:
- raise ValueError, 'Unable to convert %s to Object' % value
+ raise ValueError('Unable to convert %s to Object' % value)
class PGManager(object):
@@ -296,9 +296,9 @@ def lookup(self, cls, name, value):
row = self.cursor.fetchone()
return self._object_from_row(row, self.cursor.description)
elif self.cursor.rowcount == 0:
- raise KeyError, 'Object not found'
+ raise KeyError('Object not found')
else:
- raise LookupError, 'Multiple Objects Found'
+ raise LookupError('Multiple Objects Found')
def query(self, cls, filters, limit=None, order_by=None):
parts = []
@@ -333,7 +333,7 @@ def get_property(self, prop, obj, name):
if prop.name == name:
v = self.decode_value(prop, rs[0])
return v
- raise AttributeError, '%s not found' % name
+ raise AttributeError('%s not found' % name)
def set_property(self, prop, obj, name, value):
pass
View
6 boto/sdb/db/manager/sdbmanager.py
@@ -106,7 +106,7 @@ def encode_map(self, prop, value):
if value == None:
return None
if not isinstance(value, dict):
- raise ValueError, 'Expected a dict value, got %s' % type(value)
+ raise ValueError('Expected a dict value, got %s' % type(value))
new_value = []
for key in value:
item_type = getattr(prop, "item_type")
@@ -647,7 +647,7 @@ def _get_all_decendents(self, cls):
return decendents
def query_gql(self, query_string, *args, **kwds):
- raise NotImplementedError, "GQL queries not supported in SimpleDB"
+ raise NotImplementedError("GQL queries not supported in SimpleDB")
def save_object(self, obj, expected_value=None):
if not obj.id:
@@ -713,7 +713,7 @@ def get_property(self, prop, obj, name):
value = prop.make_value_from_datastore(value)
setattr(obj, prop.name, value)
return value
- raise AttributeError, '%s not found' % name
+ raise AttributeError('%s not found' % name)
def set_key_value(self, obj, name, value):
self.domain.put_attributes(obj.id, {name: value}, replace=True)
View
2 boto/sdb/db/manager/xmlmanager.py
@@ -395,7 +395,7 @@ def _build_query(self, cls, filters, limit, order_by):
return ' intersection '.join(parts)
def query_gql(self, query_string, *args, **kwds):
- raise NotImplementedError, "GQL queries not supported in XML"
+ raise NotImplementedError("GQL queries not supported in XML")
def save_list(self, doc, items, prop_node):
items_node = doc.createElement('items')
View
4 boto/sdb/db/model.py
@@ -86,7 +86,7 @@ def get_by_id(cls, ids=None, parent=None):
@classmethod
def get_by_key_name(cls, key_names, parent=None):
- raise NotImplementedError, "Key Names are not currently supported"
+ raise NotImplementedError("Key Names are not currently supported")
@classmethod
def find(cls, limit=None, next_token=None, **params):
@@ -101,7 +101,7 @@ def all(cls, limit=None, next_token=None):
@classmethod
def get_or_insert(key_name, **kw):
- raise NotImplementedError, "get_or_insert not currently supported"
+ raise NotImplementedError("get_or_insert not currently supported")
@classmethod
def properties(cls, hidden=True):
View
141 boto/sdb/db/property.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.
@@ -28,15 +28,16 @@
import boto.s3.key
from boto.sdb.db.blob import Blob
+
class Property(object):
data_type = str
type_name = ''
name = ''
verbose_name = ''
- def __init__(self, verbose_name=None, name=None, default=None, required=False,
- validator=None, choices=None, unique=False):
+ def __init__(self, verbose_name=None, name=None, default=None,
+ required=False, validator=None, choices=None, unique=False):
self.verbose_name = verbose_name
self.name = name
self.default = default
@@ -48,7 +49,7 @@ def __init__(self, verbose_name=None, name=None, default=None, required=False,
else:
self.slot_name = '_'
self.unique = unique
-
+
def __get__(self, obj, objtype):
if obj:
obj.load()
@@ -78,16 +79,16 @@ def default_validator(self, value):
if isinstance(value, basestring) or value == self.default_value():
return
if not isinstance(value, self.data_type):
- raise TypeError, 'Validation Error, %s.%s expecting %s, got %s' % (self.model_class.__name__, self.name, self.data_type, type(value))
-
+ raise TypeError('Validation Error, %s.%s expecting %s, got %s' % (self.model_class.__name__, self.name, self.data_type, type(value)))
+
def default_value(self):
return self.default
def validate(self, value):
- if self.required and value==None:
- raise ValueError, '%s is a required property' % self.name
+ if self.required and value == None:
+ raise ValueError('%s is a required property' % self.name)
if self.choices and value and not value in self.choices:
- raise ValueError, '%s not a valid choice for %s.%s' % (value, self.model_class.__name__, self.name)
+ raise ValueError('%s not a valid choice for %s.%s' % (value, self.model_class.__name__, self.name))
if self.validator:
self.validator(value)
else:
@@ -108,38 +109,46 @@ def get_choices(self):
return self.choices()
return self.choices
+
def validate_string(value):
if value == None:
return
elif isinstance(value, str) or isinstance(value, unicode):
if len(value) > 1024:
- raise ValueError, 'Length of value greater than maxlength'
+ raise ValueError('Length of value greater than maxlength')
else:
- raise TypeError, 'Expecting String, got %s' % type(value)
+ raise TypeError('Expecting String, got %s' % type(value))
+
class StringProperty(Property):
type_name = 'String'
-
- def __init__(self, verbose_name=None, name=None, default='', required=False,
- validator=validate_string, choices=None, unique=False):
- Property.__init__(self, verbose_name, name, default, required, validator, choices, unique)
+
+ def __init__(self, verbose_name=None, name=None, default='',
+ required=False, validator=validate_string,
+ choices=None, unique=False):
+ Property.__init__(self, verbose_name, name, default, required,
+ validator, choices, unique)
+
class TextProperty(Property):
-
+
type_name = 'Text'
-
- def __init__(self, verbose_name=None, name=None, default='', required=False,
- validator=None, choices=None, unique=False, max_length=None):
- Property.__init__(self, verbose_name, name, default, required, validator, choices, unique)
+
+ def __init__(self, verbose_name=None, name=None, default='',
+ required=False, validator=None, choices=None,
+ unique=False, max_length=None):
+ Property.__init__(self, verbose_name, name, default, required,
+ validator, choices, unique)
self.max_length = max_length
def validate(self, value):
value = super(TextProperty, self).validate(value)
if not isinstance(value, str) and not isinstance(value, unicode):
- raise TypeError, 'Expecting Text, got %s' % type(value)
+ 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
+ raise ValueError('Length of value greater than maxlength %s' % self.max_length)
+
class PasswordProperty(StringProperty):
"""
@@ -153,7 +162,7 @@ class PasswordProperty(StringProperty):
The comparison
- obj.password == 'foo'
+ obj.password == 'foo'
generates a hash of 'foo' and compares it to the
stored hash.
@@ -164,7 +173,7 @@ class PasswordProperty(StringProperty):
where sha512 is not available )
It's unlikely you'll ever need to use a different hash
- function, but if you do, you can control the behavior
+ function, but if you do, you can control the behavior
in one of two ways:
1) Specifying hashfunc in PasswordProperty constructor
@@ -175,7 +184,7 @@ class MyModel(model):
password = PasswordProperty(hashfunc=hashlib.sha224)
2) Subclassing Password and PasswordProperty
-
+
class SHA224Password(Password):
hashfunc=hashlib.sha224
@@ -198,9 +207,9 @@ def __init__(self, verbose_name=None, name=None, default='', required=False,
The remaining parameters are passed through to StringProperty.__init__"""
-
- StringProperty.__init__(self, verbose_name, name, default, required, validator, choices, unique)
- self.hashfunc=hashfunc
+ StringProperty.__init__(self, verbose_name, name, default, required,
+ validator, choices, unique)
+ self.hashfunc = hashfunc
def make_value_from_datastore(self, value):
p = self.data_type(value, hashfunc=self.hashfunc)
@@ -227,9 +236,10 @@ def validate(self, value):
value = Property.validate(self, value)
if isinstance(value, self.data_type):
if len(value) > 1024:
- raise ValueError, 'Length of value greater than maxlength'
+ raise ValueError('Length of value greater than maxlength')
else:
- raise TypeError, 'Expecting %s, got %s' % (type(self.data_type), type(value))
+ raise TypeError('Expecting %s, got %s' % (type(self.data_type), type(value)))
+
class BlobProperty(Property):
data_type = Blob
@@ -246,8 +256,9 @@ def __set__(self, obj, value):
value = b
Property.__set__(self, obj, value)
+
class S3KeyProperty(Property):
-
+
data_type = boto.s3.key.Key
type_name = 'S3Key'
validate_regex = "^s3:\/\/([^\/]*)\/(.*)$"
@@ -266,7 +277,7 @@ def validate(self, value):
match = re.match(self.validate_regex, value)
if match:
return
- raise TypeError, 'Validation Error, expecting %s, got %s' % (self.data_type, type(value))
+ raise TypeError('Validation Error, expecting %s, got %s' % (self.data_type, type(value)))
def __get__(self, obj, objtype):
value = Property.__get__(self, obj, objtype)
@@ -284,14 +295,15 @@ def __get__(self, obj, objtype):
return k
else:
return value
-
+
def get_value_for_datastore(self, model_instance):
value = Property.get_value_for_datastore(self, model_instance)
if value:
return "s3://%s/%s" % (value.bucket.name, value.name)
else:
return None
+
class IntegerProperty(Property):
data_type = int
@@ -307,11 +319,11 @@ def validate(self, value):
value = int(value)
value = Property.validate(self, value)
if value > self.max:
- raise ValueError, 'Maximum value is %d' % self.max
+ raise ValueError('Maximum value is %d' % self.max)
if value < self.min:
- raise ValueError, 'Minimum value is %d' % self.min
+ raise ValueError('Minimum value is %d' % self.min)
return value
-
+
def empty(self, value):
return value is None
@@ -321,7 +333,6 @@ def __set__(self, obj, value):
return Property.__set__(self, obj, value)
-
class LongProperty(Property):
data_type = long
@@ -337,14 +348,15 @@ def validate(self, value):
min = -9223372036854775808
max = 9223372036854775807
if value > max:
- raise ValueError, 'Maximum value is %d' % max
+ raise ValueError('Maximum value is %d' % max)
if value < min:
- raise ValueError, 'Minimum value is %d' % min
+ raise ValueError('Minimum value is %d' % min)
return value
-
+
def empty(self, value):
return value is None
+
class BooleanProperty(Property):
data_type = bool
@@ -356,7 +368,8 @@ def __init__(self, verbose_name=None, name=None, default=False, required=False,
def empty(self, value):
return value is None
-
+
+
class FloatProperty(Property):
data_type = float
@@ -370,10 +383,11 @@ def validate(self, value):
value = float(value)
value = Property.validate(self, value)
return value
-
+
def empty(self, value):
return value is None
+
class DateTimeProperty(Property):
"""This class handles both the datetime.datetime object
And the datetime.date objects. It can return either one,
@@ -408,6 +422,7 @@ def get_value_for_datastore(self, model_instance):
def now(self):
return datetime.datetime.utcnow()
+
class DateProperty(Property):
data_type = datetime.date
@@ -429,7 +444,7 @@ def validate(self, value):
if value == None:
return
if not isinstance(value, self.data_type):
- raise TypeError, 'Validation Error, expecting %s, got %s' % (self.data_type, type(value))
+ raise TypeError('Validation Error, expecting %s, got %s' % (self.data_type, type(value)))
def get_value_for_datastore(self, model_instance):
if self.auto_now:
@@ -456,7 +471,7 @@ def validate(self, value):
if value is None:
return
if not isinstance(value, self.data_type):
- raise TypeError, 'Validation Error, expecting %s, got %s' % (self.data_type, type(value))
+ raise TypeError('Validation Error, expecting %s, got %s' % (self.data_type, type(value)))
class ReferenceProperty(Property):
@@ -469,7 +484,7 @@ def __init__(self, reference_class=None, collection_name=None,
Property.__init__(self, verbose_name, name, default, required, validator, choices, unique)
self.reference_class = reference_class
self.collection_name = collection_name
-
+
def __get__(self, obj, objtype):
if obj:
value = getattr(obj, self.slot_name)
@@ -487,15 +502,15 @@ def __set__(self, obj, value):
"""Don't allow this object to be associated to itself
This causes bad things to happen"""
if value != None and (obj.id == value or (hasattr(value, "id") and obj.id == value.id)):
- raise ValueError, "Can not associate an object with itself!"
+ raise ValueError("Can not associate an object with itself!")
return super(ReferenceProperty, self).__set__(obj, value)
def __property_config__(self, model_class, property_name):
Property.__property_config__(self, model_class, property_name)
if self.collection_name is None:
self.collection_name = '%s_%s_set' % (model_class.__name__.lower(), self.name)
if hasattr(self.reference_class, self.collection_name):
- raise ValueError, 'duplicate property: %s' % self.collection_name
+ raise ValueError('duplicate property: %s' % self.collection_name)
setattr(self.reference_class, self.collection_name,
_ReverseReferenceProperty(model_class, property_name, self.collection_name))
@@ -511,20 +526,21 @@ def check_instance(self, value):
cls_lineage = self.reference_class.get_lineage()
if obj_lineage.startswith(cls_lineage):
return
- raise TypeError, '%s not instance of %s' % (obj_lineage, cls_lineage)
+ raise TypeError('%s not instance of %s' % (obj_lineage, cls_lineage))
except:
- raise ValueError, '%s is not a Model' % value
-
+ raise ValueError('%s is not a Model' % value)
+
def validate(self, value):
if self.validator:
self.validator(value)
- if self.required and value==None:
- raise ValueError, '%s is a required property' % self.name
+ if self.required and value == None:
+ 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):
self.check_instance(value)
-
+
+
class _ReverseReferenceProperty(Property):
data_type = Query
type_name = 'query'
@@ -552,9 +568,9 @@ def __get__(self, model_instance, model_class):
def __set__(self, model_instance, value):
"""Not possible to set a new collection."""
- raise ValueError, 'Virtual property is read-only'
+ raise ValueError('Virtual property is read-only')
+
-
class CalculatedProperty(Property):
def __init__(self, verbose_name=None, name=None, default=None,
@@ -564,7 +580,7 @@ def __init__(self, verbose_name=None, name=None, default=None,
validator, choices, unique)
self.calculated_type = calculated_type
self.use_method = use_method
-
+
def __get__(self, obj, objtype):
value = self.default_value()
if obj:
@@ -591,8 +607,9 @@ def get_value_for_datastore(self, model_instance):
else:
return None
+
class ListProperty(Property):
-
+
data_type = list
type_name = 'List'
@@ -619,7 +636,7 @@ def validate(self, value):
for item in value:
if not isinstance(item, item_type):
if item_type == (int, long):
- raise ValueError, 'Items in the %s list must all be integers.' % self.name
+ raise ValueError('Items in the %s list must all be integers.' % self.name)
else:
raise ValueError('Items in the %s list must all be %s instances' %
(self.name, self.item_type.__name__))
@@ -641,13 +658,13 @@ def __set__(self, obj, value):
item_type = self.item_type
if isinstance(value, item_type):
value = [value]
- elif value == None: # Override to allow them to set this to "None" to remove everything
+ elif value == None: # Override to allow them to set this to "None" to remove everything
value = []
return super(ListProperty, self).__set__(obj, value)
class MapProperty(Property):
-
+
data_type = dict
type_name = 'Map'
@@ -661,7 +678,7 @@ def validate(self, value):
value = super(MapProperty, self).validate(value)
if value is not None:
if not isinstance(value, dict):
- raise ValueError, 'Value must of type dict'
+ raise ValueError('Value must of type dict')
if self.item_type in (int, long):
item_type = (int, long)
@@ -673,7 +690,7 @@ def validate(self, value):
for key in value:
if not isinstance(value[key], item_type):
if item_type == (int, long):
- raise ValueError, 'Values in the %s Map must all be integers.' % self.name
+ raise ValueError('Values in the %s Map must all be integers.' % self.name)
else:
raise ValueError('Values in the %s Map must all be %s instances' %
(self.name, self.item_type.__name__))
View
2 boto/sdb/db/sequence.py
@@ -171,7 +171,7 @@ def set(self, val):
self.timestamp = new_val['timestamp']
except SDBResponseError, e:
if e.status == 409:
- raise ValueError, "Sequence out of sync"
+ raise ValueError("Sequence out of sync")
else:
raise

0 comments on commit 761e5a0

Please sign in to comment.