1515from commoncode import filetype
1616from commoncode import functional
1717from commoncode .ignore import is_ignored
18-
1918from typecode import contenttype
2019
2120from extractcode import all_kinds
@@ -204,7 +203,9 @@ def get_handlers(location):
204203 mtype = T .mimetype_file
205204
206205 if TRACE_DEEP :
207- logger .debug ('get_handlers: processing %(location)s: ftype: %(ftype)s, mtype: %(mtype)s ' % locals ())
206+ logger .debug (
207+ 'get_handlers: processing %(location)s: '
208+ 'ftype: %(ftype)s, mtype: %(mtype)s ' % locals ())
208209 for handler in archive_handlers :
209210 if not handler .extractors :
210211 continue
@@ -223,9 +224,19 @@ def get_handlers(location):
223224 extension_matched = exts and location .lower ().endswith (exts )
224225
225226 if TRACE_DEEP :
226- print (f' get_handlers: matched type: { type_matched } , mime: { mime_matched } , ext: { extension_matched } ' % locals ())
227-
228- if handler .strict and not (type_matched and mime_matched and extension_matched ):
227+ print (
228+ f' get_handlers: matched type: { type_matched } , '
229+ f'mime: { mime_matched } , ext: { extension_matched } ' % locals ()
230+ )
231+
232+ if (
233+ handler .strict
234+ and not (
235+ type_matched
236+ and mime_matched
237+ and extension_matched
238+ )
239+ ):
229240 if TRACE_DEEP :
230241 print (f' get_handlers: skip strict: { handler .name } ' )
231242 continue
@@ -449,17 +460,30 @@ def try_to_extract(location, target_dir, extractor):
449460
450461extract_deb = libarchive2 .extract
451462
452- # sevenzip is best for windows lib formats and works fine otherwise. libarchive works on standard ar formats.
453- extract_ar = functional .partial (extract_with_fallback , extractor1 = libarchive2 .extract , extractor2 = sevenzip .extract )
463+ # sevenzip is best for windows lib formats and works fine otherwise. libarchive
464+ # works on standard ar formats.
465+ extract_ar = functional .partial (
466+ extract_with_fallback ,
467+ extractor1 = libarchive2 .extract ,
468+ extractor2 = sevenzip .extract ,
469+ )
454470
455471extract_msi = sevenzip .extract
456472extract_cpio = libarchive2 .extract
457473
458474# sevenzip should be best at extracting 7zip but most often libarchive is better first
459- extract_7z = functional .partial (extract_with_fallback , extractor1 = libarchive2 .extract , extractor2 = sevenzip .extract )
475+ extract_7z = functional .partial (
476+ extract_with_fallback ,
477+ extractor1 = libarchive2 .extract ,
478+ extractor2 = sevenzip .extract ,
479+ )
460480
461481# libarchive is best for the run of the mill zips, but sevenzip sometimes is better
462- extract_zip = functional .partial (extract_with_fallback , extractor1 = libarchive2 .extract , extractor2 = sevenzip .extract )
482+ extract_zip = functional .partial (
483+ extract_with_fallback ,
484+ extractor1 = libarchive2 .extract ,
485+ extractor2 = sevenzip .extract ,
486+ )
463487
464488extract_springboot = functional .partial (try_to_extract , extractor = extract_zip )
465489
@@ -515,7 +539,12 @@ def try_to_extract(location, target_dir, extractor):
515539
516540OfficeDocHandler = Handler (
517541 name = 'Office doc' ,
518- filetypes = ('zip archive' , 'microsoft word 2007+' , 'microsoft excel 2007+' , 'microsoft powerpoint 2007+' ),
542+ filetypes = (
543+ 'zip archive' ,
544+ 'microsoft word 2007+' ,
545+ 'microsoft excel 2007+' ,
546+ 'microsoft powerpoint 2007+' ,
547+ ),
519548 mimetypes = ('application/zip' , 'application/vnd.openxmlformats' ,),
520549 # Extensions of office documents that are zip files too
521550 extensions = (
@@ -553,7 +582,7 @@ def try_to_extract(location, target_dir, extractor):
553582 strict = True
554583)
555584
556- # see http://tools.android.com/tech-docs/new-build-system/aar-formats
585+ # see http://tools.android.com/tech-docs/new-build-system/aar-formats
557586AndroidLibHandler = Handler (
558587 name = 'Android library' ,
559588 filetypes = ('zip archive' ,),
@@ -827,8 +856,16 @@ def try_to_extract(location, target_dir, extractor):
827856 name = 'Tar bzip2' ,
828857 filetypes = ('bzip2 compressed' ,),
829858 mimetypes = ('application/x-bzip2' ,),
830- extensions = ('.tar.bz2' , '.tar.bz' , '.tar.bzip' , '.tar.bzip2' ,
831- '.tbz' , '.tbz2' , '.tb2' , '.tarbz2' ,),
859+ extensions = (
860+ '.tar.bz2' ,
861+ '.tar.bz' ,
862+ '.tar.bzip' ,
863+ '.tar.bzip2' ,
864+ '.tbz' ,
865+ '.tbz2' ,
866+ '.tb2' ,
867+ '.tarbz2' ,
868+ ),
832869 kind = regular_nested ,
833870 extractors = [extract_tar ],
834871 strict = False
@@ -876,10 +913,11 @@ def try_to_extract(location, target_dir, extractor):
876913
877914NugetHandler = Handler (
878915 name = 'Nuget' ,
879- # weirdly enough the detection by libmagic is sometimes wrong
880- # TODO file a bug upstream
881- # this is due to this: https://en.wikipedia.org/wiki/Open_Packaging_Conventions#File_formats_using_the_OPC
916+ # TODO: file a bug upstream
917+ # Weirdly enough the detection by libmagic is sometimes wrong
918+ # this is due to this issue:
882919 # being recognized by libmagic as an OOXML file
920+ # https://en.wikipedia.org/wiki/Open_Packaging_Conventions#File_formats_using_the_OPC
883921 filetypes = ('zip archive' , 'microsoft ooxml' ,),
884922 mimetypes = ('application/zip' , 'application/octet-stream' ,),
885923 extensions = ('.nupkg' ,),
@@ -921,7 +959,10 @@ def try_to_extract(location, target_dir, extractor):
921959DebHandler = Handler (
922960 name = 'Debian package' ,
923961 filetypes = ('debian binary package' ,),
924- mimetypes = ('application/vnd.debian.binary-package' , 'application/x-archive' ,),
962+ mimetypes = (
963+ 'application/vnd.debian.binary-package' ,
964+ 'application/x-archive' ,
965+ ),
925966 extensions = ('.deb' , '.udeb' ,),
926967 kind = package ,
927968 extractors = [extract_deb ],
0 commit comments