mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	Retouch my last change after a comment on style from Guido.
This commit is contained in:
		
							parent
							
								
									0f98d8f8ea
								
							
						
					
					
						commit
						ead70565fc
					
				
					 1 changed files with 7 additions and 10 deletions
				
			
		
							
								
								
									
										15
									
								
								Lib/gzip.py
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								Lib/gzip.py
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -149,18 +149,15 @@ def _init_write(self, filename):
 | 
			
		|||
    def _write_gzip_header(self):
 | 
			
		||||
        self.fileobj.write(b'\037\213')             # magic header
 | 
			
		||||
        self.fileobj.write(b'\010')                 # compression method
 | 
			
		||||
        fname = self.name
 | 
			
		||||
        if fname.endswith(".gz"):
 | 
			
		||||
            fname = fname[:-3]
 | 
			
		||||
        flags = 0
 | 
			
		||||
 | 
			
		||||
        try:
 | 
			
		||||
            # RFC 1952 requires the FNAME field to be Latin-1. Do not
 | 
			
		||||
            # include filenames that cannot be represented that way.
 | 
			
		||||
        try:
 | 
			
		||||
            fname = fname.encode('latin-1')
 | 
			
		||||
            fname = self.name.encode('latin-1')
 | 
			
		||||
            if fname.endswith(b'.gz'):
 | 
			
		||||
                fname = fname[:-3]
 | 
			
		||||
        except UnicodeEncodeError:
 | 
			
		||||
            fname = ''
 | 
			
		||||
 | 
			
		||||
            fname = b''
 | 
			
		||||
        flags = 0
 | 
			
		||||
        if fname:
 | 
			
		||||
            flags = FNAME
 | 
			
		||||
        self.fileobj.write(chr(flags).encode('latin-1'))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue