Skip to content

Sourcery refactored master branch #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions appengine/flexible/django_cloudsql/mysite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@
# Locally, you can use the CloudSQL proxy to proxy a localhost connection
# to the instance
DATABASES['default']['HOST'] = '/cloudsql/<your-cloudsql-connection-string>'
if os.getenv('GAE_INSTANCE'):
pass
else:
if not os.getenv('GAE_INSTANCE'):
DATABASES['default']['HOST'] = '127.0.0.1'
# [END dbconfig]

Expand Down
9 changes: 4 additions & 5 deletions appengine/standard/app_identity/signing/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ def verify_signed_by_app(data, signature):
for the application."""
public_certificates = app_identity.get_public_certificates()

for cert in public_certificates:
if verify_signature(data, signature, cert.x509_certificate_pem):
return True

return False
return any(
verify_signature(data, signature, cert.x509_certificate_pem)
for cert in public_certificates
)


class MainPage(webapp2.RequestHandler):
Expand Down
24 changes: 12 additions & 12 deletions appengine/standard/channel/chatactoe.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ def check_win(self):
return

def make_move(self, position, user):
if (position >= 0 and user == self.game.userX or
user == self.game.userO):
if self.game.moveX == (user == self.game.userX):
boardList = list(self.game.board)
if (boardList[position] == ' '):
boardList[position] = 'X' if self.game.moveX else 'O'
self.game.board = "".join(boardList)
self.game.moveX = not self.game.moveX
self.check_win()
self.game.put()
self.send_update()
return
if (
(position >= 0 and user == self.game.userX or user == self.game.userO)
) and self.game.moveX == (user == self.game.userX):
boardList = list(self.game.board)
if (boardList[position] == ' '):
boardList[position] = 'X' if self.game.moveX else 'O'
self.game.board = "".join(boardList)
self.game.moveX = not self.game.moveX
self.check_win()
self.game.put()
self.send_update()
return
# [END validate_message_3]


Expand Down
31 changes: 10 additions & 21 deletions appengine/standard/cloudsql/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,20 @@


def connect_to_cloudsql():
# When deployed to App Engine, the `SERVER_SOFTWARE` environment variable
# will be set to 'Google App Engine/version'.
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
# Connect using the unix socket located at
# /cloudsql/cloudsql-connection-name.
cloudsql_unix_socket = os.path.join(
'/cloudsql', CLOUDSQL_CONNECTION_NAME)

db = MySQLdb.connect(
if not os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
return MySQLdb.connect(
host='127.0.0.1', user=CLOUDSQL_USER, passwd=CLOUDSQL_PASSWORD)

# Connect using the unix socket located at
# /cloudsql/cloudsql-connection-name.
cloudsql_unix_socket = os.path.join(
'/cloudsql', CLOUDSQL_CONNECTION_NAME)

return MySQLdb.connect(
unix_socket=cloudsql_unix_socket,
user=CLOUDSQL_USER,
passwd=CLOUDSQL_PASSWORD)

# If the unix socket is unavailable, then try to connect using TCP. This
# will work if you're running a local MySQL server or using the Cloud SQL
# proxy, for example:
#
# $ cloud_sql_proxy -instances=your-connection-name=tcp:3306
#
else:
db = MySQLdb.connect(
host='127.0.0.1', user=CLOUDSQL_USER, passwd=CLOUDSQL_PASSWORD)

return db


class MainPage(webapp2.RequestHandler):
def get(self):
Expand Down
9 changes: 2 additions & 7 deletions appengine/standard/firebase/firenotes/backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,11 @@ def query_database(user_id):
query = Note.query(ancestor=ancestor_key).order(-Note.created)
notes = query.fetch()

note_messages = []

for note in notes:
note_messages.append({
return [{
'friendly_id': note.friendly_id,
'message': note.message,
'created': note.created
})

return note_messages
} for note in notes]
# [END query_database]


Expand Down
5 changes: 2 additions & 3 deletions appengine/standard/memcache/snippets/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ def get_data():
data = memcache.get('key')
if data is not None:
return data
else:
data = query_for_data()
memcache.add('key', data, 60)
data = query_for_data()
memcache.add('key', data, 60)
return data
# [END get_data]

Expand Down
2 changes: 1 addition & 1 deletion appengine/standard/ndb/cache/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

def test_set_in_process_cache_policy(testbed):
def policy(key):
return 1 == 1
return True

snippets.set_in_process_cache_policy(policy)
assert policy == ndb.get_context().get_cache_policy()
Expand Down
32 changes: 11 additions & 21 deletions appengine/standard/ndb/entities/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ class Account(ndb.Model):


def create_entity_using_keyword_arguments():
sandy = Account(
return Account(
username='Sandy', userid=123, email='sandy@example.com')
return sandy


def create_entity_using_attributes():
Expand All @@ -45,23 +44,20 @@ def create_entity_using_populate():


def demonstrate_model_constructor_type_checking():
bad = Account(
username='Sandy', userid='not integer') # raises an exception
return bad
return Account(
username='Sandy', userid='not integer')


def demonstrate_entity_attribute_type_checking(sandy):
sandy.username = 42 # raises an exception


def save_entity(sandy):
sandy_key = sandy.put()
return sandy_key
return sandy.put()


def get_entity(sandy_key):
sandy = sandy_key.get()
return sandy
return sandy_key.get()


def get_key_kind_and_id(sandy_key):
Expand All @@ -71,14 +67,12 @@ def get_key_kind_and_id(sandy_key):


def get_url_safe_key(sandy_key):
url_string = sandy_key.urlsafe()
return url_string
return sandy_key.urlsafe()


def get_entity_from_url_safe_key(url_string):
sandy_key = ndb.Key(urlsafe=url_string)
sandy = sandy_key.get()
return sandy
return sandy_key.get()


def get_key_and_numeric_id_from_url_safe_key(url_string):
Expand Down Expand Up @@ -145,8 +139,7 @@ def equivalent_ways_to_define_key_with_parent():


def create_root_key():
sandy_key = ndb.Key(Account, 'sandy@example.com')
return sandy_key
return ndb.Key(Account, 'sandy@example.com')


def create_entity_with_parent_keys():
Expand All @@ -168,8 +161,7 @@ def create_entity_with_parent_keys():


def get_parent_key_of_entity(initial_revision):
message_key = initial_revision.key.parent()
return message_key
return initial_revision.key.parent()


def operate_on_multiple_keys_at_once(list_of_entities):
Expand Down Expand Up @@ -207,8 +199,7 @@ class FlexEmployee(ndb.Expando):


def create_expando_model_entity_with_defined_properties():
employee = FlexEmployee(name='Sandy', location='SF')
return employee
return FlexEmployee(name='Sandy', location='SF')


class Specialized(ndb.Expando):
Expand Down Expand Up @@ -276,8 +267,7 @@ def reserve_model_ids_with_a_parent(p):


def construct_keys_from_range_of_reserved_ids(first, last):
keys = [ndb.Key(MyModel, id) for id in range(first, last+1)]
return keys
return [ndb.Key(MyModel, id) for id in range(first, last+1)]


def reserve_model_ids_up_to(N):
Expand Down
8 changes: 4 additions & 4 deletions appengine/standard/ndb/overview/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def get(self):
greetings = Greeting.query_book(ancestor_key).fetch(20)
# [END query]

greeting_blockquotes = []
for greeting in greetings:
greeting_blockquotes.append(
'<blockquote>%s</blockquote>' % cgi.escape(greeting.content))
greeting_blockquotes = [
'<blockquote>%s</blockquote>' % cgi.escape(greeting.content)
for greeting in greetings
]

self.response.out.write(textwrap.dedent("""\
<html>
Expand Down
3 changes: 1 addition & 2 deletions appengine/standard/ndb/projection_queries/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ class Foo(ndb.Model):


