Skip to content

Commit 9016835

Browse files
committed
First batch of yapf auto-formatting.
This covers all our files under app/ which don't start with a, f, m, or v. Starts addressing issue google#619.
1 parent 047c968 commit 9016835

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1359
-761
lines changed

app/cloud_storage.py

+29-22
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,20 @@ def insert_object(self, object_name, content_type, data):
6464
content_type (str): MIME type string of the object.
6565
data (str): The content of the object.
6666
"""
67-
media = MediaIoBaseUpload(StringIO.StringIO(data), mimetype=content_type)
67+
media = MediaIoBaseUpload(
68+
StringIO.StringIO(data), mimetype=content_type)
6869
self.service.objects().insert(
6970
bucket=self.bucket_name,
7071
name=object_name,
7172
body={
7273
# This let browsers to download the file instead of opening
7374
# it in a browser.
74-
'contentDisposition':
75-
'attachment; filename=%s' % object_name,
75+
'contentDisposition': 'attachment; filename=%s' % object_name,
7676
},
7777
media_body=media).execute()
7878

79-
def compose_objects(
80-
self,
81-
source_object_names,
82-
destination_object_name,
83-
destination_content_type):
79+
def compose_objects(self, source_object_names, destination_object_name,
80+
destination_content_type):
8481
"""Concatenates the source objects to generate the destination object.
8582
8683
Args:
@@ -92,13 +89,16 @@ def compose_objects(
9289
destinationBucket=self.bucket_name,
9390
destinationObject=destination_object_name,
9491
body={
95-
'sourceObjects': [{'name': name} for name in source_object_names],
92+
'sourceObjects': [{
93+
'name': name
94+
} for name in source_object_names],
9695
'destination': {
97-
'contentType': destination_content_type,
96+
'contentType':
97+
destination_content_type,
9898
# This let browsers to download the file instead of opening
9999
# it in a browser.
100100
'contentDisposition':
101-
'attachment; filename=%s' % destination_object_name,
101+
'attachment; filename=%s' % destination_object_name,
102102
},
103103
}).execute()
104104

@@ -146,7 +146,8 @@ def sign_url(self, object_name, url_lifetime):
146146
'Expires': str(expiration_sec),
147147
'Signature': base64.b64encode(signature),
148148
}
149-
return 'https://storage.googleapis.com%s?%s' % (path, urllib.urlencode(query_params))
149+
return 'https://storage.googleapis.com%s?%s' % (
150+
path, urllib.urlencode(query_params))
150151

151152
def set_objects_lifetime(self, lifetime_days):
152153
"""Sets lifetime of all objects in the bucket in days.
@@ -155,13 +156,19 @@ def set_objects_lifetime(self, lifetime_days):
155156
156157
lifetime_days (int): Lifetime of objects in a number of days.
157158
"""
158-
self.service.buckets().patch(bucket=self.bucket_name, body={
159-
'lifecycle': {
160-
'rule': [
161-
{
162-
'action': {'type': 'Delete'},
163-
'condition': {'age': lifetime_days},
164-
},
165-
],
166-
},
167-
}).execute()
159+
self.service.buckets().patch(
160+
bucket=self.bucket_name,
161+
body={
162+
'lifecycle': {
163+
'rule': [
164+
{
165+
'action': {
166+
'type': 'Delete'
167+
},
168+
'condition': {
169+
'age': lifetime_days
170+
},
171+
},
172+
],
173+
},
174+
}).execute()

app/config.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15-
1615
"""Storage for configuration settings. Settings can be global or specific
1716
to a repository, and their values can be of any JSON-encodable type.
1817
@@ -47,9 +46,9 @@ class ConfigurationCache:
4746

4847
def flush(self):
4948
self.storage.clear()
50-
self.items_count=0
49+
self.items_count = 0
5150

52-
def delete(self,key):
51+
def delete(self, key):
5352
"""Deletes the entry with given key from config_cache."""
5453
if key in self.storage:
5554
self.storage.pop(key)
@@ -67,12 +66,12 @@ def read(self, key, default=None):
6766
"""Gets the value corresponding to the key from cache. If cache entry
6867
has expired, it is deleted from the cache and None is returned."""
6968
value, expiry = self.storage.get(key, (None, 0))
70-
if value is None :
69+
if value is None:
7170
self.miss_count += 1
7271
return default
7372

7473
now = utils.get_utcnow()
75-
if (expiry > now) :
74+
if (expiry > now):
7675
self.hit_count += 1
7776
return value
7877
else:
@@ -100,7 +99,7 @@ def get_config(self, repo, name, default=None):
10099
return default
101100
logging.debug("Adding repository %r to config_cache" % repo)
102101
config_dict = dict([(e.key().name().split(':', 1)[1],
103-
simplejson.loads(e.value)) for e in entries])
102+
simplejson.loads(e.value)) for e in entries])
104103
self.add(repo, config_dict, self.expiry_time)
105104

106105
if name in config_dict:
@@ -110,13 +109,16 @@ def get_config(self, repo, name, default=None):
110109
def enable(self, value):
111110
"""Enable/disable caching of config."""
112111
logging.info('Setting config_cache_enable to %s' % value)
113-
db.put(ConfigEntry(key_name="*:config_cache_enable",
114-
value=simplejson.dumps(bool(value))))
112+
db.put(
113+
ConfigEntry(
114+
key_name="*:config_cache_enable",
115+
value=simplejson.dumps(bool(value))))
115116
self.delete('*')
116117

117118
def is_enabled(self):
118119
return self.get_config('*', 'config_cache_enable', None)
119120

121+
120122
cache = ConfigurationCache()
121123

122124

@@ -139,16 +141,19 @@ def get(name, default=None, repo='*'):
139141
return simplejson.loads(entry.value)
140142
return default
141143

144+
142145
def set(repo='*', **kwargs):
143146
"""Sets configuration settings."""
144147
if 'launched_repos' in kwargs.keys():
145148
raise Exception(
146149
'Config "launched_repos" is deprecated. Use per-repository '
147150
'config "launched" instead.')
148-
db.put(ConfigEntry(key_name=repo + ':' + name,
149-
value=simplejson.dumps(value)) for name, value in kwargs.items())
151+
db.put(
152+
ConfigEntry(key_name=repo + ':' + name, value=simplejson.dumps(value))
153+
for name, value in kwargs.items())
150154
cache.delete(repo)
151155

156+
152157
# If calling from code where a Configuration object is available (e.g., from
153158
# within a handler), prefer Configuration.get. Configuration objects get all
154159
# config entries when they're initialized, so they don't need to make an
@@ -162,19 +167,20 @@ def get_for_repo(repo, name, default=None):
162167
value = get(name, default, '*')
163168
return value
164169

170+
165171
def set_for_repo(repo, **kwargs):
166172
"""Sets configuration settings for a particular repository. When used
167173
with get_for_repo, has the effect of overriding global settings."""
168174
set(str(repo), **kwargs)
169175

170176

171177
class Configuration(UserDict.DictMixin):
178+
172179
def __init__(self, repo):
173180
self.repo = repo
174181
# We fetch all the config entries at once here, so that we don't have to
175182
# make many Datastore queries for each individual entry later.
176-
db_entries = model.filter_by_prefix(
177-
ConfigEntry.all(), self.repo + ':')
183+
db_entries = model.filter_by_prefix(ConfigEntry.all(), self.repo + ':')
178184
self.entries = {
179185
entry.key().name().split(':', 1)[1]: simplejson.loads(entry.value)
180186
for entry in db_entries

app/confirm_disable_notes.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121

2222
from django.utils.translation import ugettext as _
2323

24+
2425
class DisableAndEnableNotesError(Exception):
2526
"""Container for user-facing error messages when confirming to disable
2627
or enable future nots to a record."""
2728
pass
2829

30+
2931
class Handler(utils.BaseHandler):
3032
"""This handler lets the author confirm to disable future notes
3133
to a person record."""
@@ -36,10 +38,11 @@ def get(self):
3638
except DisableAndEnableNotesError, e:
3739
return self.error(400, unicode(e))
3840

39-
self.render('confirm_disable_notes.html',
40-
person=person,
41-
id=self.params.id,
42-
token=token)
41+
self.render(
42+
'confirm_disable_notes.html',
43+
person=person,
44+
id=self.params.id,
45+
token=token)
4346

4447
def post(self):
4548
try:
@@ -49,8 +52,7 @@ def post(self):
4952

5053
# Log the user action.
5154
model.UserActionLog.put_new(
52-
'disable_notes',
53-
person,
55+
'disable_notes', person,
5456
self.request.get('reason_for_disabling_notes'))
5557

5658
# Update the notes_disabled flag in person record.
@@ -62,7 +64,7 @@ def post(self):
6264

6365
# Send subscribers a notice email.
6466
subject = _('[Person Finder] Notes are now disabled for "%(full_name)s"'
65-
) % {'full_name': person.primary_full_name}
67+
) % {'full_name': person.primary_full_name}
6668
email_addresses = person.get_associated_emails()
6769
for address in email_addresses:
6870
self.send_mail(
@@ -71,9 +73,7 @@ def post(self):
7173
body=self.render_to_string(
7274
'disable_notes_notice_email.txt',
7375
full_name=person.primary_full_name,
74-
record_url=record_url
75-
)
76-
)
76+
record_url=record_url))
7777

7878
self.redirect(record_url)
7979

app/confirm_enable_notes.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
from confirm_disable_notes import DisableAndEnableNotesError
2525

26+
2627
class Handler(utils.BaseHandler):
2728
"""This handler lets the author confirm to disable future nots
2829
to a person record."""
@@ -45,7 +46,7 @@ def get(self):
4546

4647
# Send subscribers a notice email.
4748
subject = _('[Person Finder] Notes are now enabled on "%(full_name)s"'
48-
) % {'full_name': person.primary_full_name}
49+
) % {'full_name': person.primary_full_name}
4950
email_addresses = person.get_associated_emails()
5051
for address in email_addresses:
5152
self.send_mail(
@@ -54,13 +55,10 @@ def get(self):
5455
body=self.render_to_string(
5556
'enable_notes_notice_email.txt',
5657
full_name=person.primary_full_name,
57-
record_url=record_url
58-
)
59-
)
58+
record_url=record_url))
6059

6160
self.redirect(record_url)
6261

63-
6462
def post(self):
6563
try:
6664
person, token = self.get_person_and_verify_params()
@@ -79,7 +77,7 @@ def post(self):
7977

8078
# Send subscribers a notice email.
8179
subject = _('[Person Finder] Enabling notes notice for "%(full_name)s"'
82-
) % {'full_name': person.primary_full_name}
80+
) % {'full_name': person.primary_full_name}
8381
email_addresses = person.get_associated_emails()
8482
for address in email_addresses:
8583
self.send_mail(
@@ -88,13 +86,10 @@ def post(self):
8886
body=self.render_to_string(
8987
'enable_notes_notice_email.txt',
9088
full_name=person.primary_full_name,
91-
record_url=record_url
92-
)
93-
)
89+
record_url=record_url))
9490

9591
self.redirect(record_url)
9692

97-
9893
def get_person_and_verify_params(self):
9994
"""Check the request for a valid person id and valid crypto token.
10095

