Skip to content

Commit

Permalink
Merge pull request #799 from gholms/sorted
Browse files Browse the repository at this point in the history
Use sorted(foo) instead of foo.sort() afterwards
  • Loading branch information
garnaat committed Jun 10, 2012
2 parents 68cb0b0 + 1dbdf21 commit 4e41869
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 21 deletions.
10 changes: 4 additions & 6 deletions boto/auth.py
Expand Up @@ -215,11 +215,10 @@ def canonical_headers(self, headers_to_sign):
case, sorting them in alphabetical order and then joining case, sorting them in alphabetical order and then joining
them into a string, separated by newlines. them into a string, separated by newlines.
""" """
l = ['%s:%s'%(n.lower().strip(), l = sorted(['%s:%s'%(n.lower().strip(),
headers_to_sign[n].strip()) for n in headers_to_sign] headers_to_sign[n].strip()) for n in headers_to_sign])
l.sort()
return '\n'.join(l) return '\n'.join(l)

def string_to_sign(self, http_request): def string_to_sign(self, http_request):
""" """
Return the canonical StringToSign as well as a dict Return the canonical StringToSign as well as a dict
Expand Down Expand Up @@ -349,8 +348,7 @@ def _calc_signature(self, params, verb, path, server_name):
params['SignatureMethod'] = 'HmacSHA1' params['SignatureMethod'] = 'HmacSHA1'
if self._provider.security_token: if self._provider.security_token:
params['SecurityToken'] = self._provider.security_token params['SecurityToken'] = self._provider.security_token
keys = params.keys() keys = sorted(params.keys())
keys.sort()
pairs = [] pairs = []
for key in keys: for key in keys:
val = boto.utils.get_utf8_value(params[key]) val = boto.utils.get_utf8_value(params[key])
Expand Down
8 changes: 3 additions & 5 deletions boto/ec2/connection.py
Expand Up @@ -1710,10 +1710,9 @@ def trim_snapshots(self, hourly_backups = 8, daily_backups = 7,
if temp.__contains__(t) == False: if temp.__contains__(t) == False:
temp.append(t) temp.append(t)


target_backup_times = temp # sort to make the oldest dates first, and make sure the month start
# make the oldeest dates first, and make sure the month start
# and last four week's start are in the proper order # and last four week's start are in the proper order
target_backup_times.sort() target_backup_times = sorted(temp)


# get all the snapshots, sort them by date and time, and # get all the snapshots, sort them by date and time, and
# organize them into one array for each volume: # organize them into one array for each volume:
Expand Down Expand Up @@ -2799,8 +2798,7 @@ def delete_placement_group(self, name):
# Tag methods # Tag methods


def build_tag_param_list(self, params, tags): def build_tag_param_list(self, params, tags):
keys = tags.keys() keys = sorted(tags.keys())
keys.sort()
i = 1 i = 1
for key in keys: for key in keys:
value = tags[key] value = tags[key]
Expand Down
3 changes: 1 addition & 2 deletions boto/fps/connection.py
Expand Up @@ -213,8 +213,7 @@ def cbui_url(self, **kw):


safestr = lambda x: x is not None and str(x) or '' safestr = lambda x: x is not None and str(x) or ''
safequote = lambda x: urllib.quote(safestr(x), safe='~') safequote = lambda x: urllib.quote(safestr(x), safe='~')
payload = [(k, safequote(v)) for k, v in kw.items()] payload = sorted([(k, safequote(v)) for k, v in kw.items()])
payload.sort()


encoded = lambda p: '&'.join([k + '=' + v for k, v in p]) encoded = lambda p: '&'.join([k + '=' + v for k, v in p])
canonical = '\n'.join(['GET', endpoint, base, encoded(payload)]) canonical = '\n'.join(['GET', endpoint, base, encoded(payload)])
Expand Down
3 changes: 1 addition & 2 deletions boto/sdb/connection.py
Expand Up @@ -139,8 +139,7 @@ def set_item_cls(self, cls):


def _build_name_value_list(self, params, attributes, replace=False, def _build_name_value_list(self, params, attributes, replace=False,
label='Attribute'): label='Attribute'):
keys = attributes.keys() keys = sorted(attributes.keys())
keys.sort()
i = 1 i = 1
for key in keys: for key in keys:
value = attributes[key] value = attributes[key]
Expand Down
3 changes: 1 addition & 2 deletions boto/services/result.py
Expand Up @@ -57,8 +57,7 @@ def calculate_stats(self, msg):
self.latest_time = end_time self.latest_time = end_time


def log_message(self, msg, path): def log_message(self, msg, path):
keys = msg.keys() keys = sorted(msg.keys())
keys.sort()
if not self.log_fp: if not self.log_fp:
self.log_fp = open(os.path.join(path, self.LogFileName), 'a') self.log_fp = open(os.path.join(path, self.LogFileName), 'a')
line = ','.join(keys) line = ','.join(keys)
Expand Down
3 changes: 1 addition & 2 deletions boto/utils.py
Expand Up @@ -112,8 +112,7 @@ def canonical_string(method, path, headers, expires=None,
if expires: if expires:
interesting_headers['date'] = str(expires) interesting_headers['date'] = str(expires)


sorted_header_keys = interesting_headers.keys() sorted_header_keys = sorted(interesting_headers.keys())
sorted_header_keys.sort()


buf = "%s\n" % method buf = "%s\n" % method
for key in sorted_header_keys: for key in sorted_header_keys:
Expand Down
3 changes: 1 addition & 2 deletions tests/db/test_lists.py
Expand Up @@ -66,8 +66,7 @@ def test_old_compat(self):
item.save() item.save()
time.sleep(3) time.sleep(3)
t = SimpleListModel.get_by_id(t.id) t = SimpleListModel.get_by_id(t.id)
i1 = item['strs'] i1 = sorted(item['strs'])
i1.sort()
i2 = t.strs i2 = t.strs
i2.sort() i2.sort()
assert(i1 == i2) assert(i1 == i2)
Expand Down

0 comments on commit 4e41869

Please sign in to comment.