Skip to content

Commit

Permalink
Tidy up by formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
nolze committed Jan 5, 2024
1 parent 84a4f37 commit 82a612e
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 21 deletions.
11 changes: 7 additions & 4 deletions msoffcrypto/format/doc97.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import logging, io, shutil, tempfile
from struct import pack, unpack, unpack_from
import io
import logging
import shutil
import tempfile
from collections import namedtuple
from struct import pack, unpack, unpack_from

import olefile

Expand Down Expand Up @@ -66,7 +69,7 @@ def _parseFibBase(blob):
'0x1'
"""
getBit = lambda bits, i: (bits & (1 << i)) >> i
getBitSlice = lambda bits, i, w: (bits & (2 ** w - 1 << i)) >> i
getBitSlice = lambda bits, i, w: (bits & (2**w - 1 << i)) >> i

# https://msdn.microsoft.com/en-us/library/dd944620(v=office.12).aspx
(buf,) = unpack_from("<H", blob.read(2))
Expand Down Expand Up @@ -166,7 +169,7 @@ def _parseFibBase(blob):

def _packFibBase(fibbase):
setBit = lambda bits, i, v: (bits & ~(1 << i)) | (v << i)
setBitSlice = lambda bits, i, w, v: (bits & ~((2 ** w - 1) << i)) | ((v & (2 ** w - 1)) << i)
setBitSlice = lambda bits, i, w, v: (bits & ~((2**w - 1) << i)) | ((v & (2**w - 1)) << i)

blob = io.BytesIO()
buf = pack("<H", fibbase.wIdent)
Expand Down
15 changes: 9 additions & 6 deletions msoffcrypto/format/ppt97.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import logging, io, shutil, tempfile
from struct import pack, unpack
import io
import logging
import shutil
import tempfile
from collections import namedtuple
from struct import pack, unpack

import olefile

Expand All @@ -26,7 +29,7 @@

def _parseRecordHeader(blob):
# RecordHeader: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-ppt/df201194-0cd0-4dfb-bf10-eea353d8eabc
getBitSlice = lambda bits, i, w: (bits & (2 ** w - 1 << i)) >> i
getBitSlice = lambda bits, i, w: (bits & (2**w - 1 << i)) >> i

blob.seek(0)

Expand All @@ -48,7 +51,7 @@ def _parseRecordHeader(blob):


def _packRecordHeader(rh):
setBitSlice = lambda bits, i, w, v: (bits & ~((2 ** w - 1) << i)) | ((v & (2 ** w - 1)) << i)
setBitSlice = lambda bits, i, w, v: (bits & ~((2**w - 1) << i)) | ((v & (2**w - 1)) << i)

blob = io.BytesIO()

Expand Down Expand Up @@ -312,7 +315,7 @@ def _packUserEditAtom(usereditatom):

def _parsePersistDirectoryEntry(blob):
# PersistDirectoryEntry: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-ppt/6214b5a6-7ca2-4a86-8a0e-5fd3d3eff1c9
getBitSlice = lambda bits, i, w: (bits & (2 ** w - 1 << i)) >> i
getBitSlice = lambda bits, i, w: (bits & (2**w - 1 << i)) >> i

(buf,) = unpack("<I", blob.read(4))
persistId = getBitSlice(buf, 0, 20)
Expand All @@ -337,7 +340,7 @@ def _parsePersistDirectoryEntry(blob):


def _packPersistDirectoryEntry(directoryentry):
setBitSlice = lambda bits, i, w, v: (bits & ~((2 ** w - 1) << i)) | ((v & (2 ** w - 1)) << i)
setBitSlice = lambda bits, i, w, v: (bits & ~((2**w - 1) << i)) | ((v & (2**w - 1)) << i)

blob = io.BytesIO()

Expand Down
7 changes: 5 additions & 2 deletions msoffcrypto/format/xls97.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import logging, io, shutil, tempfile
from struct import pack, unpack
import io
import logging
import shutil
import tempfile
from collections import namedtuple
from struct import pack, unpack

import olefile

Expand Down
1 change: 1 addition & 0 deletions msoffcrypto/method/ecma376_agile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"SHA512": sha512,
}


def _get_hash_func(algorithm):
return ALGORITHM_HASH.get(algorithm, sha1)

Expand Down
2 changes: 1 addition & 1 deletion msoffcrypto/method/ecma376_standard.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import io
import logging
from hashlib import sha1
from struct import pack, unpack

Expand Down
4 changes: 3 additions & 1 deletion msoffcrypto/method/rc4.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import functools, io, logging
import functools
import io
import logging
from hashlib import md5
from struct import pack

Expand Down
4 changes: 3 additions & 1 deletion msoffcrypto/method/rc4_cryptoapi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import functools, io, logging
import functools
import io
import logging
from hashlib import sha1
from struct import pack

Expand Down
8 changes: 4 additions & 4 deletions tests/test_compare_known_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

"""Compare output of msoffcrypto-tool for a few input files."""

import os
import sys
import unittest
import os
from os.path import dirname, abspath, isfile, join as pjoin
from tempfile import mkstemp
from difflib import SequenceMatcher
from os.path import abspath, dirname, isfile
from os.path import join as pjoin
from tempfile import mkstemp

try:
import cryptography
Expand All @@ -21,7 +22,6 @@
sys.path.insert(0, MODULE_BASE_DIR)
import msoffcrypto


#: encryption password for files tested here
PASSWORD = "Password1234_"

Expand Down
3 changes: 1 addition & 2 deletions tests/test_file_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@


import unittest
from os.path import join, dirname
from os.path import dirname, join

from msoffcrypto import OfficeFile


#: directory with input
DATA_DIR = join(dirname(__file__), "inputs")

Expand Down

0 comments on commit 82a612e

Please sign in to comment.