IronPython.Modules
zip_searchorder defines how we search for a module in the Zip
archive: we first search for a package __init__, then for
non-package .pyc, .pyo and .py entries. The .pyc and .pyo entries
are swapped by initzipimport() if we run in optimized mode. Also,
'/' is replaced by SEP there.
Given a path to a Zip file and a toc_entry, return the (uncompressed)
data as a new reference.
Return the code object for the module named by 'fullname' from the
Zip archive as a new reference.
Given a path to a Zip archive, build a dict, mapping file names
(local to the archive, using SEP as a separator) to toc entries.
A toc_entry is a tuple:
(__file__, # value to use for __file__, available for all files
compress, # compression kind; 0 for uncompressed
data_size, # size of compressed data on disk
file_size, # size of decompressed data
file_offset, # offset of file header from start of archive
time, # mod time of file (in dos format)
date, # mod data of file (in dos format)
crc, # crc checksum of the data
)
Directories can be recognized by the trailing SEP in the name,
data_size and file_offset are 0.
Given a (sub)modulename, write the potential file path in the
archive (without extension) to the path buffer.
Determines the type of module we have (package or module, or not found).
Provides a StreamContentProvider for a stream of content backed by a file on disk.
This class represents adler32 checksum algorithm
This static method returns adler32 checksum of the buffer data
Implementation of the Deflate compression algorithm.
Maximum memory level
Defalult compression method
Default memory level
block not completed, need more input or more output
Block internalFlush performed
Finish started, need only more output at next deflate
finish done, accept no more input or output
preset dictionary flag in zlib header
The deflate compression method
The size of the buffer
repeat previous bit length 3-6 times (2 bits of repeat count)
repeat a zero length 3-10 times (3 bits of repeat count)
repeat a zero length 11-138 times (7 bits of repeat count)
Deflate class congiration table
Pointer back to this zlib stream
As the name implies
Output still pending
Size of Pending_buf
Next pending byte to output to the stream
Number of bytes in the pending buffer
suppress zlib header and adler32
UNKNOWN, BINARY or ASCII
STORED (for zip only) or DEFLATED
Value of internalFlush parameter for previous deflate call
LZ77 Window size (32K by default)
log2(w_size) (8..16)
w_size - 1
Sliding Window. Input bytes are ReadPos into the second half of the Window,
and move to the first half later to keep a dictionary of at least wSize
bytes. With this organization, matches are limited to a distance of
wSize-MAX_MATCH bytes, but this ensures that IO is always
performed with a length multiple of the block size. Also, it limits
the Window size to 64K, which is quite useful on MSDOS.
To do: use the user input buffer as sliding Window.
Actual size of Window: 2*wSize, except when the user input buffer is directly used as sliding Window.
Link to older string with same hash index. To limit the size of this
array to 64K, this link is maintained only for the last 32K strings.
An index in this array is thus a Window index modulo 32K.
Heads of the hash chains or NIL.
hash index of string to be inserted
number of elements in hash table
log2(hash_size)
hash_size-1
Number of bits by which ins_h must be shifted at each input
step. It must be such that after MIN_MATCH steps, the oldest
byte no longer takes part in the hash key, that is:
hash_shift * MIN_MATCH >= hash_bits
Window position at the beginning of the current output block. Gets negative when the Window is moved backwards.
length of best match
previous match
set if previous match exists
start of string to insert
start of matching string
number of valid bytes ahead in Window
Length of the best match at previous step. Matches not greater than this
are discarded. This is used in the lazy match evaluation.
To speed up deflation, hash chains are never searched beyond this
length. A higher limit improves compression ratio but degrades the speed.
Attempt to find a better match only when the current match is strictly
smaller than this value. This mechanism is used only for compression
levels >= 4.
compression level (1..9)
favor or force Huffman coding
Use a faster search when the previous match is longer than this
Stop searching when current match exceeds this
literal and length tree
distance tree
Huffman tree for bit lengths
Desc for literal tree
desc for distance tree
desc for bit length tree
number of codes at each bit length for an optimal tree
heap used to build the Huffman trees
number of elements in the heap
element of largest frequency
Depth of each subtree used as tie breaker for trees of equal frequency
index for literals or lengths
Size of match buffer for literals/lengths. There are 4 reasons for
limiting lit_bufsize to 64K:
- frequencies can be kept in 16 bit counters
- if compression is not successful for the first block, all input
data is still in the Window so we can still emit a stored block even
when input comes from standard input. (This can also be done for
all blocks if lit_bufsize is not greater than 32K.)
- if compression is not successful for a file smaller than 64K, we can
even emit a stored file instead of a stored block (saving 5 bytes).
This is applicable only for zip (not gzip or zlib).
- creating new Huffman trees less frequently may not provide fast
adaptation to changes in the input data statistics. (Take for
example a binary file with poorly compressible code followed by
a highly compressible string table.) Smaller buffer sizes give
fast adaptation but have of course the overhead of transmitting
trees more frequently.
- I can't count above 4
running index in l_buf
index of pendig_buf
bit length of current block with optimal trees
bit length of current block with static trees
number of string matches in current block
bit length of EOB code for last block
Output buffer. bits are inserted starting at the bottom (least
significant bits).
Number of valid bits in bi_buf. All bits above the last valid bit
are always zero.
Default constructor
Initialization
Initialize the tree data structures for a new zlib stream.
Initializes block
Restore the heap property by moving down the tree starting at node k,
exchanging a node with the smallest of its two sons if necessary, stopping
when the heap property is re-established (each father smaller than its
two sons).
Scan a literal or distance tree to determine the frequencies of the codes
in the bit length tree.
Construct the Huffman tree for the bit lengths and return the index in
bl_order of the last bit length code to send.
Send the header for a block using dynamic Huffman trees: the counts, the
lengths of the bit length codes, the literal tree and the distance tree.
IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
Send a literal or distance tree in compressed form, using the codes in
bl_tree.
Output a byte on the stream.
IN assertion: there is enough room in Pending_buf.
Adds a byte to the buffer
Send one empty static block to give enough lookahead for inflate.
This takes 10 bits, of which 7 may remain in the bit buffer.
The current inflate code requires 9 bits of lookahead. If the
last two codes for the previous block (real code plus EOB) were coded
on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
the last real code. In this case we send two empty static blocks instead
of one. (There are no problems if the previous block is stored or fixed.)
To simplify the code, we assume the worst case of last real code encoded
on one bit only.
Save the match info and tally the frequency counts. Return true if
the current block must be flushed.
Send the block data compressed using the given Huffman trees
Set the data type to ASCII or BINARY, using a crude approximation:
binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise.
IN assertion: the fields freq of dyn_ltree are set and the total of all
frequencies does not exceed 64K (to fit in an int on 16 bit machines).
Flush the bit buffer, keeping at most 7 bits in it.
Flush the bit buffer and align the output on a byte boundary
Copy a stored block, storing first the length and its
one's complement if requested.
Flushes block
Copy without compression as much as possible from the input stream, return
the current block state.
This function does not insert new strings in the dictionary since
uncompressible data is probably not useful. This function is used
only for the level=0 compression option.
NOTE: this function should be optimized to avoid extra copying from
Window to Pending_buf.
Send a stored block
Determine the best encoding for the current block: dynamic trees, static
trees or store, and output the encoded block to the zip file.
Fill the Window when the lookahead becomes insufficient.
Updates strstart and lookahead.
IN assertion: lookahead less than MIN_LOOKAHEAD
OUT assertions: strstart less than or equal to window_size-MIN_LOOKAHEAD
At least one byte has been ReadPos, or _avail_in == 0; reads are
performed for at least two bytes (required for the zip translate_eol
option -- not supported here).
Compress as much as possible from the input stream, return the current
block state.
This function does not perform lazy evaluation of matches and inserts
new strings in the dictionary only for unmatched strings or for short
matches. It is used only for the fast compression options.
Same as above, but achieves better compression. We use a lazy
evaluation for matches: a match is finally adopted only if there is
no better match at the next Window position.
Finds the longest matching data part
Deflate algorithm initialization
ZStream object
Compression level
Window bits
A result code
Initializes deflate algorithm
ZStream object
Compression level
Operation result result code
Deflate algorithm initialization
ZStream object
Compression level
Compression method
Window bits
Memory level
Compression strategy
Operation result code
Resets the current state of deflate object
Finish compression with deflate algorithm
Sets deflate algorithm parameters
Sets deflate dictionary
Performs data compression with the deflate algorithm
Static constructor initializes config_table
Compression level
Number of bytes in the pending buffer
Output still pending
Next pending byte to output to the stream
suppress zlib header and adler32
Deflate algorithm configuration parameters class
reduce lazy search above this match length
do not perform lazy search above this match length
quit search above this match length
Constructor which initializes class inner fields
current inflate_block mode
if STORED, bytes left to copy
table lengths (14 bits)
index into blens (or border)
bit lengths of codes
bit length tree depth
bit length decoding tree
if CODES, current state
true if this block is the last block
bits in bit buffer
bit buffer
single malloc for tree space
sliding Window
one byte after sliding Window
Window ReadPos pointer
Window WritePos pointer
need check
check on output
Resets this InfBlocks class instance
Block processing functions
Frees inner buffers
Sets dictionary
Returns true if inflate is currently at the End of a block generated
by Z_SYNC_FLUSH or Z_FULL_FLUSH.
copy as much as possible from the sliding Window to the output area
sliding window
one byte after sliding Window
Window ReadPos pointer
Window WritePos pointer
bits in bit buffer
bit buffer
Inflate codes mode
This class is used by the InfBlocks class
current inflate_codes mode
length
pointer into tree
current index of the tree
ltree bits decoded per branch
dtree bits decoded per branch
literal/length/eob tree
literal/length/eob tree index
distance tree
distance tree index
Constructor which takes literal, distance trees, corresponding bites decoded for branches, corresponding indexes and a ZStream object
Constructor which takes literal, distance trees, corresponding bites decoded for branches and a ZStream object
Block processing method
An instance of the InfBlocks class
A ZStream object
A result code
Frees allocated resources
Fast inflate procedure. Called with number of bytes left to WritePos in Window at least 258
(the maximum string length) and number of input bytes available
at least ten. The ten bytes are six bytes for the longest length/
distance pair plus four bytes for overloading the bit buffer.
This enumeration contains modes of inflate processing
waiting for method byte
waiting for flag byte
four dictionary check bytes to go
three dictionary check bytes to go
two dictionary check bytes to go
one dictionary check byte to go
waiting for inflateSetDictionary
decompressing blocks
four check bytes to go
three check bytes to go
two check bytes to go
one check byte to go
finished check, done
got an error--stay here
current inflate mode
if FLAGS, method byte
computed check value
stream check value
if BAD, inflateSync's marker bytes count
flag for no wrapper
log2(Window size) (8..15, defaults to 15)
current inflate_blocks state
Resets the Inflate algorithm
A ZStream object
A result code
Finishes the inflate algorithm processing
A ZStream object
Operation result code
Initializes the inflate algorithm
A ZStream object
Window size
Operation result code
Runs inflate algorithm
A ZStream object
Flush strategy
Operation result code
Sets dictionary for the inflate operation
A ZStream object
An array of byte - dictionary
Dictionary length
Operation result code
Inflate synchronization
A ZStream object
Operation result code
Returns true if inflate is currently at the End of a block generated
by Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
implementation to provide an additional safety check. PPP uses Z_SYNC_FLUSH
but removes the length bytes of the resulting empty stored block. When
decompressing, PPP checks that at the End of input packet, inflate is
waiting for these length bytes.
Contains utility information for the InfTree class
Given a list of code lengths and a maximum table size, make a set of
tables to decode that set of codes.
Return (int)ZLibResultCode.Z_OK on success, (int)ZLibResultCode.Z_DATA_ERROR if the given code set is incomplete (the tables are still built in this case), (int)ZLibResultCode.Z_DATA_ERROR if the input is invalid (an over-subscribed set of lengths), or (int)ZLibResultCode.Z_DATA_ERROR if not enough memory.
Build trees
Builds dynamic trees
Build fixed trees
Bit length codes must not exceed MAX_BL_BITS bits
This class represents a tree and is used in the Deflate class
The dynamic tree
Largest code with non zero frequency
the corresponding static tree
Mapping from a distance to a distance code. dist is the distance - 1 and
must not have side effects. _dist_code[256] and _dist_code[257] are never
used.
Compute the optimal bit lengths for a tree and update the total bit length
for the current block.
IN assertion: the fields freq and dad are set, heap[heap_max] and
above are the tree nodes sorted by increasing frequency.
OUT assertions: the field count is set to the optimal bit length, the
array bl_count contains the frequencies for each bit length.
The length opt_len is updated; static_len is also updated if stree is
not null.
Construct one Huffman tree and assigns the code bit strings and lengths.
Update the total bit length for the current block.
IN assertion: the field freq is set for all tree elements.
OUT assertions: the fields count and code are set to the optimal bit length
and corresponding code. The length opt_len is updated; static_len is
also updated if stree is not null. The field max_code is set.
Generate the codes for a given tree and bit counts (which need not be
optimal).
IN assertion: the array bl_count contains the bit length statistics for
the given tree and the field count is set for all tree elements.
OUT assertion: the field code is set for all tree elements of non
zero code length.
Reverse the first count bits of a code, using straightforward code (a faster
method would use a table)
The dynamic tree
Largest code with non zero frequency
the corresponding static tree
Some constants for specifying compression levels. Methods which takes a compression level as a parameter expects an integer value from 0 to 9. You can either specify an integer value or use constants for some most widely used compression levels.
No compression should be used at all.
Minimal compression, but greatest speed.
Maximum compression, but slowest.
Select default compression level (good compression, good speed).
Compression strategies. The strategy parameter is used to tune the compression algorithm. The strategy parameter only affects the compression ratio but not the correctness of the compressed output even if it is not set appropriately.
This strategy is designed for filtered data. Data which consists of mostly small values, with random distribution should use Z_FILTERED. With this strategy, less string matching is performed.
Z_HUFFMAN_ONLY forces Huffman encoding only (no string match)
The default strategy is the most commonly used. With this strategy, string matching and huffman compression are balanced.
Flush strategies
Do not internalFlush data, but just write data as normal to the output buffer. This is the normal way in which data is written to the output buffer.
Obsolete. You should use Z_SYNC_FLUSH instead.
All pending output is flushed to the output buffer and the output is aligned on a byte boundary, so that the decompressor can get all input data available so far.
All output is flushed as with Z_SYNC_FLUSH, and the compression state is reset so that decompression can restart from this point if previous compressed data has been damaged or if random access is desired. Using Z_FULL_FLUSH too often can seriously degrade the compression. ZLib_InflateSync will locate points in the compression string where a full has been performed.
Notifies the module that the input has now been exhausted. Pending input is processed, pending output is flushed and calls return with Z_STREAM_END if there was enough output space.
Results of operations in ZLib library
No failure was encountered, the operation completed without problem.
No failure was encountered, and the input has been exhausted.
A preset dictionary is required for decompression of the data.
An internal error occurred
The stream structure was inconsistent
Input data has been corrupted (for decompression).
Memory allocation failed.
There was not enough space in the output buffer.
The version supplied does not match that supported by the ZLib module.
States of deflate operation
Data block types, i.e. binary or ascii text
Helper class
Max Window size
preset dictionary flag in zlib header
The size of the buffer
Deflate compression method index
see definition of array dist_code below
This method returns the literal value received
The literal to return
The received value
This method returns the literal value received
The literal to return
The received value
This method returns the literal value received
The literal to return
The received value
This method returns the literal value received
The literal to return
The received value
Performs an unsigned bitwise right shift with the specified number
Number to operate on
Ammount of bits to shift
The resulting number from the shift operation
Performs an unsigned bitwise right shift with the specified number
Number to operate on
Ammount of bits to shift
The resulting number from the shift operation
Performs an unsigned bitwise right shift with the specified number
Number to operate on
Ammount of bits to shift
The resulting number from the shift operation
Performs an unsigned bitwise right shift with the specified number
Number to operate on
Ammount of bits to shift
The resulting number from the shift operation
Reads a number of characters from the current source Stream and writes the data to the target array at the specified index.
The source Stream to ReadPos from.
Contains the array of characters ReadPos from the source Stream.
The starting index of the target array.
The maximum number of characters to ReadPos from the source Stream.
The number of characters ReadPos. The number will be less than or equal to count depending on the data available in the source Stream. Returns -1 if the End of the stream is reached.
Reads a number of characters from the current source TextReader and writes the data to the target array at the specified index.
The source TextReader to ReadPos from
Contains the array of characteres ReadPos from the source TextReader.
The starting index of the target array.
The maximum number of characters to ReadPos from the source TextReader.
The number of characters ReadPos. The number will be less than or equal to count depending on the data available in the source TextReader. Returns -1 if the End of the stream is reached.
Converts a string to an array of bytes
The string to be converted
The new array of bytes
Converts an array of bytes to an array of chars
The array of bytes to convert
The new array of chars
Copies large array which was passed as srcBuf to the Initialize method into the destination array which were passes as destBuff
The number of bytes copied
ZStream is used to store user data to compress/decompress.
Maximum memory level
Next input byte array
Index of the first byte in the input array.
Number of bytes available at _next_in
total nb of input bytes ReadPos so far
Byte array for the next output block
Index of the first byte in the _next_out array
Remaining free space at _next_out
Total number of bytes in output array
A string to store operation result message (corresponding to result codes)
A deflate object to perform data compression
Inflate object to perform data decompression
Best guess about the data type: ascii or binary
A checksum computed with Adler algorithm
Initializes the internal stream state for decompression. The fields , must be
initialized before by the caller. If is not null and is large
enough (the exact value depends on the compression method), determines the compression
method from the ZLib header and allocates all data structures accordingly; otherwise the allocation will be deferred
to the first call of .
inflateInit returns if success, if there was not enough memory,
if the ZLib library version is incompatible with the version assumed by the caller.
is set to null if there is no error message. does not perform any decompression
apart from reading the ZLib header if present: this will be done by . (So and
may be modified, but and are unchanged.)
This is another version of with an extra parameter. The fields , must be
initialized before by the caller. If is not null and is large enough
(the exact value depends on the compression method), determines the compression method from
the ZLib header and allocates all data structures accordingly; otherwise the allocation will be deferred to the first
call of .
The windowBits parameter is the base two logarithm of the maximum window size (the size of the history buffer).
It should be in the range 8..15 for this version of the library. The default value is 15 if is used instead.
If a compressed stream with a larger window size is given as input, will return with the error code
instead of trying to allocate a larger window.
inflateInit returns if success, if there was not enough memory,
if a parameter is invalid (such as a negative memLevel). is set to null
if there is no error message. does not perform any decompression apart from reading the ZLib header
if present: this will be done by . (So and may be modified,
but and are unchanged.)
This method decompresses as much data as possible, and stops when the input buffer () becomes empty or
the output buffer () becomes full. It may some introduce some output latency (reading input without producing any output)
except when forced to flush.
The detailed semantics are as follows. performs one or both of the following actions:
- Decompress more input starting at and update and
accordingly. If not all input can be processed (because there is not enough room in the output buffer), is updated and
processing will resume at this point for the next call of .
- Provide more output starting at and update and
accordingly. provides as much output as possible, until there is no more input data or no more space in
the output buffer (see below about the parameter).
Flush strategy to use.
Before the call of , the application should ensure that at least one of the actions is possible, by providing
more input and/or consuming more output, and updating the next_* and avail_* values accordingly. The application can consume the uncompressed
output when it wants, for example when the output buffer is full (avail_out == 0), or after each call of .
If returns and with zero , it must be called again
after making room in the output buffer because there might be more output pending.
If the parameter is set to , flushes
as much output as possible to the output buffer. The flushing behavior of is not specified for values of
the parameter other than and ,
but the current implementation actually flushes as much output as possible anyway.
should normally be called until it returns or an error.
However if all decompression is to be performed in a single step (a single call of inflate), the parameter
should be set to . In this case all pending input is processed and all pending output is flushed;
must be large enough to hold all the uncompressed data. (The size of the uncompressed data may have been
saved by the compressor for this purpose.) The next operation on this stream must be to deallocate the decompression
state. The use of is never required, but can be used to inform that a faster
routine may be used for the single call.
If a preset dictionary is needed at this point (see ), sets strm-adler
to the adler32 checksum of the dictionary chosen by the compressor and returns ; otherwise it
sets strm->adler to the adler32 checksum of all output produced so far (that is, bytes) and returns
, or an error code as described below. At the end of the stream,
) checks that its computed adler32 checksum is equal to that saved by the compressor and returns
only if the checksum is correct.
returns if some progress has been made (more input processed or more output produced),
if the end of the compressed data has been reached and all uncompressed output has been produced,
if a preset dictionary is needed at this point, if
the input data was corrupted (input stream not conforming to the ZLib format or incorrect adler32 checksum),
if the stream structure was inconsistent (for example if or
was null), if there was not enough memory,
if no progress is possible or if there was not enough room in the output buffer
when is used. In the case, the application
may then call to look for a good compression block.
All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any
pending output.
inflateEnd returns if success,
if the stream state was inconsistent. In the error case, msg may be set but then points to a static string (which must not be deallocated).
Skips invalid compressed data until a full flush point (see the description of deflate with Z_FULL_FLUSH) can be found,
or until all available input is skipped. No output is provided.
returns if a full flush point has been found,
if no more input was provided, if no flush point has been found, or
if the stream structure was inconsistent. In the success case, the application may save the current
current value of which indicates where valid compressed data was found. In the error case, the application may repeatedly
call , providing more input each time, until success or end of the input data.
Initializes the decompression dictionary from the given uncompressed byte sequence. This function must be called immediately after a call of if this call returned . The dictionary chosen by the compressor can be determined from the Adler32 value returned by this call of . The compressor and decompresser must use exactly the same dictionary.
A byte array - a dictionary.
The length of the dictionary.
inflateSetDictionary returns if success, if a parameter is invalid (such as null dictionary) or the stream state is inconsistent, if the given dictionary doesn't match the expected one (incorrect Adler32 value). inflateSetDictionary does not perform any decompression: this will be done by subsequent calls of .
Initializes the internal stream state for compression.
An integer value from 0 to 9 indicating the desired compression level.
deflateInit returns if success, if there was not enough memory,
if level is not a valid compression level. is set to null if there is
no error message. does not perform any compression: this will be done by .
Initializes the internal stream state for compression.
An integer value from 0 to 9 indicating the desired compression level.
The windowBits parameter is the base two logarithm of the window size (the size of the history buffer). It should be in the
range 8..15 for this version of the library. Larger values of this parameter result in better compression at the expense of memory usage.
The default value is 15 if deflateInit is used instead.
deflateInit returns if success, if there was not enough memory,
if level is not a valid compression level. is set to null if there
is no error message. does not perform any compression: this will be done by .
Deflate compresses as much data as possible, and stops when the input buffer becomes empty or the
output buffer becomes full. It may introduce some output latency (reading input without producing any output)
except when forced to flush.
The detailed semantics are as follows. deflate performs one or both of the following actions:
- Compress more input starting at and update and accordingly.
If not all input can be processed (because there is not enough room in the output buffer), and
are updated and processing will resume at this point for the next call of .
- Provide more output starting at and update and accordingly.
This action is forced if the parameter flush is non zero. Forcing flush frequently degrades the compression ratio, so this parameter should
be set only when necessary (in interactive applications). Some output may be provided even if flush is not set.
The flush strategy to use.
Before the call of , the application should ensure that at least one of the actions is possible, by providing
more input and/or consuming more output, and updating or accordingly ;
should never be zero before the call. The application can consume the compressed output when it wants, for example when the output buffer is full
(avail_out == 0), or after each call of . If returns
and with zero , it must be called again after making room in the output buffer because there might be more output pending.
If the parameter is set to , all pending output is flushed to the
output buffer and the output is aligned on a byte boundary, so that the decompressor can get all input
data available so far. (In particular is zero after the call if enough output space has been provided before the call.)
Flushing may degrade compression for some compression algorithms and so it should be used only when necessary.
If flush is set to , all output is flushed as with ,
and the compression state is reset so that decompression can restart from this point if previous compressed data has been damaged or if
random access is desired. Using too often can seriously degrade the compression.
If deflate returns with == 0, this function must be called again with the same value of the flush
parameter and more output space (updated ), until the flush is complete ( returns with
non-zero ).
If the parameter is set to , pending input is processed, pending
output is flushed and deflate returns with if there was enough output space ;
if deflate returns with , this function must be called again with
and more output space (updated ) but no more input data, until it returns with
or an error. After deflate has returned , the only possible operation on the stream is
.
can be used immediately after if all the compression is to be
done in a single step. In this case, avail_out must be at least 0.1% larger than avail_in plus 12 bytes. If deflate does not return
Z_STREAM_END, then it must be called again as described above.
sets strm-> adler to the adler32 checksum of all input read so far (that is, bytes).
may update data_type if it can make a good guess about the input data type (Z_ASCII or Z_BINARY).
In doubt, the data is considered binary. This field is only for information purposes and does not affect the compression algorithm in any manner.
returns if some progress has been made (more input processed or more output produced),
if all input has been consumed and all output has been produced (only when flush is set to
), if the stream state was inconsistent (for example if
or was null), if no progress is possible
(for example or was zero).
All dynamically allocated data structures for this stream are freed. This function discards any unprocessed input and does not flush any pending
output.
deflateEnd returns if success, if the stream state was inconsistent,
if the stream was freed prematurely (some input or output was discarded). In the error case,
may be set but then points to a static string (which must not be deallocated).
Dynamically update the compression level and compression strategy. The interpretation of level is as in .
This can be used to switch between compression and straight copy of the input data, or to switch to a different kind of input data
requiring a different strategy. If the compression level is changed, the input available so far is compressed with the old level
(and may be flushed); the new level will take effect only at the next call of
An integer value indicating the desired compression level.
A flush strategy to use.
Before the call of , the stream state must be set as for a call of , since the
currently available input may have to be compressed and flushed. In particular, must be non-zero.
deflateParams returns if success, if the source stream
state was inconsistent or if a parameter was invalid, if was zero.
Initializes the compression dictionary from the given byte sequence without producing any compressed output. This function must be called
immediately after , before any call of . The compressor and decompressor must use
exactly the same dictionary (see ).
A byte array - a dictionary.
The length of the dictionary byte array
The dictionary should consist of strings (byte sequences) that are likely to be encountered later in the data to be compressed,
with the most commonly used strings preferably put towards the end of the dictionary. Using a dictionary is most useful when the data
to be compressed is short and can be predicted with good accuracy; the data can then be compressed better than with the default empty dictionary.
Depending on the size of the compression data structures selected by , a part of the dictionary may
in effect be discarded, for example if the dictionary is larger than the window size in . Thus the strings most likely
to be useful should be put at the end of the dictionary, not at the front.
Upon return of this function, adler is set to the Adler32 value of the dictionary; the decompresser may later use this value to determine
which dictionary has been used by the compressor. (The Adler32 value applies to the whole dictionary even if only a subset of the dictionary
is actually used by the compressor.)
deflateSetDictionary returns if success, or if a parameter
is invalid (such as null dictionary) or the stream state is inconsistent (for example if has already been
called for this stream or if the compression method is bsort). does not perform any compression:
this will be done by .
Flush as much pending output as possible. All output goes through this function so some applications may wish to
modify it to avoid allocating a large buffer and copying into it.
Read a new buffer from the current input stream, update the adler32 and total number of bytes read. All input goes
through this function so some applications may wish to modify it to avoid allocating a large buffer and copying from it.
Frees all inner buffers.
Adler-32 value for uncompressed data processed so far.
Best guess about the data type: ascii or binary
Gets/Sets the next input byte array.
Index of the first byte in the input array.
Gets/Sets the number of bytes available in the input buffer.
Gets/Sets the total number of bytes in the input buffer.
Gets/Sets the buffer for the next output data.
Gets/Sets the index of the first byte in the byte array to write to.
Gets/Sets the remaining free space in the buffer.
Gets/Sets the total number of bytes in the output array.
Gets sets the last error message occurred during class operations.
A deflate object to perform data compression
Inflate object to perform data decompression
Exceptions that occur in ZStream
Default constructor.
Constructor which takes one parameter - an error message
Creates an optimized encoding mapping that can be consumed by an optimized version of charmap_encode.
Decodes the input string using the provided string mapping.
Encodes the input string with the specified optimized encoding map.
Optimied encoding mapping that can be consumed by charmap_encode.
Provides helper functions which need to be called from generated code to implement various
portions of modules.
Convert string or bytes into bytes
Convert most bytearray-like objects into IList of byte
BytesIO([initializer]) -> object
Create a buffered I/O implementation using an in-memory bytes
buffer, ready for reading and writing.
close() -> None. Disable all I/O operations.
getvalue() -> bytes.
Retrieve the entire contents of the BytesIO object.
True if the file is closed.
Read and decode the next chunk from the buffered reader. Returns true if EOF was
not reached. Places decoded string in _decodedChars.
Remove all 'b's from mode string to simplify parsing
Walks the queue calling back to the specified delegate for
each populated index in the queue.
Throw TypeError with a specified message if object isn't callable.
Convert object to ushort, throwing ValueError on overflow.
Interface for "file-like objects" that implement the protocol needed by load() and friends.
This enables the creation of thin wrappers that make fast .NET types and slow Python types look the same.
Interface for "file-like objects" that implement the protocol needed by dump() and friends.
This enables the creation of thin wrappers that make fast .NET types and slow Python types look the same.
Call the appropriate reduce method for obj and pickle the object using
the resulting data. Use the first available of
copy_reg.dispatch_table[type(obj)], obj.__reduce_ex__, and obj.__reduce__.
Pickle the result of a reduce function.
Only context, obj, func, and reduceCallable are required; all other arguments may be null.
Write value in pickle decimalnl_short format.
Write value in pickle float8 format.
Write value in pickle uint1 format.
Write value in pickle uint2 format.
Write value in pickle int4 format.
Write value in pickle decimalnl_short format.
Write value in pickle decimalnl_short format.
Write value in pickle decimalnl_long format.
Write value in pickle unicodestringnl format.
Write value in pickle unicodestring4 format.
Write value in pickle stringnl_noescape_pair format.
Return true if value is appropriate for formatting in pickle uint1 format.
Return true if value is appropriate for formatting in pickle uint2 format.
Return true if value is appropriate for formatting in pickle int4 format.
Emit a series of opcodes that will set append all items indexed by iter
to the object at the top of the stack. Use APPENDS if possible, but
append no more than BatchSize items at a time.
Emit a series of opcodes that will set all (key, value) pairs indexed by
iter in the object at the top of the stack. Use SETITEMS if possible,
but append no more than BatchSize items at a time.
Emit a series of opcodes that will set all (key, value) pairs indexed by
iter in the object at the top of the stack. Use SETITEMS if possible,
but append no more than BatchSize items at a time.
Find the module for obj and ensure that obj is reachable in that module by the given name.
Throw PicklingError if any of the following are true:
- The module couldn't be determined.
- The module couldn't be loaded.
- The given name doesn't exist in the module.
- The given name is a different object than obj.
Otherwise, return the name of the module.
To determine which module obj lives in, obj.__module__ is used if available. The
module named by obj.__module__ is loaded if needed. If obj has no __module__
attribute, then each loaded module is searched. If a loaded module has an
attribute with the given name, and that attribute is the same object as obj,
then that module is used.
Interpret everything from markIndex to the top of the stack as a sequence
of key, value, key, value, etc. Set dict[key] = value for each. Pop
everything from markIndex up when done.
Used to check the type to see if we can do a comparison. Returns true if we can
or false if we should return NotImplemented. May throw if the type's really wrong.
Helper function for doing the comparisons. time has no __cmp__ method
Base class used for iterator wrappers.
Returns the dialects from the code context.
Popupates the given directory w/ the locale information from the given
CultureInfo.
Error function on real values
Complementary error function on real values: erfc(x) = 1 - erf(x)
Gamma function on real values
Natural log of absolute value of Gamma function
Checks for the specific permissions, provided by the mode parameter, are available for the provided path. Permissions can be:
F_OK: Check to see if the file exists
R_OK | W_OK | X_OK: Check for the specific permissions. Only W_OK is respected.
single instance of environment dictionary is shared between multiple runtimes because the environment
is shared by multiple runtimes.
lstat(path) -> stat result
Like stat(path), but do not follow symbolic links.
spawns a new process.
If mode is nt.P_WAIT then then the call blocks until the process exits and the return value
is the exit code.
Otherwise the call returns a handle to the process. The caller must then call nt.waitpid(pid, options)
to free the handle and get the exit code of the process. Failure to call nt.waitpid will result
in a handle leak.
spawns a new process.
If mode is nt.P_WAIT then then the call blocks until the process exits and the return value
is the exit code.
Otherwise the call returns a handle to the process. The caller must then call nt.waitpid(pid, options)
to free the handle and get the exit code of the process. Failure to call nt.waitpid will result
in a handle leak.
spawns a new process.
If mode is nt.P_WAIT then then the call blocks until the process exits and the return value
is the exit code.
Otherwise the call returns a handle to the process. The caller must then call nt.waitpid(pid, options)
to free the handle and get the exit code of the process. Failure to call nt.waitpid will result
in a handle leak.
spawns a new process.
If mode is nt.P_WAIT then then the call blocks until the process exits and the return value
is the exit code.
Otherwise the call returns a handle to the process. The caller must then call nt.waitpid(pid, options)
to free the handle and get the exit code of the process. Failure to call nt.waitpid will result
in a handle leak.
Copy elements from a Python mapping of dict environment variables to a StringDictionary.
Convert a sequence of args to a string suitable for using to spawn a process.
Python regular expression module.
Preparses a regular expression text returning a ParsedRegex class
that can be used for further regular expressions.
Compiled reg-ex pattern
Process a sequence of objects that are compatible with ObjectToSocket(). Return two
things as out params: an in-order List of sockets that correspond to the original
objects in the passed-in sequence, and a mapping of these socket objects to their
original objects.
The socketToOriginal mapping is generated because the CPython select module supports
passing to select either file descriptor numbers or an object with a fileno() method.
We try to be faithful to what was originally requested when we return.
Return the System.Net.Sockets.Socket object that corresponds to the passed-in
object. obj can be a System.Net.Sockets.Socket, a PythonSocket.SocketObj, a
long integer (representing a socket handle), or a Python object with a fileno()
method (whose result is used to look up an existing PythonSocket.SocketObj,
which is in turn converted to a Socket.
Convert an object to a 32-bit integer. This adds two features to Converter.ToInt32:
1. Sign is ignored. For example, 0xffff0000 converts to 4294901760, where Convert.ToInt32
would throw because 0xffff0000 is less than zero.
2. Overflow exceptions are thrown. Converter.ToInt32 throws TypeError if x is
an integer, but is bigger than 32 bits. Instead, we throw OverflowException.
Convert an object to a 16-bit integer. This adds two features to Converter.ToInt16:
1. Sign is ignored. For example, 0xff00 converts to 65280, where Convert.ToInt16
would throw because signed 0xff00 is -256.
2. Overflow exceptions are thrown. Converter.ToInt16 throws TypeError if x is
an integer, but is bigger than 16 bits. Instead, we throw OverflowException.
Return a standard socket exception (socket.error) whose message and error code come from a SocketException
This will eventually be enhanced to generate the correct error type (error, herror, gaierror) based on the error code.
Convert an IPv6 address byte array to a string in standard colon-hex notation.
The .NET IPAddress.ToString() method uses dotted-quad for the last 32 bits,
which differs from the normal Python implementation (but is allowed by the IETF);
this method returns the standard (no dotted-quad) colon-hex form.
Handle conversion of "" to INADDR_ANY and "<broadcast>" to INADDR_BROADCAST.
Otherwise returns host unchanged.
Return the IP address associated with host, with optional address family checking.
host may be either a name or an IP address (in string form).
If family is non-null, a gaierror will be thrown if the host's address family is
not the same as the specified family. gaierror is also raised if the hostname cannot be
converted to an IP address (e.g. through a name lookup failure).
Return the IP address associated with host, with optional address family checking.
host may be either a name or an IP address (in string form).
If family is non-null, a gaierror will be thrown if the host's address family is
not the same as the specified family. gaierror is also raised if the hostname cannot be
converted to an IP address (e.g. through a name lookup failure).
Return fqdn, but with its domain removed if it's on the same domain as the local machine.
Convert a (host, port) tuple [IPv4] (host, port, flowinfo, scopeid) tuple [IPv6]
to its corresponding IPEndPoint.
Throws gaierror if host is not a valid address.
Throws ArgumentTypeException if any of the following are true:
- address does not have exactly two elements
- address[0] is not a string
- address[1] is not an int
Convert an IPEndPoint to its corresponding (host, port) [IPv4] or (host, port, flowinfo, scopeid) [IPv6] tuple.
Throws SocketException if the address family is other than IPv4 or IPv6.
handleToSocket allows us to translate from Python's idea of a socket resource (file
descriptor numbers) to .NET's idea of a socket resource (System.Net.Socket objects).
In particular, this allows the select module to convert file numbers (as returned by
fileno()) and convert them to Socket objects so that it can do something useful with them.
Return the internal System.Net.Sockets.Socket socket object associated with the given
handle (as returned by GetHandle()), or null if no corresponding socket exists. This is
primarily intended to be used by other modules (such as select) that implement
networking primitives. User code should not normally need to call this function.
Create a Python socket object from an existing .NET socket object
(like one returned from Socket.Accept())
Perform initialization common to all constructors
Wrapper class for emitting locals/variables during marshalling code gen.
A wrapper around allocated memory to ensure it gets released and isn't accessed
when it could be finalized.
Creates a new MemoryHolder and allocates a buffer of the specified size.
Creates a new MemoryHolder at the specified address which is not tracked
by us and we will never free.
Creates a new MemoryHolder at the specified address which will keep alive the
parent memory holder.
Used to track the lifetime of objects when one memory region depends upon
another memory region. For example if you have an array of objects that
each have an element which has it's own lifetime the array needs to keep
the individual elements alive.
The keys used here match CPython's keys as tested by CPython's test_ctypes.
Typically they are a string which is the array index, "ffffffff" when
from_buffer is used, or when it's a simple type there's just a string
instead of the full dictionary - we store that under the key "str".
Copies the data in data into this MemoryHolder.
Copies memory from one location to another keeping the associated memory holders alive during the
operation.
Gets the address of the held memory. The caller should ensure the MemoryHolder
is always alive as long as the address will continue to be accessed.
Gets a list of objects which need to be kept alive for this MemoryHolder to be
remain valid.
Native functions used for exposing ctypes functionality.
Allocates memory that's zero-filled
Helper function for implementing memset. Could be more efficient if we
could P/Invoke or call some otherwise native code to do this.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Provides support for interop with native code from Python code.
Implementation of our cast function. data is marshalled as a void*
so it ends up as an address. obj and type are marshalled as an object
so we need to unmarshal them.
Returns a new type which represents a pointer given the existing type.
Converts an address acquired from PyObj_FromPtr or that has been
marshaled as type 'O' back into an object.
Converts an object into an opaque address which can be handed out to
managed code.
Decreases the ref count on an object which has been increased with
Py_INCREF.
Increases the ref count on an object ensuring that it will not be collected.
returns address of C instance internal buffer.
It is the callers responsibility to ensure that the provided instance will
stay alive if memory in the resulting address is to be used later.
Gets the required alignment of the given type.
Gets the required alignment of an object.
Returns a pointer instance for the given CData
Given a specific size returns a .NET type of the equivalent size that
we can use when marshalling these values across calls.
Shared helper between struct and union for getting field info and validating it.
Verifies that the provided bit field settings are valid for this type.
Shared helper to get the _fields_ list for struct/union and validate it.
Helper function for translating from memset to NT's FillMemory API.
Helper function for translating from memset to NT's FillMemory API.
Emits the marshalling code to create a CData object for reverse marshalling.
Gets a function which casts the specified memory. Because this is used only
w/ Python API we use a delegate as the return type instead of an actual address.
Gets the ModuleBuilder used to generate our unsafe call stubs into.
The enum used for tracking the various ctypes primitive types.
'c'
'b'
'B'
'h'
'H'
'i'
'I'
'l'
'L'
'f'
'd', 'g'
'q'
'Q'
'O'
'P'
'z'
'Z'
'u'
'?'
'v'
'X'
Base class for all ctypes interop types.
The meta class for ctypes array instances.
Common functionality that all of the meta classes provide which is part of
our implementation. This is used to implement the serialization/deserialization
of values into/out of memory, emit the marshalling logic for call stubs, and
provide common information (size/alignment) for the types.
Deserialized the value of this type from the given address at the given
offset. Any new objects which are created will keep the provided
MemoryHolder alive.
raw determines if the cdata is returned or if the primitive value is
returned. This is only applicable for subtypes of simple cdata types.
Serializes the provided value into the specified address at the given
offset.
Gets the .NET type which is used when calling or returning the value
from native code.
Gets the .NET type which the native type is converted into when going to Python
code. This is usually int, BigInt, double, object, or a CData type.
Emits marshalling of an object from Python to native code. This produces the
native type from the Python type.
Emits marshalling from native code to Python code This produces the python type
from the native type. This is used for return values and parameters
to Python callable objects that are passed back out to native code.
Gets the native size of the type
Gets the required alignment for the type
Returns a string which describes the type. Used for _buffer_info implementation which
only exists for testing purposes.
Converts an object into a function call parameter.
Creates a new CFuncPtr object from a tuple. The 1st element of the
tuple is the ordinal or function name. The second is an object with
a _handle property. The _handle property is the handle of the module
from which the function will be loaded.
Creates a new CFuncPtr which calls a COM method.
Creates a new CFuncPtr with the specfied address.
Creates a new CFuncPtr with the specfied address.
we need to keep alive any methods which have arguments for the duration of the
call. Otherwise they could be collected on the finalizer thread before we come back.
Creates a method for calling with the specified signature. The returned method has a signature
of the form:
(IntPtr funcAddress, arg0, arg1, ..., object[] constantPool)
where IntPtr is the address of the function to be called. The arguments types are based upon
the types that the ArgumentMarshaller requires.
Base class for marshalling arguments from the user provided value to the
call stub. This class provides the logic for creating the call stub and
calling it.
Emits the IL to get the argument for the call stub generated into
a dynamic method.
Gets an expression which keeps alive the argument for the duration of the call.
Returns null if a keep alive is not necessary.
Gets the expression used to provide the argument. This is the expression
from an incoming DynamicMetaObject.
Provides marshalling of primitive values when the function type
has no type information or when the user has provided us with
an explicit cdata instance.
Provides marshalling for when the function type provide argument information.
Provides marshalling for when the user provides a native argument object
(usually gotten by byref or pointer) and the function type has no type information.
The meta class for ctypes function pointer instances.
Converts an object into a function call parameter.
Fields are created when a Structure is defined and provide
introspection of the structure.
Called for fields which have been limited to a range of bits. Given the
value for the full type this extracts the individual bits.
Called for fields which have been limited to a range of bits. Sets the
specified value into the bits for the field.
The meta class for ctypes pointers.
Converts an object into a function call parameter.
Access an instance at the specified address
The meta class for ctypes simple data types. These include primitives like ints,
floats, etc... char/wchar pointers, and untyped pointers.
Converts an object into a function call parameter.
Helper function for reading char/wchar's. This is used for reading from
arrays and pointers to avoid creating lots of 1-char strings.
Meta class for structures. Validates _fields_ on creation, provides factory
methods for creating instances from addresses and translating to parameters.
Converts an object into a function call parameter.
Structures just return themselves.
If our size/alignment hasn't been initialized then grabs the size/alignment
from all of our base classes. If later new _fields_ are added we'll be
initialized and these values will be replaced.
Base class for data structures. Subclasses can define _fields_ which
specifies the in memory layout of the values. Instances can then
be created with the initial values provided as the array. The values
can then be accessed from the instance by field name. The value can also
be passed to a foreign C API and the type can be used in other structures.
class MyStructure(Structure):
_fields_ = [('a', c_int), ('b', c_int)]
MyStructure(1, 2).a
MyStructure()
class MyOtherStructure(Structure):
_fields_ = [('c', MyStructure), ('b', c_int)]
MyOtherStructure((1, 2), 3)
MyOtherStructure(MyStructure(1, 2), 3)
The meta class for ctypes unions.
Converts an object into a function call parameter.
Enum which specifies the format type for a compiled struct
Struct used to store the format and the number of times it should be repeated.
Stops execution of Python or other .NET code on the main thread. If the thread is
blocked in native code the thread will be interrupted after it returns back to Python
or other .NET code.
Provides a dictionary storage implementation whose storage is local to
the thread.
Represents the date components that we found while parsing the date. Used for zeroing out values
which have different defaults from CPython. Currently we only know that we need to do this for
the year.
Samples on how to subtype built-in types from C#
an int variable for demonstration purposes
an int variable for demonstration purposes
Returns a new callable object with the provided initial set of arguments
bound to it. Calling the new function then appends to the additional
user provided arguments.
Creates a new partial object with the provided positional arguments.
Creates a new partial object with the provided positional and keyword arguments.
Calls func with the previously provided arguments and more positional arguments.
Calls func with the previously provided arguments and more positional arguments and keyword arguments.
Operator method to set arbitrary members on the partial object.
Operator method to get additional arbitrary members defined on the partial object.
Operator method to delete arbitrary members defined in the partial object.
Gets the function which will be called
Gets the initially provided positional arguments.
Gets the initially provided keyword arguments or None.
Gets or sets the dictionary used for storing extra attributes on the partial object.
BER encoding of an integer value is the number of bytes
required to represent the integer followed by the bytes
Duplicates a subprocess handle which was created for piping.
This is only called when we're duplicating the handle to make it inheritable to the child process. In CPython
the parent handle is always reliably garbage collected. Because we know this handle is not going to be
used we close the handle being duplicated.
Special hash function because IStructuralEquatable.GetHashCode is not allowed to throw.
Special equals because none of the special cases in Ops.Equals
are applicable here, and the reference equality check breaks some tests.
gets the object or throws a reference exception
Special equality function because IStructuralEquatable.Equals is not allowed to throw.
gets the object or throws a reference exception
Special equality function because IStructuralEquatable.Equals is not allowed to throw.
Returns the underlying .NET RegistryKey