def declare_multiple_valued_property():
entity = Foo(A=[1, 1, 2, 3], B=['x', 'y', 'x'])
return entity
return Foo(A=[1, 1, 2, 3], B=['x', 'y', 'x'])
12 changes: 3 additions & 9 deletions appengine/standard/ndb/property_subclasses/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def create_entity():
# Create an entity and write it to the Datastore.
entity = my_models.MyModel(name='booh', xyz=[10**100, 6**666])
assert entity.abc == 0
key = entity.put()
return key
return entity.put()


def read_and_update_entity(key):
Expand All @@ -34,11 +33,8 @@ def read_and_update_entity(key):


def query_entity():
# Query for a MyModel entity whose xyz contains 6**666.
# (NOTE: using ordering operations don't work, but == does.)
results = my_models.MyModel.query(
return my_models.MyModel.query(
my_models.MyModel.xyz == 6**666).fetch(10)
return results


def create_and_query_columbus():
Expand All @@ -51,7 +47,5 @@ def create_and_query_columbus():
event_names=['Discovery of America'])
columbus.put()

# Query for historic people born no later than 1451.
results = my_models.HistoricPerson.query(
return my_models.HistoricPerson.query(
my_models.HistoricPerson.birth.last <= date(1451, 12, 31)).fetch()
return results
Loading