6
6
import json
7
7
import logging
8
8
import os
9
- import os .path
10
9
import sys
11
10
from collections .abc import Callable , Hashable , Iterable
11
+ from pathlib import Path
12
12
from typing import (
13
13
TypeVar ,
14
14
cast ,
@@ -79,15 +79,15 @@ def get_cache_dir() -> str:
79
79
if xdg_cache_home is None :
80
80
user_home = os .getenv ("HOME" , None )
81
81
if user_home :
82
- xdg_cache_home = os . path . join ( user_home , ".cache" )
82
+ xdg_cache_home = str ( Path ( user_home , ".cache" ) )
83
83
84
84
if xdg_cache_home is not None :
85
- return os . path . join (
86
- xdg_cache_home , "python-tldextract" , get_pkg_unique_identifier ()
85
+ return str (
86
+ Path ( xdg_cache_home , "python-tldextract" , get_pkg_unique_identifier () )
87
87
)
88
88
89
89
# fallback to trying to use package directory itself
90
- return os . path . join ( os .path .dirname (__file__ ), ".suffix_cache/" )
90
+ return str ( Path ( os .path .dirname (__file__ ), ".suffix_cache" ) )
91
91
92
92
93
93
class DiskCache :
@@ -153,7 +153,7 @@ def clear(self) -> None:
153
153
self .file_ext + ".lock"
154
154
):
155
155
try :
156
- os .unlink (os . path . join ( root , filename ))
156
+ os .unlink (str ( Path ( root , filename ) ))
157
157
except FileNotFoundError :
158
158
pass
159
159
except OSError as exc :
@@ -165,10 +165,10 @@ def clear(self) -> None:
165
165
def _key_to_cachefile_path (
166
166
self , namespace : str , key : str | dict [str , Hashable ]
167
167
) -> str :
168
- namespace_path = os . path . join ( self .cache_dir , namespace )
168
+ namespace_path = str ( Path ( self .cache_dir , namespace ) )
169
169
hashed_key = _make_cache_key (key )
170
170
171
- cache_path = os . path . join ( namespace_path , hashed_key + self .file_ext )
171
+ cache_path = str ( Path ( namespace_path , hashed_key + self .file_ext ) )
172
172
173
173
return cache_path
174
174
0 commit comments