Merge lp:~oubiwann/txaws/413741-pep8-cleanup into lp:~txawsteam/txaws/trunk

Proposed by Duncan McGreggor
Status: Merged
Merged at revision: not available
Proposed branch: lp:~oubiwann/txaws/413741-pep8-cleanup
Merge into: lp:~txawsteam/txaws/trunk
Diff against target: None lines
To merge this branch: bzr merge lp:~oubiwann/txaws/413741-pep8-cleanup
Reviewer Review Type Date Requested Status
Original txAWS Team Pending
Review via email: mp+10204@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Duncan McGreggor (oubiwann) wrote :

I'd like to merge this small fix-up branch to trunk. Could I get some reviews?

Thanks!

d

Revision history for this message
Robert Collins (lifeless) wrote :

review +1

I don't really like this bit though;

#comment
#comment
"""Docstring"""

I find it _much_ easier to read visually as

#comment
#comment

"""Docstring"""

-- comments are not classes or functions :)

Revision history for this message
Duncan McGreggor (oubiwann) wrote :

On Sun, Aug 16, 2009 at 6:51 PM, Robert
Collins<email address hidden> wrote:
> review +1
>
> I don't really like this bit though;
>
> #comment
> #comment
> """Docstring"""
>
> I find it _much_ easier to read visually as
>
> #comment
> #comment
>
> """Docstring"""
>
> -- comments are not classes or functions :)

Cool -- I have no problem with that :-) I'll put it back.

d

7. By Duncan McGreggor <email address hidden>

Added new lines between comments, docstrings, and imports at the top of files
(lifeless 1).

Revision history for this message
Duncan McGreggor (oubiwann) wrote :

Robert's review point has been addressed.

Since there's not a lot of activity in this team, how about we merge with one +1. Once we have more people and contributions, maybe we can bump that up...

Revision history for this message
Robert Collins (lifeless) wrote :

On Tue, 2009-08-18 at 18:20 +0000, Duncan McGreggor wrote:
> Robert's review point has been addressed.
>
> Since there's not a lot of activity in this team, how about we merge with one +1. Once we have more people and contributions, maybe we can bump that up...

I think 2 review-capable people agreeing is sufficient - that is the
author and a reviewer, or for non team contributions, two team members.

