Commit bd778c5f authored by Marco Mariani's avatar Marco Mariani

use dict literals, except..as syntax

parent 504ba6e6
...@@ -448,13 +448,13 @@ class ComputerPartition(SlapRequester): ...@@ -448,13 +448,13 @@ class ComputerPartition(SlapRequester):
'message': message}) 'message': message})
def rename(self, new_name, slave_reference=None): def rename(self, new_name, slave_reference=None):
post_dict = dict( post_dict = {
computer_id=self._computer_id, 'computer_id': self._computer_id,
computer_partition_id=self.getId(), 'computer_partition_id': self.getId(),
new_name=new_name, 'new_name': new_name,
) }
if slave_reference is not None: if slave_reference:
post_dict.update(slave_reference=slave_reference) post_dict['slave_reference'] = slave_reference
self._connection_helper.POST('/softwareInstanceRename', post_dict) self._connection_helper.POST('/softwareInstanceRename', post_dict)
def getId(self): def getId(self):
...@@ -569,14 +569,14 @@ class ConnectionHelper: ...@@ -569,14 +569,14 @@ class ConnectionHelper:
return xml_marshaller.loads(xml) return xml_marshaller.loads(xml)
def connect(self): def connect(self):
connection_dict = dict( connection_dict = {
host=self.host) 'host': self.host
}
if self.key_file and self.cert_file: if self.key_file and self.cert_file:
connection_dict.update( connection_dict['key_file'] = self.key_file
key_file=self.key_file, connection_dict['cert_file'] = self.cert_file
cert_file=self.cert_file) if self.master_ca_file:
if self.master_ca_file is not None: connection_dict['ca_file'] = self.master_ca_file
connection_dict.update(ca_file=self.master_ca_file)
self.connection = self.connection_wrapper(**connection_dict) self.connection = self.connection_wrapper(**connection_dict)
def GET(self, path): def GET(self, path):
...@@ -588,14 +588,14 @@ class ConnectionHelper: ...@@ -588,14 +588,14 @@ class ConnectionHelper:
self.connection.request('GET', self.path + path) self.connection.request('GET', self.path + path)
response = self.connection.getresponse() response = self.connection.getresponse()
# If ssl error : may come from bad configuration # If ssl error : may come from bad configuration
except ssl.SSLError, e: except ssl.SSLError as exc:
if e.message == "The read operation timed out": if exc.message == 'The read operation timed out':
raise socket.error(str(e) + self.error_message_timeout) raise socket.error(str(exc) + self.error_message_timeout)
raise ssl.SSLError(str(e) + self.ssl_error_message_connect_fail) raise ssl.SSLError(str(exc) + self.ssl_error_message_connect_fail)
except socket.error, e: except socket.error as exc:
if e.message == "timed out": if exc.message == 'timed out':
raise socket.error(str(e) + self.error_message_timeout) raise socket.error(str(exc) + self.error_message_timeout)
raise socket.error(self.error_message_connect_fail + str(e)) raise socket.error(self.error_message_connect_fail + str(exc))
# check self.response.status and raise exception early # check self.response.status and raise exception early
if response.status == httplib.REQUEST_TIMEOUT: if response.status == httplib.REQUEST_TIMEOUT:
...@@ -626,10 +626,10 @@ class ConnectionHelper: ...@@ -626,10 +626,10 @@ class ConnectionHelper:
self.connection.request("POST", self.path + path, self.connection.request("POST", self.path + path,
urllib.urlencode(parameter_dict), header_dict) urllib.urlencode(parameter_dict), header_dict)
# If ssl error : must come from bad configuration # If ssl error : must come from bad configuration
except ssl.SSLError, e: except ssl.SSLError as exc:
raise ssl.SSLError(self.ssl_error_message_connect_fail + str(e)) raise ssl.SSLError(self.ssl_error_message_connect_fail + str(exc))
except socket.error, e: except socket.error as exc:
raise socket.error(self.error_message_connect_fail + str(e)) raise socket.error(self.error_message_connect_fail + str(exc))
response = self.connection.getresponse() response = self.connection.getresponse()
# check self.response.status and raise exception early # check self.response.status and raise exception early
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment