|
34 | 34 | import glob |
35 | 35 | import inspect |
36 | 36 | import os |
| 37 | +import pathlib |
37 | 38 | import pickle |
38 | 39 | import re |
39 | 40 | import sys |
@@ -3465,29 +3466,29 @@ def _initialize_history(self, hist_file): |
3465 | 3466 | self.persistent_history_file = hist_file |
3466 | 3467 | return |
3467 | 3468 |
|
3468 | | - hist_file = os.path.expanduser(hist_file) |
| 3469 | + histpath = pathlib.Path(hist_file).expanduser().resolve() |
3469 | 3470 |
|
3470 | 3471 | # first we try and unpickle the history file |
3471 | 3472 | history = History() |
3472 | 3473 | # on Windows, trying to open a directory throws a permission |
3473 | 3474 | # error, not a `IsADirectoryError`. So we'll check it ourselves. |
3474 | | - if os.path.isdir(hist_file): |
| 3475 | + if histpath.is_dir(): |
3475 | 3476 | msg = "persistent history file '{}' is a directory" |
3476 | | - self.perror(msg.format(hist_file)) |
| 3477 | + self.perror(msg.format(histpath)) |
3477 | 3478 | return |
3478 | 3479 |
|
3479 | 3480 | try: |
3480 | | - with open(hist_file, 'rb') as fobj: |
| 3481 | + with open(str(histpath), 'rb') as fobj: |
3481 | 3482 | history = pickle.load(fobj) |
3482 | 3483 | except (FileNotFoundError, KeyError, EOFError): |
3483 | 3484 | pass |
3484 | 3485 | except OSError as ex: |
3485 | 3486 | msg = "can not read persistent history file '{}': {}" |
3486 | | - self.perror(msg.format(hist_file, ex), traceback_war=False) |
| 3487 | + self.perror(msg.format(histpath, ex), traceback_war=False) |
3487 | 3488 | return |
3488 | 3489 |
|
3489 | 3490 | self.history = history |
3490 | | - self.persistent_history_file = hist_file |
| 3491 | + self.persistent_history_file = str(histpath) |
3491 | 3492 |
|
3492 | 3493 | # populate readline history |
3493 | 3494 | if rl_type != RlType.NONE: |
|
0 commit comments