-Rob

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/aws-status'
--- bin/aws-status 2009-04-26 08:32:36 +0000
+++ bin/aws-status 2009-08-15 03:28:45 +0000
@@ -1,8 +1,9 @@
1#!/usr/bin/env python1#!/usr/bin/env python
2# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>2# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
3# Licenced under the txaws licence available at /LICENSE in the txaws source.3# Licenced under the txaws licence available at /LICENSE in the txaws source.
4
5import sys4import sys
6from txaws.client.gui.gtk import main5from txaws.client.gui.gtk import main
6
7
7sys.exit(main(sys.argv))8sys.exit(main(sys.argv))
89
910
=== modified file 'txaws/client/gui/gtk.py'
--- txaws/client/gui/gtk.py 2009-05-08 13:18:59 +0000
+++ txaws/client/gui/gtk.py 2009-08-15 03:28:45 +0000
@@ -1,18 +1,19 @@
1# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>1# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
2# Licenced under the txaws licence available at /LICENSE in the txaws source.2# Licenced under the txaws licence available at /LICENSE in the txaws source.
3
4"""A GTK client for working with aws."""3"""A GTK client for working with aws."""
54
6from __future__ import absolute_import5from __future__ import absolute_import
76
8__all__ = ['main']
9
10import gnomekeyring7import gnomekeyring
11import gobject8import gobject
12import gtk9import gtk
1310
14from txaws.credentials import AWSCredentials11from txaws.credentials import AWSCredentials
1512
13
14__all__ = ['main']
15
16
16class AWSStatusIcon(gtk.StatusIcon):17class AWSStatusIcon(gtk.StatusIcon):
17 """A status icon shown when instances are running."""18 """A status icon shown when instances are running."""
1819
@@ -49,7 +50,8 @@
49 self.manager = gtk.UIManager()50 self.manager = gtk.UIManager()
50 self.manager.insert_action_group(ag, 0)51 self.manager.insert_action_group(ag, 0)
51 self.manager.add_ui_from_string(menu)52 self.manager.add_ui_from_string(menu)
52 self.menu = self.manager.get_widget('/Menubar/Menu/Stop instances').props.parent53 self.menu = self.manager.get_widget(
54 '/Menubar/Menu/Stop instances').props.parent
53 self.connect('popup-menu', self.on_popup_menu)55 self.connect('popup-menu', self.on_popup_menu)
5456
55 def create_client(self, creds):57 def create_client(self, creds):
@@ -79,7 +81,8 @@
79 return AWSCredentials(access_key=key_id, secret_key=secret_key)81 return AWSCredentials(access_key=key_id, secret_key=secret_key)
8082
81 def show_a_password_dialog(self):83 def show_a_password_dialog(self):
82 self.password_dialog = gtk.Dialog("Enter your AWS credentals", None, gtk.DIALOG_MODAL,84 self.password_dialog = gtk.Dialog(
85 "Enter your AWS credentals", None, gtk.DIALOG_MODAL,
83 (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,86 (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT,
84 gtk.STOCK_CANCEL,87 gtk.STOCK_CANCEL,
85 gtk.RESPONSE_REJECT))88 gtk.RESPONSE_REJECT))
@@ -109,7 +112,8 @@
109 # credentials.112 # credentials.
110 return113 return
111 self.probing = True114 self.probing = True
112 self.client.describe_instances().addCallbacks(self.showhide, self.describe_error)115 d = self.client.describe_instances()
116 d.addCallbacks(self.showhide, self.describe_error)
113117
114 def on_popup_menu(self, status, button, time):118 def on_popup_menu(self, status, button, time):
115 self.menu.popup(None, None, None, button, time)119 self.menu.popup(None, None, None, button, time)
116120
=== modified file 'txaws/credentials.py'
--- txaws/credentials.py 2009-04-27 08:53:11 +0000
+++ txaws/credentials.py 2009-08-15 03:28:45 +0000
@@ -1,14 +1,15 @@
1# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>1# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
2# Licenced under the txaws licence available at /LICENSE in the txaws source.2# Licenced under the txaws licence available at /LICENSE in the txaws source.
3
4"""Credentials for accessing AWS services."""3"""Credentials for accessing AWS services."""
54
6__all__ = ['AWSCredentials']
7
8import os5import os
96
10from txaws.util import *7from txaws.util import *
118
9
10__all__ = ['AWSCredentials']
11
12
12class AWSCredentials(object):13class AWSCredentials(object):
1314
14 def __init__(self, access_key=None, secret_key=None):15 def __init__(self, access_key=None, secret_key=None):
1516
=== modified file 'txaws/ec2/client.py'
--- txaws/ec2/client.py 2009-04-28 11:52:57 +0000
+++ txaws/ec2/client.py 2009-08-15 03:28:45 +0000
@@ -1,10 +1,6 @@
1# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>1# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
2# Licenced under the txaws licence available at /LICENSE in the txaws source.2# Licenced under the txaws licence available at /LICENSE in the txaws source.
3
4"""EC2 client support."""3"""EC2 client support."""
5
6__all__ = ['EC2Client']
7
8from base64 import b64encode4from base64 import b64encode
9from urllib import quote5from urllib import quote
106
@@ -14,13 +10,15 @@
14from txaws.util import iso8601time, XML10from txaws.util import iso8601time, XML
1511
1612
13__all__ = ['EC2Client']
14
15
17class Instance(object):16class Instance(object):
18 """An Amazon EC2 Instance.17 """An Amazon EC2 Instance.
1918
20 :attrib instanceId: The instance ID of this instance.19 @attrib instanceId: The instance ID of this instance.
21 :attrib instanceState: The state of this instance.20 @attrib instanceState: The state of this instance.
22 """21 """
23
24 def __init__(self, instanceId, instanceState):22 def __init__(self, instanceId, instanceState):
25 self.instanceId = instanceId23 self.instanceId = instanceId
26 self.instanceState = instanceState24 self.instanceState = instanceState
@@ -34,7 +32,7 @@
34 def __init__(self, creds=None, query_factory=None):32 def __init__(self, creds=None, query_factory=None):
35 """Create an EC2Client.33 """Create an EC2Client.
3634
37 :param creds: Explicit credentials to use. If None, credentials are35 @param creds: Explicit credentials to use. If None, credentials are
38 inferred as per txaws.credentials.AWSCredentials.36 inferred as per txaws.credentials.AWSCredentials.
39 """37 """
40 if creds is None:38 if creds is None:
@@ -67,8 +65,8 @@
67 def terminate_instances(self, *instance_ids):65 def terminate_instances(self, *instance_ids):
68 """Terminate some instances.66 """Terminate some instances.
69 67
70 :param instance_ids: The ids of the instances to terminate.68 @param instance_ids: The ids of the instances to terminate.
71 :return: A deferred which on success gives an iterable of69 @return: A deferred which on success gives an iterable of
72 (id, old-state, new-state) tuples.70 (id, old-state, new-state) tuples.
73 """71 """
74 instanceset = {}72 instanceset = {}
7573
=== modified file 'txaws/ec2/tests/test_client.py'
--- txaws/ec2/tests/test_client.py 2009-04-28 11:52:57 +0000
+++ txaws/ec2/tests/test_client.py 2009-08-15 03:28:45 +0000
@@ -1,6 +1,5 @@
1# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>1# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
2# Licenced under the txaws licence available at /LICENSE in the txaws source.2# Licenced under the txaws licence available at /LICENSE in the txaws source.
3
4import os3import os
54
6from twisted.internet.defer import succeed5from twisted.internet.defer import succeed
@@ -9,6 +8,7 @@
9from txaws.ec2 import client8from txaws.ec2 import client
10from txaws.tests import TXAWSTestCase9from txaws.tests import TXAWSTestCase
1110
11
12sample_describe_instances_result = """<?xml version="1.0"?>12sample_describe_instances_result = """<?xml version="1.0"?>
13<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2008-12-01/">13<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2008-12-01/">
14 <requestId>52b4c730-f29f-498d-94c1-91efb75994cc</requestId>14 <requestId>52b4c730-f29f-498d-94c1-91efb75994cc</requestId>
@@ -49,6 +49,7 @@
49</DescribeInstancesResponse>49</DescribeInstancesResponse>
50"""50"""
5151
52
52sample_terminate_instances_result = """<?xml version="1.0"?>53sample_terminate_instances_result = """<?xml version="1.0"?>
53<TerminateInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2008-12-01/">54<TerminateInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2008-12-01/">
54 <instancesSet>55 <instancesSet>
5556
=== modified file 'txaws/storage/client.py'
--- txaws/storage/client.py 2009-04-27 08:53:11 +0000
+++ txaws/storage/client.py 2009-08-15 03:28:45 +0000
@@ -6,8 +6,6 @@
6Various API-incompatible changes are planned in order to expose missing6Various API-incompatible changes are planned in order to expose missing
7functionality in this wrapper.7functionality in this wrapper.
8"""8"""
9
10
11from hashlib import md59from hashlib import md5
12from base64 import b64encode10from base64 import b64encode
1311
@@ -64,7 +62,8 @@
6462
65 if self.creds is not None:63 if self.creds is not None:
66 signature = self.getSignature(headers)64 signature = self.getSignature(headers)
67 headers['Authorization'] = 'AWS %s:%s' % (self.creds.access_key, signature)65 headers['Authorization'] = 'AWS %s:%s' % (
66 self.creds.access_key, signature)
6867
69 return headers68 return headers
7069
@@ -73,7 +72,8 @@
7372
74 def getCanonicalizedAmzHeaders(self, headers):73 def getCanonicalizedAmzHeaders(self, headers):
75 result = ''74 result = ''
76 headers = [(name.lower(), value) for name, value in headers.iteritems() if name.lower().startswith('x-amz-')]75 headers = [(name.lower(), value) for name, value in headers.iteritems()
76 if name.lower().startswith('x-amz-')]
77 headers.sort()77 headers.sort()
78 return ''.join('%s:%s\n' % (name, value) for name, value in headers)78 return ''.join('%s:%s\n' % (name, value) for name, value in headers)
7979
@@ -87,7 +87,9 @@
87 return self.creds.sign(text)87 return self.creds.sign(text)
8888
89 def submit(self):89 def submit(self):
90 return self.getPage(url=self.getURI(), method=self.verb, postdata=self.data, headers=self.getHeaders())90 return self.getPage(
91 url=self.getURI(), method=self.verb, postdata=self.data,
92 headers=self.getHeaders())
9193
92 def getPage(self, *a, **kw):94 def getPage(self, *a, **kw):
93 return getPage(*a, **kw)95 return getPage(*a, **kw)
@@ -95,6 +97,7 @@
9597
96NS = '{http://s3.amazonaws.com/doc/2006-03-01/}'98NS = '{http://s3.amazonaws.com/doc/2006-03-01/}'
9799
100
98class S3(object):101class S3(object):
99 rootURI = 'https://s3.amazonaws.com/'102 rootURI = 'https://s3.amazonaws.com/'
100 requestFactory = S3Request103 requestFactory = S3Request
@@ -117,8 +120,11 @@
117 """120 """
118 root = XML(response)121 root = XML(response)
119 for bucket in root.find(NS + 'Buckets'):122 for bucket in root.find(NS + 'Buckets'):
120 yield {'name': bucket.findtext(NS + 'Name'),123 timeText = bucket.findtext(NS + 'CreationDate')
121 'created': Time.fromISO8601TimeAndDate(bucket.findtext(NS + 'CreationDate'))}124 yield {
125 'name': bucket.findtext(NS + 'Name'),
126 'created': Time.fromISO8601TimeAndDate(timeText),
127 }
122128
123 def listBuckets(self):129 def listBuckets(self):
124 """130 """
@@ -127,7 +133,9 @@
127 Returns a list of all the buckets owned by the authenticated sender of133 Returns a list of all the buckets owned by the authenticated sender of
128 the request.134 the request.
129 """135 """
130 return self.makeRequest('GET').submit().addCallback(self._parseBucketList)136 d = self.makeRequest('GET').submit()
137 d.addCallback(self._parseBucketList)
138 return d
131139
132 def createBucket(self, bucket):140 def createBucket(self, bucket):
133 """141 """
@@ -143,13 +151,15 @@
143 """151 """
144 return self.makeRequest('DELETE', bucket).submit()152 return self.makeRequest('DELETE', bucket).submit()
145153
146 def putObject(self, bucket, objectName, data, contentType=None, metadata={}):154 def putObject(self, bucket, objectName, data, contentType=None,
155 metadata={}):
147 """156 """
148 Put an object in a bucket.157 Put an object in a bucket.
149158
150 Any existing object of the same name will be replaced.159 Any existing object of the same name will be replaced.
151 """160 """
152 return self.makeRequest('PUT', bucket, objectName, data, contentType, metadata).submit()161 return self.makeRequest(
162 'PUT', bucket, objectName, data, contentType, metadata).submit()
153163
154 def getObject(self, bucket, objectName):164 def getObject(self, bucket, objectName):
155 """165 """
156166
=== modified file 'txaws/storage/test/test_client.py'
--- txaws/storage/test/test_client.py 2009-04-26 08:32:36 +0000
+++ txaws/storage/test/test_client.py 2009-08-15 03:28:45 +0000
@@ -8,6 +8,7 @@
8from txaws.tests import TXAWSTestCase8from txaws.tests import TXAWSTestCase
9from txaws.storage.client import S3, S3Request, calculateMD59from txaws.storage.client import S3, S3Request, calculateMD5
1010
11
11class StubbedS3Request(S3Request):12class StubbedS3Request(S3Request):
12 def getPage(self, url, method, postdata, headers):13 def getPage(self, url, method, postdata, headers):
13 self.getPageArgs = (url, method, postdata, headers)14 self.getPageArgs = (url, method, postdata, headers)
@@ -25,9 +26,13 @@
25 DATA = 'objectData'26 DATA = 'objectData'
26 DIGEST = 'zhdB6gwvocWv/ourYUWMxA=='27 DIGEST = 'zhdB6gwvocWv/ourYUWMxA=='
2728
28 request = S3Request('PUT', 'somebucket', 'object/name/here', DATA, contentType='text/plain', metadata={'foo': 'bar'})29 request = S3Request(
30 'PUT', 'somebucket', 'object/name/here', DATA,
31 contentType='text/plain', metadata={'foo': 'bar'})
29 self.assertEqual(request.verb, 'PUT')32 self.assertEqual(request.verb, 'PUT')
30 self.assertEqual(request.getURI(), 'https://s3.amazonaws.com/somebucket/object/name/here')33 self.assertEqual(
34 request.getURI(),
35 'https://s3.amazonaws.com/somebucket/object/name/here')
31 headers = request.getHeaders()36 headers = request.getHeaders()
32 self.assertNotEqual(headers.pop('Date'), '')37 self.assertNotEqual(headers.pop('Date'), '')
33 self.assertEqual(headers,38 self.assertEqual(headers,
@@ -45,7 +50,8 @@
4550
46 request = S3Request('GET', 'somebucket')51 request = S3Request('GET', 'somebucket')
47 self.assertEqual(request.verb, 'GET')52 self.assertEqual(request.verb, 'GET')
48 self.assertEqual(request.getURI(), 'https://s3.amazonaws.com/somebucket')53 self.assertEqual(
54 request.getURI(), 'https://s3.amazonaws.com/somebucket')
49 headers = request.getHeaders()55 headers = request.getHeaders()
50 self.assertNotEqual(headers.pop('Date'), '')56 self.assertNotEqual(headers.pop('Date'), '')
51 self.assertEqual(headers,57 self.assertEqual(headers,
@@ -75,7 +81,9 @@
75 req.date = 'Wed, 28 Mar 2007 01:29:59 +0000'81 req.date = 'Wed, 28 Mar 2007 01:29:59 +0000'
7682
77 headers = req.getHeaders()83 headers = req.getHeaders()
78 self.assertEqual(headers['Authorization'], 'AWS 0PN5J17HBGZHT7JJ3X82:jF7L3z/FTV47vagZzhKupJ9oNig=')84 self.assertEqual(
85 headers['Authorization'],
86 'AWS 0PN5J17HBGZHT7JJ3X82:jF7L3z/FTV47vagZzhKupJ9oNig=')
7987
8088
81class InertRequest(S3Request):89class InertRequest(S3Request):
@@ -140,7 +148,8 @@
140148
141 def setUp(self):149 def setUp(self):
142 TXAWSTestCase.setUp(self)150 TXAWSTestCase.setUp(self)
143 self.creds = AWSCredentials(access_key='accessKey', secret_key='secretKey')151 self.creds = AWSCredentials(
152 access_key='accessKey', secret_key='secretKey')
144 self.s3 = TestableS3(creds=self.creds)153 self.s3 = TestableS3(creds=self.creds)
145154
146 def test_makeRequest(self):155 def test_makeRequest(self):
@@ -167,11 +176,14 @@
167 self.assertEqual(req.objectName, None)176 self.assertEqual(req.objectName, None)
168177
169 def _checkResult(buckets):178 def _checkResult(buckets):
170 self.assertEqual(list(buckets),179 self.assertEqual(
171 [{'name': u'quotes',180 list(buckets),
172 'created': Time.fromDatetime(datetime(2006, 2, 3, 16, 45, 9))},181 [{'name': u'quotes',
173 {'name': u'samples',182 'created': Time.fromDatetime(
174 'created': Time.fromDatetime(datetime(2006, 2, 3, 16, 41, 58))}])183 datetime(2006, 2, 3, 16, 45, 9))},
184 {'name': u'samples',
185 'created': Time.fromDatetime(
186 datetime(2006, 2, 3, 16, 41, 58))}])
175 return d.addCallback(_checkResult)187 return d.addCallback(_checkResult)
176188
177 def test_createBucket(self):189 def test_createBucket(self):
@@ -191,7 +203,8 @@
191 self.assertEqual(req.objectName, None)203 self.assertEqual(req.objectName, None)
192204
193 def test_putObject(self):205 def test_putObject(self):
194 self.s3.putObject('foobucket', 'foo', 'data', 'text/plain', {'foo': 'bar'})206 self.s3.putObject(
207 'foobucket', 'foo', 'data', 'text/plain', {'foo': 'bar'})
195 req = self.s3._lastRequest208 req = self.s3._lastRequest
196 self.assertTrue(req.submitted)209 self.assertTrue(req.submitted)
197 self.assertEqual(req.verb, 'PUT')210 self.assertEqual(req.verb, 'PUT')
198211
=== modified file 'txaws/tests/__init__.py'
--- txaws/tests/__init__.py 2009-04-27 08:53:11 +0000
+++ txaws/tests/__init__.py 2009-08-15 03:28:45 +0000
@@ -2,6 +2,7 @@
22
3from twisted.trial.unittest import TestCase3from twisted.trial.unittest import TestCase
44
5
5class TXAWSTestCase(TestCase):6class TXAWSTestCase(TestCase):
6 """Support for isolation of txaws tests."""7 """Support for isolation of txaws tests."""
78
89
=== modified file 'txaws/tests/test_credentials.py'
--- txaws/tests/test_credentials.py 2009-04-27 14:15:48 +0000
+++ txaws/tests/test_credentials.py 2009-08-15 03:28:45 +0000
@@ -1,6 +1,5 @@
1# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>1# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
2# Licenced under the txaws licence available at /LICENSE in the txaws source.2# Licenced under the txaws licence available at /LICENSE in the txaws source.
3
4import os3import os
54
6from twisted.trial.unittest import TestCase5from twisted.trial.unittest import TestCase
76
=== modified file 'txaws/tests/test_util.py'
--- txaws/tests/test_util.py 2009-04-27 08:53:11 +0000
+++ txaws/tests/test_util.py 2009-08-15 03:28:45 +0000
@@ -2,6 +2,7 @@
22
3from txaws.util import *3from txaws.util import *
44
5
5class MiscellaneousTests(TestCase):6class MiscellaneousTests(TestCase):
67
7 def test_hmac_sha1(self):8 def test_hmac_sha1(self):
89
=== modified file 'txaws/util.py'
--- txaws/util.py 2009-04-27 08:53:11 +0000
+++ txaws/util.py 2009-08-15 03:28:45 +0000
@@ -3,19 +3,21 @@
3New things in this module should be of relevance to more than one of amazon's3New things in this module should be of relevance to more than one of amazon's
4services.4services.
5"""5"""
6
7__all__ = ['hmac_sha1', 'iso8601time']
8
9from base64 import b64encode6from base64 import b64encode
10from hashlib import sha17from hashlib import sha1
11import hmac8import hmac
12import time9import time
10
13# Import XML from somwhere; here in one place to prevent duplication.11# Import XML from somwhere; here in one place to prevent duplication.
14try:12try:
15 from xml.etree.ElementTree import XML13 from xml.etree.ElementTree import XML
16except ImportError:14except ImportError:
17 from elementtree.ElementTree import XML15 from elementtree.ElementTree import XML
1816
17
18__all__ = ['hmac_sha1', 'iso8601time']
19
20
19def hmac_sha1(secret, data):21def hmac_sha1(secret, data):
20 digest = hmac.new(secret, data, sha1).digest()22 digest = hmac.new(secret, data, sha1).digest()
21 return b64encode(digest)23 return b64encode(digest)

Subscribers

People subscribed via source and target branches