[Kimchi-devel] [PATCH] typo: named the first KeyError exception data from item to key

Aline Manera alinefm at linux.vnet.ibm.com
Wed Feb 26 02:15:33 UTC 2014


On 02/25/2014 11:05 PM, shaohef at linux.vnet.ibm.com wrote:
> From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
>
> Python raises a KeyError whenever a dict() object is requested (using
> the format a = adict[key]) and the key is not in the dictionary.
>
> for example:
> In [1]: dog_owned_by = {'Peter': 'Furry', 'Sally': 'Fluffy'}
>
> In [2]: dog_owned_by['NoExist']
> KeyError: 'NoExist'
>
> The first argument is the exception type, and then the first data follow
> it it, and it is the missing 'key'.
>
> Now in the code we use 'item'.  This may be confused.
> 'item' usually means (key, value) pairs of a dict.
>
> change it to 'key'.
>
> Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
> ---
>   src/kimchi/mockmodel.py            | 8 ++++----
>   src/kimchi/model/storagepools.py   | 4 ++--
>   src/kimchi/model/storagevolumes.py | 4 ++--
>   src/kimchi/root.py                 | 4 ++--
>   4 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
> index b23a024..52d06fd 100644
> --- a/src/kimchi/mockmodel.py
> +++ b/src/kimchi/mockmodel.py
> @@ -365,9 +365,9 @@ class MockModel(object):
>                   pool.info['autostart'] = True
>               else:
>                   pool.info['autostart'] = False
> -        except KeyError, item:
> +        except KeyError, key:
>               raise MissingParameter("KCHPOOL0004E",
> -                                   {'item': str(item), 'name': name})
> +                                   {'key': str(key), 'name': name})

As you are changing the keys expected in the message KCHPOOL0004E you 
also need to update the message itself

"Specify %(item)s in order to create the storage pool %(name)s"

It is expecting an "item" and now you are passing "key"

You need to update the message properly

"Specify %(key)s in order to create the storage pool %(name)s"

It also applies to all changes below.


>
>           if name in self._mock_storagepools or name in (ISO_POOL_NAME,):
>               raise InvalidOperation("KCHPOOL0001E", {'name': name})
> @@ -426,9 +426,9 @@ class MockModel(object):
>               volume.info['format'] = params['format']
>               volume.info['path'] = os.path.join(
>                   pool.info['path'], name)
> -        except KeyError, item:
> +        except KeyError, key:
>               raise MissingParameter("KCHVOL0004E",
> -                                   {'item': str(item), 'volume': name})
> +                                   {'key': str(key), 'volume': name})
>
>           if name in pool._volumes:
>               raise InvalidOperation("KCHVOL0001E", {'name': name})
> diff --git a/src/kimchi/model/storagepools.py b/src/kimchi/model/storagepools.py
> index 011feb0..78bc334 100644
> --- a/src/kimchi/model/storagepools.py
> +++ b/src/kimchi/model/storagepools.py
> @@ -88,9 +88,9 @@ class StoragePoolsModel(object):
>               poolDef = StoragePoolDef.create(params)
>               poolDef.prepare(conn)
>               xml = poolDef.xml.encode("utf-8")
> -        except KeyError, item:
> +        except KeyError, key:
>               raise MissingParameter("KCHPOOL0004E",
> -                                   {'item': str(item), 'name': name})
> +                                   {'key': str(key), 'name': name})
>
>           if name in self.get_list():
>               raise InvalidOperation("KCHPOOL0001E", {'name': name})
> diff --git a/src/kimchi/model/storagevolumes.py b/src/kimchi/model/storagevolumes.py
> index 6bd6ded..135e2ef 100644
> --- a/src/kimchi/model/storagevolumes.py
> +++ b/src/kimchi/model/storagevolumes.py
> @@ -61,8 +61,8 @@ class StorageVolumesModel(object):
>           try:
>               pool = StoragePoolModel.get_storagepool(pool, self.conn)
>               xml = vol_xml % params
> -        except KeyError, item:
> -            raise MissingParameter("KCHVOL0004E", {'item': str(item),
> +        except KeyError, key:
> +            raise MissingParameter("KCHVOL0004E", {'key': str(key),
>                                                      'volume': name})
>
>           try:
> diff --git a/src/kimchi/root.py b/src/kimchi/root.py
> index 08056d2..601f834 100644
> --- a/src/kimchi/root.py
> +++ b/src/kimchi/root.py
> @@ -105,8 +105,8 @@ class KimchiRoot(Root):
>           try:
>               userid = params['userid']
>               password = params['password']
> -        except KeyError, item:
> -            e = MissingParameter('KCHAUTH0003E', {'item': str(item)})
> +        except KeyError, key:
> +            e = MissingParameter('KCHAUTH0003E', {'key': str(key)})
>               raise cherrypy.HTTPError(400, e.message)
>
>           try:




More information about the Kimchi-devel mailing list