Skip to content

Commit

Permalink
lint: Clean up E126 PEP-8 rule.
Browse files Browse the repository at this point in the history
  • Loading branch information
timabbott committed Jan 24, 2017
1 parent 31e7dcd commit 4e171ce
Show file tree
Hide file tree
Showing 60 changed files with 429 additions and 432 deletions.
4 changes: 2 additions & 2 deletions analytics/management/commands/client_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ def handle(self, *args, **options):
# Report activity for a user.
user_profile = get_user_profile_by_email(arg)
self.compute_activity(UserActivity.objects.filter(
user_profile=user_profile))
user_profile=user_profile))
except UserProfile.DoesNotExist:
try:
# Report activity for a realm.
realm = get_realm(arg)
self.compute_activity(UserActivity.objects.filter(
user_profile__realm=realm))
user_profile__realm=realm))
except Realm.DoesNotExist:
print("Unknown user or realm %s" % (arg,))
exit(1)
10 changes: 5 additions & 5 deletions analytics/management/commands/realm_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def active_users(self, realm):
# Has been active (on the website, for now) in the last 7 days.
activity_cutoff = datetime.datetime.now(tz=pytz.utc) - datetime.timedelta(days=7)
return [activity.user_profile for activity in (
UserActivity.objects.filter(user_profile__realm=realm,
user_profile__is_active=True,
last_visit__gt=activity_cutoff,
query="/json/users/me/pointer",
client__name="website"))]
UserActivity.objects.filter(user_profile__realm=realm,
user_profile__is_active=True,
last_visit__gt=activity_cutoff,
query="/json/users/me/pointer",
client__name="website"))]

def messages_sent_by(self, user, days_ago):
# type: (UserProfile, int) -> int
Expand Down
88 changes: 44 additions & 44 deletions analytics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,9 +699,9 @@ def get_user_activity_records_for_realm(realm, is_bot):
]

records = UserActivity.objects.filter(
user_profile__realm__string_id=realm,
user_profile__is_active=True,
user_profile__is_bot=is_bot
user_profile__realm__string_id=realm,
user_profile__is_active=True,
user_profile__is_bot=is_bot
)
records = records.order_by("user_profile__email", "-last_visit")
records = records.select_related('user_profile', 'client').only(*fields)
Expand All @@ -718,7 +718,7 @@ def get_user_activity_records_for_email(email):
]

records = UserActivity.objects.filter(
user_profile__email=email
user_profile__email=email
)
records = records.order_by("-last_visit")
records = records.select_related('user_profile', 'client').only(*fields)
Expand All @@ -736,10 +736,10 @@ def raw_user_activity_table(records):
def row(record):
# type: (QuerySet) -> List[Any]
return [
record.query,
record.client.name,
record.count,
format_date_for_activity_reports(record.last_visit)
record.query,
record.client.name,
record.count,
format_date_for_activity_reports(record.last_visit)
]

rows = list(map(row, records))
Expand All @@ -759,14 +759,14 @@ def update(action, record):
# type: (str, QuerySet) -> None
if action not in summary:
summary[action] = dict(
count=record.count,
last_visit=record.last_visit
count=record.count,
last_visit=record.last_visit
)
else:
summary[action]['count'] += record.count
summary[action]['last_visit'] = max(
summary[action]['last_visit'],
record.last_visit
summary[action]['last_visit'],
record.last_visit
)

if records:
Expand Down Expand Up @@ -820,13 +820,13 @@ def realm_activity_link(realm_str):
def realm_client_table(user_summaries):
# type: (Dict[str, Dict[str, Dict[str, Any]]]) -> str
exclude_keys = [
'internal',
'name',
'use',
'send',
'pointer',
'website',
'desktop',
'internal',
'name',
'use',
'send',
'pointer',
'website',
'desktop',
]

rows = []
Expand All @@ -840,22 +840,22 @@ def realm_client_table(user_summaries):
count = v['count']
last_visit = v['last_visit']
row = [
format_date_for_activity_reports(last_visit),
client,
name,
email_link,
count,
format_date_for_activity_reports(last_visit),
client,
name,
email_link,
count,
]
rows.append(row)

