From bfa866c6d43b128c846e9dc3b15c4f93a7cfce1a Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Sat, 5 Aug 2023 16:28:49 +0000 Subject: [PATCH] 'Refactored by Sourcery' --- examples/StringEncryptIsDemo.py | 20 +------------------- stringencrypt/stringencrypt.py | 8 +++----- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/examples/StringEncryptIsDemo.py b/examples/StringEncryptIsDemo.py index 584c14d..24a034d 100644 --- a/examples/StringEncryptIsDemo.py +++ b/examples/StringEncryptIsDemo.py @@ -29,25 +29,7 @@ # myStringEncrypt = StringEncrypt("ABCD-ABCD-ABCD-ABCD") -# -# login to the service -# -result = myStringEncrypt.is_demo() - -# -# result[] array holds the information about the license -# -# result["demo"] (boolean) - demo mode flag -# result["label_limit"] (int) - label limit length -# result["string_limit"] (int) - string limit length -# result["bytes_limit"] (int) - bytes/file limit length -# result["credits_left"] (int) - number of credits left -# result["credits_total"] (int) - initial number of credits -# result["cmd_min"] (int) - minimum number of encryption commands -# result["cmd_max"] (int) - maximum number of encryption commands -# -if result: - +if result := myStringEncrypt.is_demo(): print(f'Demo version status - {"True" if result["demo"] else "False"}') print(f'Label length limit - {result["label_limit"]}') diff --git a/stringencrypt/stringencrypt.py b/stringencrypt/stringencrypt.py index 1bf095d..73f8e8a 100644 --- a/stringencrypt/stringencrypt.py +++ b/stringencrypt/stringencrypt.py @@ -274,13 +274,11 @@ def encrypt_file_contents(self, file_path, label): :rtype: bool,dict """ - source_file = open(file_path, 'rb') - bytes = source_file.read() - source_file.close() - + with open(file_path, 'rb') as source_file: + bytes = source_file.read() if not bytes: return False - + # additional parameters params_array = {"command": "encrypt", "bytes": bytes, "label": label}