From fc06999e0b7cd7460565f475e568a86915ec8672 Mon Sep 17 00:00:00 2001 From: R David Murray Date: Fri, 13 Dec 2013 20:52:19 -0500 Subject: #19970: Fix some comment typos. Report and patch by Vajrasky Kok. --- Lib/test/test_signal.py | 2 +- Modules/faulthandler.c | 2 +- Modules/posixmodule.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py index 9b4ba50..191d4cf 100644 --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -825,7 +825,7 @@ class PendingSignalsTests(unittest.TestCase): # Unblock SIGUSR1 try: - # unblock the pending signal calls immediatly the signal handler + # unblock the pending signal calls immediately the signal handler signal.pthread_sigmask(signal.SIG_UNBLOCK, [signum]) except ZeroDivisionError: pass diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index c86a27f..680f630 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -301,7 +301,7 @@ faulthandler_fatal_error(int signum) return; } #endif - /* call the previous signal handler: it is called immediatly if we use + /* call the previous signal handler: it is called immediately if we use sigaction() thanks to SA_NODEFER flag, otherwise it is deferred */ raise(signum); } diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index f3234a4..f97d70b 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1742,7 +1742,7 @@ win32_xstat_impl(const char *path, struct win32_stat *result, /* FILE_FLAG_BACKUP_SEMANTICS is required to open a directory */ /* FILE_FLAG_OPEN_REPARSE_POINT does not follow the symlink. Because of this, calls like GetFinalPathNameByHandle will return - the symlink path agin and not the actual final path. */ + the symlink path again and not the actual final path. */ FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS| FILE_FLAG_OPEN_REPARSE_POINT, NULL); @@ -1838,7 +1838,7 @@ win32_xstat_impl_w(const wchar_t *path, struct win32_stat *result, /* FILE_FLAG_BACKUP_SEMANTICS is required to open a directory */ /* FILE_FLAG_OPEN_REPARSE_POINT does not follow the symlink. Because of this, calls like GetFinalPathNameByHandle will return - the symlink path agin and not the actual final path. */ + the symlink path again and not the actual final path. */ FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS| FILE_FLAG_OPEN_REPARSE_POINT, NULL); -- cgit v0.12 or
path: root/Demo/zlib/minigzip.py
blob: 0bfe355c4b7f4165e30be4417bd7a05377a854e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/local/bin/python
# Demo program for zlib; it compresses or decompresses files, but *doesn't*
# delete the original.  This doesn't support all of gzip's options.

FTEXT, FHCRC, FEXTRA, FNAME, FCOMMENT = 1, 2, 4, 8, 16

def write32(output, value):
    output.write(chr(value & 255)) ; value=value / 256
    output.write(chr(value & 255)) ; value=value / 256
    output.write(chr(value & 255)) ; value=value / 256
    output.write(chr(value & 255))
    
def read32(input):
    v=ord(input.read(1))
    v=v+ (ord(input.read(1))<<8 )
    v=v+ (ord(input.read(1))<<16)
    v=v+ (ord(input.read(1))<<24)
    return v

import zlib, sys
if len(sys.argv)!=2:
   print 'Usage: minigzip.py <filename>'
   print '  The file will be compressed or decompressed.'
   sys.exit(0)

filename=sys.argv[1]
compressing=1 ; outputname=filename+'.gz'
if filename[-3:]=='.gz':
    compressing=0 ; outputname=filename[:-3]
input=open(filename) ; output=open(outputname, 'w')

if compressing:
    output.write('\037\213\010')        # Write the header, ...
    output.write(chr(FNAME))		# ... flag byte ...

    import os				# ... modification time ...
    statval=os.stat(filename)
    mtime=statval[8]
    write32(output, mtime)
    output.write('\002')		# ... slowest compression alg. ...
    output.write('\377')		# ... OS (=unknown) ...
    output.write(filename+'\000')	# ... original filename ...

    crcval=zlib.crc32("")
    compobj=zlib.compressobj(9, zlib.DEFLATED, -zlib.MAX_WBITS,
			     zlib.DEF_MEM_LEVEL, 0)
    while (1):
	data=input.read(1024)
	if data=="": break
	crcval=zlib.crc32(data, crcval)
	output.write(compobj.compress(data))
    output.write(compobj.flush())
    write32(output, crcval)		# ... the CRC ...
    write32(output, statval[6])		# and the file size.

else:
    magic=input.read(2)
    if magic!='\037\213':
	print 'Not a gzipped file' ; sys.exit(0)
    if ord(input.read(1))!=8:
	print 'Unknown compression method' ; sys.exit(0)
    flag=ord(input.read(1))
    input.read(4+1+1)			# Discard modification time,
					# extra flags, and OS byte.
    if flag & FEXTRA:
	# Read & discard the extra field, if present
	xlen=ord(input.read(1))		
	xlen=xlen+256*ord(input.read(1))
	input.read(xlen)
    if flag & FNAME:
	# Read and discard a null-terminated string containing the filename
	while (1):
	    s=input.read(1)
	    if s=='\000': break
    if flag & FCOMMENT:
	# Read and discard a null-terminated string containing a comment
	while (1):
	    s=input.read(1)
	    if s=='\000': break
    if flag & FHCRC:
	input.read(2)			# Read & discard the 16-bit header CRC
    decompobj=zlib.decompressobj(-zlib.MAX_WBITS)
    crcval=zlib.crc32("")
    length=0
    while (1):
	data=input.read(1024)
	if data=="": break
	decompdata=decompobj.decompress(data)
	print len(decompdata)
	output.write(decompdata) ; length=length+len(decompdata)
	crcval=zlib.crc32(decompdata, crcval)
    decompdata=decompobj.flush()
    output.write(decompdata) ; length=length+len(decompdata)
    crcval=zlib.crc32(decompdata, crcval)
    
    # We've read to the end of the file, so we have to rewind in order
    # to reread the 8 bytes containing the CRC and the file size.  The
    # decompressor is smart and knows when to stop, so feeding it
    # extra data is harmless.  
    input.seek(-8, 2)
    crc32=read32(input)
    isize=read32(input)
    if crc32!=crcval: print 'CRC check failed.'
    if isize!=length: print 'Incorrect length of data produced'

input.close() ; output.close()