rows = sorted(rows, key=lambda r: r[0], reverse=True)

cols = [
'Last visit',
'Client',
'Name',
'Email',
'Count',
'Last visit',
'Client',
'Name',
'Email',
'Count',
]

title = 'Clients'
Expand All @@ -872,18 +872,18 @@ def user_activity_summary_table(user_summary):
count = v['count']
last_visit = v['last_visit']
row = [
format_date_for_activity_reports(last_visit),
client,
count,
format_date_for_activity_reports(last_visit),
client,
count,
]
rows.append(row)

rows = sorted(rows, key=lambda r: r[0], reverse=True)

cols = [
'last_visit',
'client',
'count',
'last_visit',
'client',
'count',
]

title = 'User Activity'
Expand Down Expand Up @@ -944,15 +944,15 @@ def by_used_time(row):
rows = sorted(rows, key=by_used_time, reverse=True)

cols = [
'Name',
'Email',
'Total sent',
'Heard from',
'Message sent',
'Pointer motion',
'Desktop',
'ZulipiOS',
'Android'
'Name',
'Email',
'Total sent',
'Heard from',
'Message sent',
'Pointer motion',
'Desktop',
'ZulipiOS',
'Android',
]

title = 'Summary'
Expand Down
8 changes: 4 additions & 4 deletions api/examples/create-user
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ parser.add_option('--new-short-name')
client = zulip.init_from_options(options)

print(client.create_user({
'email': options.new_email,
'password': options.new_password,
'full_name': options.new_full_name,
'short_name': options.new_short_name
'email': options.new_email,
'password': options.new_password,
'full_name': options.new_full_name,
'short_name': options.new_short_name
}))
8 changes: 4 additions & 4 deletions api/integrations/trac/zulip_trac.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def trac_subject(ticket):
def send_update(ticket, content):
# type: (Any, str) -> None
client.send_message({
"type": "stream",
"to": config.STREAM_FOR_NOTIFICATIONS,
"content": content,
"subject": trac_subject(ticket)
"type": "stream",
"to": config.STREAM_FOR_NOTIFICATIONS,
"content": content,
"subject": trac_subject(ticket)
})

class ZulipPlugin(Component):
Expand Down
24 changes: 12 additions & 12 deletions api/zulip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,9 @@ def get_user_agent(self):
vendor_version = platform.mac_ver()[0]

return "{client_name} ({vendor}; {vendor_version})".format(
client_name=self.client_name,
vendor=vendor,
vendor_version=vendor_version,
client_name=self.client_name,
vendor=vendor,
vendor_version=vendor_version,
)

def do_api_query(self, orig_request, url, method="POST", longpolling=False, files=None):
Expand Down Expand Up @@ -357,15 +357,15 @@ def end_error_retry(succeeded):
client_cert = self.client_cert

res = requests.request(
method,
urllib.parse.urljoin(self.base_url, url),
auth=requests.auth.HTTPBasicAuth(self.email,
self.api_key),
verify=self.tls_verification,
cert=client_cert,
timeout=90,
headers={"User-agent": self.get_user_agent()},
**kwargs)
method,
urllib.parse.urljoin(self.base_url, url),
auth=requests.auth.HTTPBasicAuth(self.email,
self.api_key),
verify=self.tls_verification,
cert=client_cert,
timeout=90,
headers={"User-agent": self.get_user_agent()},
**kwargs)

# On 50x errors, try again after a short sleep
if str(res.status_code).startswith('5'):
Expand Down
14 changes: 7 additions & 7 deletions bots/check-mirroring
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,16 @@ logger.info("Sent Zephyr messages!")
for key, (stream, test) in hzkeys.items():
if stream == "message":
send_zulip({
"type": "private",
"content": str(key),
"to": zulip_user,
"type": "private",
"content": str(key),
"to": zulip_user,
})
else:
send_zulip({
"type": "stream",
"subject": "test",
"content": str(key),
"to": stream,
"type": "stream",
"subject": "test",
"content": str(key),
"to": stream,
})
receive_zephyrs()

