Skip to content

Commit

Permalink
Merge pull request #852 from online-judge-tools/delete-cookie
Browse files Browse the repository at this point in the history
Show a hint message when cookie.jar is broken
  • Loading branch information
kmyk authored Feb 15, 2021
2 parents 4bb76f8 + f0bd0cc commit 6ac3818
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions onlinejudge_command/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import contextlib
import datetime
import functools
import http.cookiejar
import os
import pathlib
import platform
Expand All @@ -24,6 +25,12 @@

logger = getLogger(__name__)

# These strings can control logging output.
NO_HEADER = 'NO_HEADER: '
HINT = 'HINT: '
SUCCESS = 'SUCCESS: '
FAILURE = 'FAILURE: '

user_data_dir = utils.user_data_dir
user_cache_dir = utils.user_cache_dir
default_cookie_path = utils.default_cookie_path
Expand All @@ -34,8 +41,12 @@ def new_session_with_our_user_agent(*, path: pathlib.Path) -> Iterator[requests.
session = requests.Session()
session.headers['User-Agent'] = '{}/{} (+{})'.format(version.__package_name__, version.__version__, version.__url__)
logger.debug('User-Agent: %s', session.headers['User-Agent'])
with utils.with_cookiejar(session, path=path) as session:
yield session
try:
with utils.with_cookiejar(session, path=path) as session:
yield session
except http.cookiejar.LoadError:
logger.info(HINT + 'You can delete the broken cookie.jar file: %s', str(path))
raise


def textfile(s: str) -> str: # should have trailing newline
Expand Down Expand Up @@ -107,13 +118,6 @@ def exec_command(command_str: str, *, stdin: Optional[BinaryIO] = None, input: O
return info, proc


# These strings can control logging output.
NO_HEADER = 'NO_HEADER: '
HINT = 'HINT: '
SUCCESS = 'SUCCESS: '
FAILURE = 'FAILURE: '


def green(s: str) -> str:
"""green(s) color s with green.
Expand Down

0 comments on commit 6ac3818

Please sign in to comment.