Skip to content

Commit

Permalink
test: address lint problems
Browse files Browse the repository at this point in the history
Signed-off-by: James Chien <[email protected]>
  • Loading branch information
shc261392 committed Apr 22, 2024
1 parent d05efeb commit fdd37a9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ disable=
too-few-public-methods,
too-many-public-methods,
too-many-arguments,
unspecified-encoding,

[flake8]
max-line-length = 120
Expand Down
22 changes: 11 additions & 11 deletions src/numbers_c2pa/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import mimetypes
import os
import subprocess
import subprocess # nosec
from datetime import datetime
from tempfile import TemporaryDirectory
from typing import Any, Dict, List, Optional
Expand Down Expand Up @@ -42,9 +42,9 @@ def c2patool_inject(
env=env_vars,
check=True,
stderr=subprocess.PIPE,
)
) # nosec
except subprocess.CalledProcessError as e:
raise UnknownError(e.stderr)
raise UnknownError(e.stderr) from e


def create_c2pa_manifest(
Expand Down Expand Up @@ -219,7 +219,7 @@ def inject_file(
with TemporaryDirectory() as temp_dir:
if thumbnail_url:
thumbnail_file_path = os.path.join(temp_dir, 'thumbnail.jpg')
response = requests.get(thumbnail_url, stream=True)
response = requests.get(thumbnail_url, stream=True, timeout=120)
response.raise_for_status()
with open(thumbnail_file_path, 'wb') as thumbnail_file:
for chunk in response.iter_content(chunk_size=8192):
Expand All @@ -232,7 +232,7 @@ def inject_file(

# Save the manifest to a temporary file
manifest_file_path = os.path.join(temp_dir, 'manifest.json')
with open(manifest_file_path, 'w') as manifest_file:
with open(manifest_file_path, 'w',) as manifest_file:
json.dump(manifest, manifest_file)
manifest_file.flush()

Expand All @@ -254,25 +254,25 @@ def read_c2pa(asset_c2pa_bytes: bytes, asset_mime_type: str):
f.write(asset_c2pa_bytes)

command = ['c2patool', asset_c2pa_file]
process = subprocess.run(command, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
process = subprocess.run(
command, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False
) # nosec
if process.returncode != 0:
if 'No claim found' in process.stderr:
raise NoClaimFound
else:
raise UnknownError(process.stderr)
raise UnknownError(process.stderr)

json_output = json.loads(process.stdout)
return json_output


def read_c2pa_file(c2pa_file: str):
command = ['c2patool', c2pa_file]
process = subprocess.run(command, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False)
process = subprocess.run(command, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=False) # nosec
if process.returncode != 0:
if 'No claim found' in process.stderr:
raise NoClaimFound
else:
raise UnknownError(process.stderr)
raise UnknownError(process.stderr)

json_output = json.loads(process.stdout)
return json_output
2 changes: 1 addition & 1 deletion src/numbers_c2pa/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def create_self_signed_certificate(private_key_pem, output_file='es256_certs.pem
.not_valid_before(datetime.datetime.utcnow())
.not_valid_after(datetime.datetime.utcnow() + datetime.timedelta(days=365))
.add_extension(
x509.SubjectAlternativeName([x509.DNSName(u"my-organization.com")]),
x509.SubjectAlternativeName([x509.DNSName('my-organization.com')]),
critical=False,
)
.add_extension(
Expand Down

0 comments on commit fdd37a9

Please sign in to comment.