Skip to content
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

Avoid f"..." syntax #66

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
26 changes: 13 additions & 13 deletions piazza_api/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def user_login(self, email=None, password=None):
# Make sure a CSRF token was retrieved, otherwise bail
if response.text.upper().find('CSRF_TOKEN') == -1:
raise AuthenticationError("Could not get CSRF token")

# Remove double quotes and semicolon (ASCI 34 & 59) from response string.
# Then split the string on "=" to parse out the actual CSRF token
csrf_token = response.text.translate({34: None, 59: None}).split("=")[1]
Expand All @@ -77,14 +77,14 @@ def user_login(self, email=None, password=None):

# Log in using credentials and CSRF token and store cookie in session
response = self.session.post(
'https://piazza.com/class',
data=f'from=%2Fsignup&email={email}&password={password}&remember=on&csrf_token={csrf_token}'
'https://piazza.com/class',
data='from=%2Fsignup&email=' + email + '&password=' + password + '&remember=on&csrf_token=' + csrf_token
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)

# If non-successful http response, bail
if response.status_code != 200:
raise AuthenticationError(f"Could not authenticate.\n{response.text}")
raise AuthenticationError("Could not authenticate.\n" + response.text)

# Piazza might give a successful http response even if there is some other
# kind of authentication problem. Need to parse the response html for error message
pos = response.text.upper().find('VAR ERROR_MSG')
Expand All @@ -94,7 +94,7 @@ def user_login(self, email=None, password=None):
errorMsg = response.text[pos:pos+end].translate({34: None}).split('=')[1].strip()

if errorMsg is not None:
raise AuthenticationError(f"Could not authenticate.\n{errorMsg}")
raise AuthenticationError("Could not authenticate.\n" + errorMsg)


def demo_login(self, auth=None, url=None):
Expand Down Expand Up @@ -187,14 +187,14 @@ def content_instructor_answer(self, params):

def content_student_answer(self, cid, content, revision=1, anon=False):
"""Answer question as student or update existing student answer.

:type cid: str
:type content: str
:type revision: int
:type anon: bool
:param cid: The ID of the post to answer.
:param content: The answer content.
:param revision: Revision number. Must be greater than history_size of the student answer.
:param cid: The ID of the post to answer.
:param content: The answer content.
:param revision: Revision number. Must be greater than history_size of the student answer.
:param anon: Whether or not this action should be performed as an anonymous user.
:returns: Python object containing returned data
"""
Expand All @@ -203,9 +203,9 @@ def content_student_answer(self, cid, content, revision=1, anon=False):
method="content.answer",
data={
"content": content,
"type": "s_answer",
"type": "s_answer",
"anonymous": "stud" if anon else "no",
"revision": revision,
"revision": revision,
"cid": cid
}
)
Expand Down Expand Up @@ -251,7 +251,7 @@ def content_pin(self, params, unpin=False):
data=params
)
return self._handle_error(r, "Could not create object {}.".format(
repr(params)))
repr(params)))

def content_delete(self, params):
"""Deletes a post.
Expand Down