Skip to content

Commit 84c45d2

Browse files
committed
v1.9.1 # minor optimizations
1 parent bad6f1d commit 84c45d2

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ below is the list of `config` keys with their `default` values :
147147
'BYPASS_ROBOTS' : False
148148
```
149149

150-
told your there were plenty of `config` available!
150+
told you there were plenty of `config` available!
151151

152152
## Undocumented Features
153153

pywebcopy/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,3 @@
2828
'__version__', '__author__', '__copyright__', '__license__', '__email__',
2929
'core', 'structures', 'config', 'utils', 'generators'
3030
]
31-

pywebcopy/core.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,11 @@ def watermark(file_path):
367367
# return a bytes converted whitespace stripped down comment
368368
# Compatibility issues due to byes type
369369
if py2:
370-
return bytes(re.sub(r'[\n]+', '\n', comment_style.replace('#', mark)))
370+
return bytes(comment_style.replace('#', mark))
371371
elif py3:
372-
return bytes(re.sub(r'[\n]+', '\n', comment_style.replace('#', mark)), 'utf-8')
372+
return bytes(comment_style.replace('#', mark), 'utf-8')
373373
else:
374-
return re.sub(r'[\n]+', '\n', comment_style.replace('#', mark))
374+
return comment_style.replace('#', mark)
375375

376376

377377
# ----------------------------------------------------------------------
@@ -397,6 +397,17 @@ def now(string, level=0, unbuffered=False, to_console=False, compressed=cfg.conf
397397
:param compressed: reduces the string length to 80 characters
398398
"""
399399

400+
_event_level_strings = ["info", "warning", "error", "success"]
401+
402+
if level == 4:
403+
_event_level = _event_level_strings[2]
404+
elif level == 1 or level == 2:
405+
_event_level = _event_level_strings[3]
406+
elif level == 3:
407+
_event_level = _event_level_strings[1]
408+
else:
409+
_event_level = _event_level_strings[0]
410+
400411
# shorten the string
401412
if compressed:
402413
if len(string) > 80:
@@ -415,10 +426,10 @@ def now(string, level=0, unbuffered=False, to_console=False, compressed=cfg.conf
415426
# standardisation of the input string
416427
if compressed:
417428
_formatted_string = "{} - [Level: {}] - {}".format(
418-
_caller, level, string)
429+
_caller, _event_level, string)
419430
else:
420431
_formatted_string = "[{}] - {} - [Level: {}] - {}".format(
421-
datetime.datetime.utcnow(), _caller, level, string)
432+
datetime.datetime.utcnow(), _caller, _event_level, string)
422433

423434
# if _debug switch is true than this will write now() instances to console
424435
if cfg.config['DEBUG']:
@@ -482,7 +493,7 @@ def save_webpage(url):
482493
if py2:
483494
content = bytes(str(final_soup))
484495
elif py3:
485-
content = bytes(str(final_soup), encoding='utf-8')
496+
content = bytes(str(final_soup), "utf-8")
486497
else:
487498
content = str(final_soup)
488499

0 commit comments

Comments
 (0)