Expand Down
20 changes: 10 additions & 10 deletions bots/irc-mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def on_privmsg(self, c, e):

# Forward the PM to Zulip
print(zulip_client.send_message({
"sender": sender,
"type": "private",
"to": "[email protected]",
"content": content,
"sender": sender,
"type": "private",
"to": "[email protected]",
"content": content,
}))

def on_pubmsg(self, c, e):
Expand All @@ -81,12 +81,12 @@ def on_pubmsg(self, c, e):

# Forward the stream message to Zulip
print(zulip_client.send_message({
"forged": "yes",
"sender": sender,
"type": "stream",
"to": stream,
"subject": "IRC",
"content": content,
"forged": "yes",
"sender": sender,
"type": "stream",
"to": stream,
"subject": "IRC",
"content": content,
}))

def on_dccmsg(self, c, e):
Expand Down
2 changes: 1 addition & 1 deletion bots/jabber_mirror_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def config_error(msg):
in their help sections). Keys have the same name as options with hyphens
replaced with underscores. Zulip configuration options go in the api section,
as normal.'''.replace("\n", " ")
)
)
parser.add_option(
'--mode',
default=None,
Expand Down
32 changes: 16 additions & 16 deletions contrib_bots/bots/converter/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ def send_message(self, params):
''' % (cmd, expected_response, client_dummy.output))
def sample_conversation():
return [
('@convert 2 m cm', '2.0 m = 200.0 cm\n'),
('@converter 2 m cm', ''),
('@convert 12 celsius fahrenheit',
'12.0 celsius = 53.600054 fahrenheit\n'),
('@convert 0.002 kilometer millimile',
'0.002 kilometer = 1.2427424 millimile\n'),
('@convert 3 megabyte kilobit',
'3.0 megabyte = 24576.0 kilobit\n'),
(('foo @convert 120.5 g lb bar baz.\n'
'baz bar bar @convert 22 k c lorem ipsum dolor'),
('1. conversion: 120.5 g = 0.26565703 lb\n'
'2. conversion: 22.0 k = -251.15 c\n')),
('@convert foo bar',
('Too few arguments given. Enter `@convert help` '
'for help on using the converter.\n')),
]
('@convert 2 m cm', '2.0 m = 200.0 cm\n'),
('@converter 2 m cm', ''),
('@convert 12 celsius fahrenheit',
'12.0 celsius = 53.600054 fahrenheit\n'),
('@convert 0.002 kilometer millimile',
'0.002 kilometer = 1.2427424 millimile\n'),
('@convert 3 megabyte kilobit',
'3.0 megabyte = 24576.0 kilobit\n'),
(('foo @convert 120.5 g lb bar baz.\n'
'baz bar bar @convert 22 k c lorem ipsum dolor'),
('1. conversion: 120.5 g = 0.26565703 lb\n'
'2. conversion: 22.0 k = -251.15 c\n')),
('@convert foo bar',
('Too few arguments given. Enter `@convert help` '
'for help on using the converter.\n')),
]

if __name__ == '__main__':
test()
12 changes: 6 additions & 6 deletions contrib_bots/bots/github_issues/github_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def handle_message(self, message, client, state_handler):

# Creates the issue json, that is transmitted to the github api servers
issue = {
'title': new_issue_title,
'body': '{} **Sent by [{}](https://chat.zulip.org/#) from zulip**'.format(issue_content, original_sender),
'assignee': '',
'milestone': 'none',
'labels': [''],
}
'title': new_issue_title,
'body': '{} **Sent by [{}](https://chat.zulip.org/#) from zulip**'.format(issue_content, original_sender),
'assignee': '',
'milestone': 'none',
'labels': [''],
}
# Sends the HTTP post request
r = session.post(url_new, json.dumps(issue))

Expand Down
Loading

0 comments on commit 4e171ce

Please sign in to comment.