Commit 95bce4ed by Craig Heffner

Added check for backports.lzma when importing lzma module

parent c2cec5f6
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
import os import os
import zlib import zlib
import lzma
import struct import struct
import binwalk.core.compat import binwalk.core.compat
import binwalk.core.common import binwalk.core.common
from binwalk.core.module import Option, Kwarg, Module from binwalk.core.module import Option, Kwarg, Module
try:
import lzma
except ImportError:
from backports import lzma
class LZMAHeader(object): class LZMAHeader(object):
def __init__(self, **kwargs): def __init__(self, **kwargs):
......
...@@ -12,7 +12,11 @@ class LZMAExtractPlugin(binwalk.core.plugin.Plugin): ...@@ -12,7 +12,11 @@ class LZMAExtractPlugin(binwalk.core.plugin.Plugin):
# lzma package in Python 2.0 decompress() does not handle multiple # lzma package in Python 2.0 decompress() does not handle multiple
# compressed streams, only first stream is extracted. # compressed streams, only first stream is extracted.
# backports.lzma package could be used to keep consistent behaviour. # backports.lzma package could be used to keep consistent behaviour.
try:
import lzma import lzma
except ImportError:
from backports import lzma
self.decompressor = lzma.decompress self.decompressor = lzma.decompress
# If the extractor is enabled for the module we're currently loaded # If the extractor is enabled for the module we're currently loaded
......
...@@ -17,7 +17,10 @@ class LZMAPlugin(binwalk.core.plugin.Plugin): ...@@ -17,7 +17,10 @@ class LZMAPlugin(binwalk.core.plugin.Plugin):
def init(self): def init(self):
try: try:
try:
import lzma import lzma
except ImportError:
from backports import lzma
self.decompressor = lzma.decompress self.decompressor = lzma.decompress
except ImportError as e: except ImportError as e:
self.decompressor = None self.decompressor = None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment