Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump jinja to 3.1.5. #560

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ofrak_core/ofrak/core/binwalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ofrak.component.analyzer import Analyzer

try:
import binwalk
import binwalk_package

BINWALK_INSTALLED = True
except ImportError:
Expand Down Expand Up @@ -72,7 +72,7 @@ async def analyze(self, resource: Resource, config=None) -> BinwalkAttributes:

def _run_binwalk_on_file(filename): # pragma: no cover
offsets = dict()
for module in binwalk.scan(filename, signature=True):
for module in binwalk_package.scan(filename, signature=True):
for result in module.results:
offsets[result.offset] = result.description
return offsets
10 changes: 5 additions & 5 deletions ofrak_core/ofrak/core/gzip.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import logging
from typing import Optional
import zlib
import zlib as zlib_package
from subprocess import CalledProcessError
import tempfile312 as tempfile

Expand All @@ -18,7 +18,7 @@
# PIGZ provides significantly faster compression on multi core systems.
# It does not parallelize decompression, so we don't use it in GzipUnpacker.
PIGZ = ComponentExternalTool(
"pigz", "https://zlib.net/pigz/", "--help", apt_package="pigz", brew_package="pigz"
"pigz", "https://zlib_package.net/pigz/", "--help", apt_package="pigz", brew_package="pigz"
)


Expand Down Expand Up @@ -58,7 +58,7 @@ async def unpack(self, resource: Resource, config=None):

@staticmethod
async def unpack_with_zlib_module(data: bytes) -> bytes:
# We use zlib.decompressobj instead of the gzip module to decompress
# We use zlib_package.decompressobj instead of the gzip module to decompress
# because of a bug that causes gzip to raise BadGzipFile if there's
# trailing garbage after a compressed file instead of correctly ignoring it
# https://github.com/python/cpython/issues/68489
Expand All @@ -69,7 +69,7 @@ async def unpack_with_zlib_module(data: bytes) -> bytes:
chunks = []
while data.startswith(b"\037\213"):
# wbits > 16 handles the gzip header and footer
decompressor = zlib.decompressobj(wbits=16 + zlib.MAX_WBITS)
decompressor = zlib_package.decompressobj(wbits=16 + zlib_package.MAX_WBITS)
chunks.append(decompressor.decompress(data))
if not decompressor.eof:
raise ValueError("Incomplete gzip file")
Expand Down Expand Up @@ -103,7 +103,7 @@ async def pack(self, resource: Resource, config=None):

@staticmethod
async def pack_with_zlib_module(data: bytes) -> bytes:
compressor = zlib.compressobj(wbits=16 + zlib.MAX_WBITS)
compressor = zlib_package.compressobj(wbits=16 + zlib_package.MAX_WBITS)
result = compressor.compress(data)
result += compressor.flush()
return result
Expand Down
22 changes: 11 additions & 11 deletions ofrak_core/ofrak/core/lzma.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import lzma
import lzma as lzma_package
from io import BytesIO
from typing import Union

Expand Down Expand Up @@ -43,29 +43,29 @@ class LzmaUnpacker(Unpacker[None]):
async def unpack(self, resource: Resource, config=None):
file_data = BytesIO(await resource.get_data())

format = lzma.FORMAT_AUTO
format = lzma_package.FORMAT_AUTO

if resource.has_tag(XzData):
format = lzma.FORMAT_XZ
format = lzma_package.FORMAT_XZ
elif resource.has_tag(LzmaData):
format = lzma.FORMAT_ALONE
format = lzma_package.FORMAT_ALONE

lzma_entry_data = None
compressed_data = file_data.read()

try:
lzma_entry_data = lzma.decompress(compressed_data, format)
except lzma.LZMAError:
lzma_entry_data = lzma_package.decompress(compressed_data, format)
except lzma_package.LZMAError:
LOGGER.info("Initial LZMA decompression failed. Trying with null bytes stripped")
lzma_entry_data = lzma.decompress(compressed_data.rstrip(b"\x00"), format)
lzma_entry_data = lzma_package.decompress(compressed_data.rstrip(b"\x00"), format)

if lzma_entry_data is not None:
await resource.create_child(
tags=(GenericBinary,),
data=lzma_entry_data,
)
else:
raise lzma.LZMAError("Decompressed LZMA data is null")
raise lzma_package.LZMAError("Decompressed LZMA data is null")


class LzmaPacker(Packer[None]):
Expand All @@ -80,18 +80,18 @@ async def pack(self, resource: Resource, config=None):
lzma_file: Union[XzData, LzmaData] = await resource.view_as(tag)

lzma_child = await lzma_file.get_child()
lzma_compressed = lzma.compress(await lzma_child.resource.get_data(), lzma_format)
lzma_compressed = lzma_package.compress(await lzma_child.resource.get_data(), lzma_format)

original_size = await lzma_file.resource.get_data_length()
resource.queue_patch(Range(0, original_size), lzma_compressed)

async def _get_lzma_format_and_tag(self, resource):
if resource.has_tag(XzData):
tag = XzData
lzma_format = lzma.FORMAT_XZ
lzma_format = lzma_package.FORMAT_XZ
elif resource.has_tag(LzmaData):
tag = LzmaData
lzma_format = lzma.FORMAT_ALONE
lzma_format = lzma_package.FORMAT_ALONE
else:
raise TypeError(
f"Expected target of {self.get_id().decode()} to be either XzFile or LzmaFile"
Expand Down
6 changes: 3 additions & 3 deletions ofrak_core/ofrak/core/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ofrak.component.abstract import ComponentMissingDependencyError

try:
import magic
import magic_package

MAGIC_INSTALLED = True
except ImportError:
Expand Down Expand Up @@ -68,8 +68,8 @@ async def analyze(self, resource: Resource, config=None) -> Magic:
if not MAGIC_INSTALLED:
raise ComponentMissingDependencyError(self, LIBMAGIC_DEP)
else:
magic_mime = magic.from_buffer(data, mime=True)
magic_description = magic.from_buffer(data)
magic_mime = magic_package.from_buffer(data, mime=True)
magic_description = magic_package.from_buffer(data)
return Magic(magic_mime, magic_description)


Expand Down
6 changes: 3 additions & 3 deletions ofrak_core/ofrak/core/openwrt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import io
import struct
import zlib
import zlib as zlib_package
from dataclasses import dataclass
from enum import Enum
from typing import Optional, List
Expand Down Expand Up @@ -370,6 +370,6 @@ def openwrt_crc32(data: bytes) -> int:
Calculate CRC32 a-la OpenWrt. Original implementation:
<https://git.archive.openwrt.org/?p=14.07/openwrt.git;a=blob;f=tools/firmware-utils/src/trx.c>

Implements CRC-32 Ethernet which requires XOR'ing the zlib.crc32 result with 0xFFFFFFFF
Implements CRC-32 Ethernet which requires XOR'ing the zlib_package.crc32 result with 0xFFFFFFFF
"""
return (zlib.crc32(data) & 0xFFFFFFFF) ^ 0xFFFFFFFF
return (zlib_package.crc32(data) & 0xFFFFFFFF) ^ 0xFFFFFFFF
6 changes: 3 additions & 3 deletions ofrak_core/ofrak/core/uimage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import io
import struct
import zlib
import zlib as zlib_package
from dataclasses import dataclass
from enum import Enum
from typing import Optional, Tuple, Iterable, List
Expand Down Expand Up @@ -477,7 +477,7 @@ async def modify(self, resource: Resource, config: UImageHeaderModifierConfig) -
new_attributes = ResourceAttributes.replace_updated(original_attributes, config)
tmp_serialized_header = await UImageHeaderModifier.serialize(new_attributes, ih_hcrc=0)
# Patch this header with its CRC32 in the ih_hcrc field
ih_hcrc = zlib.crc32(tmp_serialized_header)
ih_hcrc = zlib_package.crc32(tmp_serialized_header)
serialized_header = await UImageHeaderModifier.serialize(new_attributes, ih_hcrc=ih_hcrc)
resource.queue_patch(Range.from_size(0, UIMAGE_HEADER_LEN), serialized_header)
new_attributes = ResourceAttributes.replace_updated(
Expand Down Expand Up @@ -590,7 +590,7 @@ async def pack(self, resource: Resource, config=None):
)
repacked_body_data += await trailing_bytes_r.resource.get_data()
ih_size = len(repacked_body_data)
ih_dcrc = zlib.crc32(repacked_body_data)
ih_dcrc = zlib_package.crc32(repacked_body_data)
header_modifier_config = UImageHeaderModifierConfig(ih_size=ih_size, ih_dcrc=ih_dcrc)
await header.resource.run(UImageHeaderModifier, header_modifier_config)
# Patch UImageHeader data
Expand Down
6 changes: 3 additions & 3 deletions ofrak_core/ofrak/core/zlib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import zlib
import zlib as zlib_package
from dataclasses import dataclass

from ofrak.component.analyzer import Analyzer
Expand Down Expand Up @@ -53,7 +53,7 @@ class ZlibUnpacker(Unpacker[None]):

async def unpack(self, resource: Resource, config=None):
zlib_data = await resource.get_data()
zlib_uncompressed_data = zlib.decompress(zlib_data)
zlib_uncompressed_data = zlib_package.decompress(zlib_data)
await resource.create_child(
tags=(GenericBinary,),
data=zlib_uncompressed_data,
Expand All @@ -72,7 +72,7 @@ async def pack(self, resource: Resource, config=None):
compression_level = zlib_view.compression_level
zlib_child = await zlib_view.get_child()
zlib_data = await zlib_child.resource.get_data()
zlib_compressed = zlib.compress(zlib_data, compression_level)
zlib_compressed = zlib_package.compress(zlib_data, compression_level)

original_zlib_size = await zlib_view.resource.get_data_length()
resource.queue_patch(Range(0, original_zlib_size), zlib_compressed)
Expand Down
10 changes: 5 additions & 5 deletions ofrak_core/requirements-docs.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
mkdocs==1.2.3
mkdocs-autorefs==0.3.0
mkdocstrings==0.16.2
mkdocs==1.5.3
mkdocs-autorefs>=1.2
mkdocs-gen-files==0.3.3
mkdocs-literate-nav==0.4.0
mkdocs-material==7.3.3
mkdocs_gen_files==0.3.3
jinja2==3.0.0
mkdocstrings[python]>=0.18
jinja2==3.1.5
pytkdocs>=0.12.0
PyYAML>=5.4
Loading