Skip to content

Commit da637ff

Browse files
committed
🔥 remove feature support for python 2.7. no way back. related to #303
1 parent 7e26de6 commit da637ff

File tree

6 files changed

+11
-33
lines changed

6 files changed

+11
-33
lines changed

moban/core/hashstore.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ class HashStore:
1212
IGNORE_CACHE_FILE = False
1313

1414
def __init__(self):
15-
self.cache_file = file_system.to_unicode(
16-
constants.DEFAULT_MOBAN_CACHE_FILE
17-
)
15+
self.cache_file = constants.DEFAULT_MOBAN_CACHE_FILE
1816
if (
1917
file_system.exists(self.cache_file)
2018
and self.IGNORE_CACHE_FILE is False

moban/core/moban_factory.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ def number_of_templated_files(self):
117117
return self.templated_count
118118

119119
def render_to_file(self, template_file, data_file, output_file):
120-
template_file = file_system.to_unicode(template_file)
121120
data = self.context.get_data(data_file)
122121
template = self.engine.get_template(template_file)
123122
try:
@@ -178,7 +177,7 @@ def apply_template(self, template_abs_path, template, data, output_file):
178177
return flag
179178
except exceptions.FileNotFound:
180179
# the template is a string from command line
181-
LOG.info("{} is not a file".format(template_abs_path))
180+
LOG.info(f"{template_abs_path} is not a file")
182181
self.buffered_writer.write_file_out(output_file, rendered_content)
183182
return True
184183

@@ -197,7 +196,7 @@ def _render_with_finding_template_first(self, template_file_index):
197196
for (template_file, data_output_pairs) in template_file_index.items():
198197
template = self.engine.get_template(template_file)
199198
template_abs_path = self.template_fs.geturl(
200-
file_system.to_unicode(template_file), purpose="fs"
199+
template_file, purpose="fs"
201200
)
202201
for (data_file, output) in data_output_pairs:
203202
data = self.context.get_data(data_file)
@@ -217,7 +216,7 @@ def _render_with_finding_data_first(self, data_file_index):
217216
for (template_file, output) in template_output_pairs:
218217
template = self.engine.get_template(template_file)
219218
template_abs_path = self.template_fs.geturl(
220-
file_system.to_unicode(template_file), purpose="fs"
219+
template_file, purpose="fs"
221220
)
222221
flag = self.apply_template(
223222
template_abs_path, template, data, output
@@ -240,7 +239,7 @@ def expand_template_directories(dirs):
240239

241240

242241
def expand_template_directory(directory):
243-
LOG.debug("Expanding %s..." % directory)
242+
LOG.debug(f"Expanding {directory}...")
244243
translated_directory = None
245244
if ":" in directory and directory[1] != ":" and "://" not in directory:
246245
translated_directory = deprecated_moban_path_notation(directory)

moban/core/mobanfile/templates.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def handle_template(template_file, output, template_dirs):
1111
LOG.info("handling %s" % template_file)
1212

13-
template_file = file_system.to_unicode(template_file)
13+
template_file = template_file
1414
multi_fs = file_system.get_multi_fs(template_dirs)
1515
if template_file.endswith("**"):
1616
source_dir = template_file[:-3]

moban/externals/buffered_writer.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ def write_file_out(self, filename, content):
2222
def write_file_out_to_zip(self, filename, content):
2323
zip_file, file_name = file_system.url_split(filename)
2424
if zip_file not in self.fs_list:
25-
self.fs_list[zip_file] = fs.open_fs(
26-
file_system.to_unicode(zip_file), create=True
27-
)
25+
self.fs_list[zip_file] = fs.open_fs(zip_file, create=True)
2826
base_dirs = fs.path.dirname(file_name)
2927
if not self.fs_list[zip_file].exists(base_dirs):
3028
self.fs_list[zip_file].makedirs(base_dirs)
31-
self.fs_list[zip_file].writebytes(
32-
file_system.to_unicode(file_name), content
33-
)
29+
self.fs_list[zip_file].writebytes(file_name, content)
3430

3531
def close(self):
3632
for fsx in self.fs_list.values():

moban/externals/file_system.py

+2-15
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
def url_join(path, path2):
2828
result = urlparse(path)
2929
if result.scheme and path.endswith(result.scheme):
30-
return path + to_unicode("!/") + path2
30+
return f"{path}!/{path2}"
3131
else:
32-
return path + to_unicode("/") + path2
32+
return f"{path}/{path2}"
3333

3434

3535
def log_fs_failure(function_in_this_module):
@@ -53,7 +53,6 @@ def wrapper(*args, **kwds):
5353
@log_fs_failure
5454
@contextmanager
5555
def open_fs(path):
56-
path = to_unicode(path)
5756
if is_zip_alike_url(path):
5857
zip_file, folder = url_split(path)
5958
the_fs = fs.open_fs(zip_file)
@@ -68,7 +67,6 @@ def open_fs(path):
6867
@log_fs_failure
6968
@contextmanager
7069
def open_file(path):
71-
path = to_unicode(path)
7270
if is_zip_alike_url(path):
7371
zip_file, folder = url_split(path)
7472
the_fs = fs.open_fs(zip_file)
@@ -88,7 +86,6 @@ def open_file(path):
8886
@log_fs_failure
8987
@contextmanager
9088
def open_binary_file(path):
91-
path = to_unicode(path)
9289
if is_zip_alike_url(path):
9390
zip_file, folder = url_split(path)
9491
the_fs = fs.open_fs(zip_file)
@@ -123,7 +120,6 @@ def read_bytes(path):
123120

124121
@log_fs_failure
125122
def write_bytes(filename, bytes_content):
126-
filename = to_unicode(filename)
127123
if "://" in filename:
128124
zip_file, folder = url_split(filename)
129125
with fs.open_fs(zip_file, create=True) as the_fs:
@@ -150,8 +146,6 @@ def is_file(path):
150146

151147

152148
def exists(path):
153-
path = to_unicode(path)
154-
155149
if is_zip_alike_url(path):
156150
zip_file, folder = url_split(path)
157151
try:
@@ -179,7 +173,6 @@ def exists(path):
179173

180174
@log_fs_failure
181175
def list_dir(path):
182-
path = to_unicode(path)
183176
folder_or_file, path = _path_split(path)
184177
with fs.open_fs(folder_or_file) as the_fs:
185178
for file_name in the_fs.listdir(path):
@@ -188,31 +181,26 @@ def list_dir(path):
188181

189182
@log_fs_failure
190183
def abspath(path):
191-
path = to_unicode(path)
192184
folder_or_file, path = _path_split(path)
193185
with fs.open_fs(folder_or_file) as the_fs:
194186
return the_fs.getsyspath(path)
195187

196188

197189
@log_fs_failure
198190
def fs_url(path):
199-
path = to_unicode(path)
200191
folder_or_file, path = _path_split(path)
201192
with fs.open_fs(folder_or_file) as the_fs:
202193
return the_fs.geturl(path, purpose="fs")
203194

204195

205196
@log_fs_failure
206197
def system_path(path):
207-
path = to_unicode(path)
208198
folder_or_file, path = _path_split(path)
209199
with fs.open_fs(folder_or_file) as the_fs:
210200
return the_fs.getsyspath(path)
211201

212202

213203
def to_unicode(path):
214-
if PY2 and path.__class__.__name__ != "unicode":
215-
return u"".__class__(path)
216204
return path
217205

218206

@@ -258,7 +246,6 @@ def url_split(url):
258246

259247

260248
def _path_split(url_or_path):
261-
url_or_path = to_unicode(url_or_path)
262249
if is_zip_alike_url(url_or_path):
263250
return url_split(url_or_path)
264251
else:

moban/plugins/copy.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ def __init__(self, template_fs, extensions=None):
2828
self.template_fs = template_fs
2929

3030
def get_template(self, template_file):
31-
return self.template_fs.readbytes(
32-
file_system.to_unicode(template_file)
33-
)
31+
return self.template_fs.readbytes(template_file)
3432

3533
def get_template_from_string(self, string):
3634
return string

0 commit comments

Comments
 (0)