mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 09:49:33 +08:00
change: open file in binary mode
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
**Changed**
|
**Changed**
|
||||||
|
|
||||||
- change: import locust at beginning to monkey patch all modules
|
- change: import locust at beginning to monkey patch all modules
|
||||||
|
- change: open file in binary mode
|
||||||
|
|
||||||
## 3.1.1 (2020-06-23)
|
## 3.1.1 (2020-06-23)
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ def load_har_log_entries(file_path):
|
|||||||
]
|
]
|
||||||
|
|
||||||
"""
|
"""
|
||||||
with open(file_path, encoding="utf-8") as f:
|
with open(file_path, mode="rb") as f:
|
||||||
try:
|
try:
|
||||||
content_json = json.loads(f.read())
|
content_json = json.load(f)
|
||||||
return content_json["log"]["entries"]
|
return content_json["log"]["entries"]
|
||||||
except (TypeError, JSONDecodeError) as ex:
|
except (TypeError, JSONDecodeError) as ex:
|
||||||
logger.error(f"failed to load HAR file {file_path}: {ex}")
|
logger.error(f"failed to load HAR file {file_path}: {ex}")
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ project_meta: Union[ProjectMeta, None] = None
|
|||||||
def _load_yaml_file(yaml_file: Text) -> Dict:
|
def _load_yaml_file(yaml_file: Text) -> Dict:
|
||||||
""" load yaml file and check file content format
|
""" load yaml file and check file content format
|
||||||
"""
|
"""
|
||||||
with open(yaml_file, encoding="utf-8") as stream:
|
with open(yaml_file, mode="rb") as stream:
|
||||||
try:
|
try:
|
||||||
yaml_content = yaml.load(stream)
|
yaml_content = yaml.load(stream)
|
||||||
except yaml.YAMLError as ex:
|
except yaml.YAMLError as ex:
|
||||||
@@ -42,7 +42,7 @@ def _load_yaml_file(yaml_file: Text) -> Dict:
|
|||||||
def _load_json_file(json_file: Text) -> Dict:
|
def _load_json_file(json_file: Text) -> Dict:
|
||||||
""" load json file and check file content format
|
""" load json file and check file content format
|
||||||
"""
|
"""
|
||||||
with open(json_file, encoding="utf-8") as data_file:
|
with open(json_file, mode="rb") as data_file:
|
||||||
try:
|
try:
|
||||||
json_content = json.load(data_file)
|
json_content = json.load(data_file)
|
||||||
except json.JSONDecodeError as ex:
|
except json.JSONDecodeError as ex:
|
||||||
@@ -127,17 +127,17 @@ def load_dot_env_file(dot_env_path: Text) -> Dict:
|
|||||||
logger.info(f"Loading environment variables from {dot_env_path}")
|
logger.info(f"Loading environment variables from {dot_env_path}")
|
||||||
env_variables_mapping = {}
|
env_variables_mapping = {}
|
||||||
|
|
||||||
with open(dot_env_path, encoding="utf-8") as fp:
|
with open(dot_env_path, mode="rb") as fp:
|
||||||
for line in fp:
|
for line in fp:
|
||||||
# maxsplit=1
|
# maxsplit=1
|
||||||
if "=" in line:
|
if b"=" in line:
|
||||||
variable, value = line.split("=", 1)
|
variable, value = line.split(b"=", 1)
|
||||||
elif ":" in line:
|
elif b":" in line:
|
||||||
variable, value = line.split(":", 1)
|
variable, value = line.split(b":", 1)
|
||||||
else:
|
else:
|
||||||
raise exceptions.FileFormatError(".env format error")
|
raise exceptions.FileFormatError(".env format error")
|
||||||
|
|
||||||
env_variables_mapping[variable.strip()] = value.strip()
|
env_variables_mapping[variable.strip().decode("utf-8")] = value.strip().decode("utf-8")
|
||||||
|
|
||||||
utils.set_os_environ(env_variables_mapping)
|
utils.set_os_environ(env_variables_mapping)
|
||||||
return env_variables_mapping
|
return env_variables_mapping
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ def create_scaffold(project_name):
|
|||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
def create_file(path, file_content=""):
|
def create_file(path, file_content=""):
|
||||||
with open(path, "w") as f:
|
with open(path, "w", encoding="utf-8") as f:
|
||||||
f.write(file_content)
|
f.write(file_content)
|
||||||
msg = f"created file: {path}"
|
msg = f"created file: {path}"
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user