@@ -572,27 +572,6 @@ def init(self):
572
572
573
573
# class _BZ2Proxy
574
574
575
- class _XZProxy (_CMPProxy ):
576
- """Small proxy class that enables external file object
577
- support for "r:xz" and "w:xz" modes.
578
- """
579
-
580
- def __init__ (self , fileobj , mode ):
581
- _CMPProxy .__init__ (self , fileobj , mode )
582
- self .init ()
583
-
584
- def init (self ):
585
- import lzma
586
- self .pos = 0
587
- if self .mode == "r" :
588
- self .cmpobj = lzma .BZ2Decompressor ()
589
- self .fileobj .seek (0 )
590
- self .buf = b""
591
- else :
592
- self .cmpobj = lzma .BZ2Compressor ()
593
-
594
- # class _XZProxy
595
-
596
575
597
576
#------------------------
598
577
# Extraction file object
@@ -1162,11 +1141,13 @@ def xzopen(cls, name, mode="r", fileobj=None, compresslevel=6):
1162
1141
raise CompressionError ("lzma module is not available" )
1163
1142
1164
1143
if fileobj is not None :
1165
- fileobj = _XZProxy (fileobj , mode )
1166
- else :
1167
- # FIXME: not compatible with python3 API
1168
- fileobj = lzma .LZMAFile (name , mode , options = {'level' : compresslevel , 'dict_size' : 20 })
1169
-
1144
+ raise CompressionError ("passing fileobj not implemented for LZMA" )
1145
+ kwargs = {}
1146
+ if sys .version_info < (3 , 0 ):
1147
+ kwargs ["options" ] = {"level" : compresslevel }
1148
+ elif "w" in mode :
1149
+ kwargs ["preset" ] = compresslevel
1150
+ fileobj = lzma .LZMAFile (name , mode , ** kwargs )
1170
1151
try :
1171
1152
t = cls .cpioopen (name , mode , fileobj )
1172
1153
except IOError :
@@ -1179,7 +1160,7 @@ def xzopen(cls, name, mode="r", fileobj=None, compresslevel=6):
1179
1160
"cpio" : "cpioopen" , # uncompressed cpio
1180
1161
"gz" : "gzopen" , # gzip compressed cpio
1181
1162
"bz2" : "bz2open" , # bzip2 compressed cpio
1182
- "xz" : "xzopen " # xz compressed cpio
1163
+ "xz" : "xzopen" , # xz compressed cpio
1183
1164
}
1184
1165
1185
1166
#--------------------------------------------------------------------------
0 commit comments