Skip to content

Commit a264e8a

Browse files
committed
get_user(), save(), and restore() can return None
1 parent 79f2033 commit a264e8a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pubsub/pubsub.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def check_user(user: User, password: str) -> bool:
8888
sleep(random.expovariate(10))
8989
return secrets.compare_digest(hashpass, target_hash_pass)
9090

91-
def get_user(user: User) -> UserInfo:
92-
return user_info[user]
91+
def get_user(user: User) -> Optional[UserInfo]:
92+
return user_info.get(user)
9393

9494
time_unit_cuts = [60, 3600, 3600*24] # type: List[int]
9595
time_units = [(1, 'second'), (60, 'minute'), (3600, 'hour'), (24*3600, 'day')] # type: List[Tuple[int, str]]
@@ -100,11 +100,11 @@ def age(post: Post) -> str:
100100
units = seconds // divisor
101101
return '%d %s ago' % (units, unit + ('' if units==1 else 's'))
102102

103-
def save():
103+
def save() -> None:
104104
with open('pubsub.pickle', 'wb') as f:
105105
pickle.dump([posts, user_posts, hashtag_index, following, followers, user_info], f)
106106

107-
def restore():
107+
def restore() -> None:
108108
global posts, user_posts, hashtag_index, following, followers, user_info
109109
with open('pubsub.pickle', 'rb') as f:
110110
posts, user_posts, hashtag_index, following, followers, user_info = pickle.load(f)

pubsub/webapp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def show_search():
5858
return dict(user=user, posts=posts, heading=heading, comb=comb)
5959

6060
def verify_user_exists(user):
61-
user in pubsub.user_info or abort(404, f'Unknown user: {user!r}')
61+
pubsub.user_info[user] or abort(404, f'Unknown user: {user!r}')
6262

6363
@get('/<user>')
6464
@view('user')

0 commit comments

Comments
 (0)