Skip to content

Commit 4867317

Browse files
committed
Added license headers to smtp.py/imap.py and cleaned up PEP8 errors.
1 parent 74961bf commit 4867317

File tree

3 files changed

+64
-12
lines changed

3 files changed

+64
-12
lines changed

oauth2/__init__.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
The MIT License
33
4-
Copyright (c) 2007 Leah Culver, Joe Stump, Mark Paschal, Vic Fryzel
4+
Copyright (c) 2007-2010 Leah Culver, Joe Stump, Mark Paschal, Vic Fryzel
55
66
Permission is hereby granted, free of charge, to any person obtaining a copy
77
of this software and associated documentation files (the "Software"), to deal
@@ -36,7 +36,7 @@
3636
from cgi import parse_qs, parse_qsl
3737

3838

39-
VERSION = '1.0' # Hi Blaine!
39+
VERSION = '1.0' # Hi Blaine!
4040
HTTP_METHOD = 'GET'
4141
SIGNATURE_METHOD = 'PLAINTEXT'
4242

@@ -55,27 +55,29 @@ def message(self):
5555
def __str__(self):
5656
return self._message
5757

58+
5859
class MissingSignature(Error):
5960
pass
6061

62+
6163
def build_authenticate_header(realm=''):
6264
"""Optional WWW-Authenticate header (401 error)"""
6365
return {'WWW-Authenticate': 'OAuth realm="%s"' % realm}
6466

6567

6668
def build_xoauth_string(url, consumer, token=None):
6769
"""Build an XOAUTH string for use in SMTP/IMPA authentication."""
68-
request = Request.from_consumer_and_token(consumer, token,
70+
request = Request.from_consumer_and_token(consumer, token,
6971
"GET", url)
7072

7173
signing_method = SignatureMethod_HMAC_SHA1()
7274
request.sign_request(signing_method, consumer, token)
7375

7476
params = []
75-
for k,v in sorted(request.iteritems()):
77+
for k, v in sorted(request.iteritems()):
7678
if v is not None:
7779
params.append('%s="%s"' % (k, escape(v)))
78-
80+
7981
return "%s %s %s" % ("GET", url, ','.join(params))
8082

8183

@@ -130,10 +132,8 @@ def __init__(self, key, secret):
130132
raise ValueError("Key and secret must be set.")
131133

132134
def __str__(self):
133-
data = {
134-
'oauth_consumer_key': self.key,
135-
'oauth_consumer_secret': self.secret
136-
}
135+
data = {'oauth_consumer_key': self.key,
136+
'oauth_consumer_secret': self.secret}
137137

138138
return urllib.urlencode(data)
139139

@@ -232,7 +232,7 @@ def from_string(s):
232232
try:
233233
token.callback_confirmed = params['oauth_callback_confirmed'][0]
234234
except KeyError:
235-
pass # 1.0, no callback confirmed.
235+
pass # 1.0, no callback confirmed.
236236
return token
237237

238238
def __str__(self):
@@ -714,6 +714,7 @@ def sign(self, request, consumer, token):
714714
# Calculate the digest base 64.
715715
return binascii.b2a_base64(hashed.digest())[:-1]
716716

717+
717718
class SignatureMethod_PLAINTEXT(SignatureMethod):
718719

719720
name = 'PLAINTEXT'
@@ -729,4 +730,3 @@ def signing_base(self, request, consumer, token):
729730
def sign(self, request, consumer, token):
730731
key, raw = self.signing_base(request, consumer, token)
731732
return raw
732-

oauth2/clients/imap.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
1+
"""
2+
The MIT License
3+
4+
Copyright (c) 2007-2010 Leah Culver, Joe Stump, Mark Paschal, Vic Fryzel
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
"""
24+
125
import oauth2
226
import imaplib
327

28+
429
class IMAP4_SSL(imaplib.IMAP4_SSL):
30+
"""IMAP wrapper for imaplib.IMAP4_SSL that implements XOAUTH."""
31+
532
def authenticate(self, url, consumer, token):
633
if consumer is not None and not isinstance(consumer, oauth2.Consumer):
734
raise ValueError("Invalid consumer.")
@@ -11,4 +38,3 @@ def authenticate(self, url, consumer, token):
1138

1239
imaplib.IMAP4_SSL.authenticate(self, 'XOAUTH',
1340
lambda x: oauth2.build_xoauth_string(url, consumer, token))
14-

oauth2/clients/smtp.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
1+
"""
2+
The MIT License
3+
4+
Copyright (c) 2007-2010 Leah Culver, Joe Stump, Mark Paschal, Vic Fryzel
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.
23+
"""
24+
125
import oauth2
226
import smtplib
327
import base64
428

529

630
class SMTP(smtplib.SMTP):
31+
"""SMTP wrapper for smtplib.SMTP that implements XOAUTH."""
32+
733
def authenticate(self, url, consumer, token):
834
if consumer is not None and not isinstance(consumer, oauth2.Consumer):
935
raise ValueError("Invalid consumer.")

0 commit comments

Comments
 (0)