app/confirm_post_flagged_note.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222

2323
from django.utils.translation import ugettext as _
2424

25+
2526
class ConfirmPostNoteWithBadWordsError(Exception):
2627
"""Container for user-facing error messages when confirming to post
2728
a note with bad words."""
2829
pass
2930

31+
3032
class Handler(utils.BaseHandler):
3133
"""This handler lets the author confirm to post a note containing
3234
bad words."""
@@ -83,7 +85,7 @@ def confirm_note_with_bad_words(self, note):
8385
(2) copy the note from NoteWithBadWords to Note;
8486
(3) log user action;
8587
(4) update person record. """
86-
note.confirmed = True;
88+
note.confirmed = True
8789

8890
# Check whether the record author disabled notes on
8991
# this record during the time between the note author inputs the
@@ -97,7 +99,7 @@ def confirm_note_with_bad_words(self, note):
9799
# during the time between the note author inputs the
98100
# note in the UI and confirms the note through email.
99101
if (self.params.status == 'believed_dead' and
100-
not self.config.allow_believed_dead_via_ui):
102+
not self.config.allow_believed_dead_via_ui):
101103
return self.error(
102104
200, _('Not authorized to post notes with the status '
103105
'"believed_dead".'))
@@ -124,15 +126,17 @@ def confirm_note_with_bad_words(self, note):
124126

125127
# Specially log 'believed_dead'.
126128
if note_confirmed.status == 'believed_dead':
127-
model.UserActionLog.put_new(
128-
'mark_dead', note_confirmed, person.primary_full_name,
129-
self.request.remote_addr)
129+
model.UserActionLog.put_new('mark_dead', note_confirmed,
130+
person.primary_full_name,
131+
self.request.remote_addr)
130132

131133
# Specially log a switch to an alive status.
132134
if (note_confirmed.status in ['believed_alive', 'is_note_author'] and
133-
person.latest_status not in ['believed_alive', 'is_note_author']):
134-
model.UserActionLog.put_new(
135-
'mark_alive', note_confirmed, person.primary_full_name)
135+
person.latest_status not in [
136+
'believed_alive', 'is_note_author'
137+
]):
138+
model.UserActionLog.put_new('mark_alive', note_confirmed,
139+
person.primary_full_name)
136140

137141
# Update the Person based on the Note.
138142
if person:

0 commit comments

Comments
 (0)