This commit is contained in:
parent
5ee55a19af
commit
9f956b3421
4
users.py
4
users.py
|
|
@ -34,6 +34,10 @@ import datetime
|
||||||
import queue
|
import queue
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from os import path
|
from os import path
|
||||||
|
import warnings
|
||||||
|
from cryptography.utils import CryptographyDeprecationWarning
|
||||||
|
# Suppress noisy TripleDES warnings originating from paramiko.
|
||||||
|
warnings.filterwarnings("ignore", category=CryptographyDeprecationWarning)
|
||||||
|
|
||||||
# for NLP
|
# for NLP
|
||||||
#import spacy
|
#import spacy
|
||||||
|
|
|
||||||
16
util.py
16
util.py
|
|
@ -17,17 +17,31 @@ def _ensure_parent_dir(path):
|
||||||
# Never block the open call due to directory check errors
|
# Never block the open call due to directory check errors
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Wrap builtins.open to auto-create parent folders and sanitize buffering.
|
||||||
def _open_with_dirs(file, mode='r', *args, **kwargs):
|
def _open_with_dirs(file, mode='r', *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
if isinstance(file, (str, bytes, os.PathLike)) and any(m in mode for m in ('w','a','x','+')):
|
if isinstance(file, (str, bytes, os.PathLike)) and any(m in mode for m in ('w','a','x','+')):
|
||||||
_ensure_parent_dir(file)
|
_ensure_parent_dir(file)
|
||||||
finally:
|
finally:
|
||||||
# Avoid RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode
|
# Avoid RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode
|
||||||
if 'b' in mode and kwargs.get('buffering', None) == 1:
|
args_list = None
|
||||||
|
buffering_arg = None
|
||||||
|
if args:
|
||||||
|
args_list = list(args)
|
||||||
|
buffering_arg = args_list[0]
|
||||||
|
elif 'buffering' in kwargs:
|
||||||
|
buffering_arg = kwargs['buffering']
|
||||||
|
if 'b' in mode and buffering_arg == 1:
|
||||||
|
if args_list is not None:
|
||||||
|
args_list[0] = -1
|
||||||
|
else:
|
||||||
kwargs = dict(kwargs)
|
kwargs = dict(kwargs)
|
||||||
kwargs['buffering'] = -1 # use default buffering for binary
|
kwargs['buffering'] = -1 # use default buffering for binary
|
||||||
|
if args_list is not None:
|
||||||
|
return _orig_open(file, mode, *tuple(args_list), **kwargs)
|
||||||
return _orig_open(file, mode, *args, **kwargs)
|
return _orig_open(file, mode, *args, **kwargs)
|
||||||
|
|
||||||
|
# Wrap codecs.open mirrors to ensure parent folders exist and fix buffering.
|
||||||
def _codecs_open_with_dirs(filename, mode='r', encoding=None, errors='strict', buffering=1):
|
def _codecs_open_with_dirs(filename, mode='r', encoding=None, errors='strict', buffering=1):
|
||||||
try:
|
try:
|
||||||
if isinstance(filename, (str, bytes, os.PathLike)) and any(m in mode for m in ('w','a','x','+')):
|
if isinstance(filename, (str, bytes, os.PathLike)) and any(m in mode for m in ('w','a','x','+')):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue