IronPython.Modules 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. 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. flush() -> None. Does nothing. getvalue() -> bytes. Retrieve the entire contents of the BytesIO object. True if the file is closed. 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_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. 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. Popupates the given directory w/ the locale information from the given CultureInfo. 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. 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' 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 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. 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 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.