Skip to content

Commit

Permalink
PEP8 fixes for setup.py and examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
martey committed Feb 6, 2012
1 parent d719c6d commit 0180cba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
4 changes: 3 additions & 1 deletion examples/appengine/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from google.appengine.ext.webapp import template
from google.appengine.api.urlfetch import fetch


class User(db.Model):
id = db.StringProperty(required=True)
created = db.DateTimeProperty(auto_now_add=True)
Expand Down Expand Up @@ -82,11 +83,12 @@ def get(self):
self.response.out.write(template.render(path, args))

def post(self):
url=self.request.get('url')
url = self.request.get('url')
file = urllib2.urlopen(url)
graph = facebook.GraphAPI(self.current_user.access_token)
graph.put_photo(file, "Test Image")


def main():
logging.getLogger().setLevel(logging.DEBUG)
util.run_wsgi_app(webapp.WSGIApplication([(r"/", HomeHandler)]))
Expand Down
15 changes: 10 additions & 5 deletions examples/oauth/facebookoauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def get(self):
class LoginHandler(BaseHandler):
def get(self):
verification_code = self.request.get("code")
args = dict(client_id=FACEBOOK_APP_ID, redirect_uri=self.request.path_url)
args = dict(client_id=FACEBOOK_APP_ID,
redirect_uri=self.request.path_url)
if self.request.get("code"):
args["client_secret"] = FACEBOOK_APP_SECRET
args["code"] = self.request.get("code")
Expand Down Expand Up @@ -121,7 +122,8 @@ def set_cookie(response, name, value, domain=None, path="/", expires=None):
cookie = Cookie.BaseCookie()
cookie[name] = "|".join([value, timestamp, signature])
cookie[name]["path"] = path
if domain: cookie[name]["domain"] = domain
if domain:
cookie[name]["domain"] = domain
if expires:
cookie[name]["expires"] = email.utils.formatdate(
expires, localtime=False, usegmt=True)
Expand All @@ -130,9 +132,11 @@ def set_cookie(response, name, value, domain=None, path="/", expires=None):

def parse_cookie(value):
"""Parses and verifies a cookie value from set_cookie"""
if not value: return None
if not value:
return None
parts = value.split("|")
if len(parts) != 3: return None
if len(parts) != 3:
return None
if cookie_signature(parts[0], parts[1]) != parts[2]:
logging.warning("Invalid cookie signature %r", value)
return None
Expand All @@ -153,7 +157,8 @@ def cookie_signature(*parts):
people using this example don't accidentally all use the same secret).
"""
hash = hmac.new(FACEBOOK_APP_SECRET, digestmod=hashlib.sha1)
for part in parts: hash.update(part)
for part in parts:
hash.update(part)
return hash.hexdigest()


Expand Down
3 changes: 2 additions & 1 deletion examples/tornado/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def get_current_user(self):
cookies = dict((n, self.cookies[n].value) for n in self.cookies.keys())
cookie = facebook.get_user_from_cookie(
cookies, options.facebook_app_id, options.facebook_app_secret)
if not cookie: return None
if not cookie:
return None
user = self.db.get(
"SELECT * FROM users WHERE id = %s", cookie["uid"])
if not user:
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env python
from distutils.core import setup

setup(
name='facebook-sdk',
version='0.2.0',
description='This client library is designed to support the Facebook Graph API and the official Facebook JavaScript SDK, which is the canonical way to implement Facebook authentication.',
description='This client library is designed to support the Facebook '
'Graph API and the official Facebook JavaScript SDK, which '
'is the canonical way to implement Facebook authentication.',
author='Facebook',
url='http://github.com/pythonforfacebook/facebook-sdk',
py_modules=[
'facebook',
],
)

0 comments on commit 0180cba

Please sign in to comment.