IronPython Gets the closure tuple from our parent context. Scope for the comprehension. Because scopes are usually statements and comprehensions are expressions this doesn't actually show up in the AST hierarchy and instead hangs off the comprehension expression. Pulls the closure tuple from our function/generator which is flowed into each function call. Returns an expression which creates the function object. Creates the LambdaExpression which is the actual function body. Creates the LambdaExpression which implements the body of the function. The functions signature is either "object Function(PythonFunction, ...)" where there is one object parameter for each user defined parameter or object Function(PythonFunction, object[]) for functions which take more than PythonCallTargets.MaxArgs arguments. Determines delegate type for the Python function Rewrites the tree for performing lookups against globals instead of being bound against the optimized scope. This is used if the user creates a function using public PythonFunction ctor. Returns true if the node can throw, false otherwise. Used to determine whether or not we need to update the current dynamic stack info. Creates a method frame for tracking purposes and enforces recursion Removes the frames from generated code for when we're compiling the tracing delegate which will track the frames it's self. A temporary variable to track if the current line number has been emitted via the fault update block. For example consider: try: raise Exception() except Exception, e: # do something here raise At "do something here" we need to have already emitted the line number, when we re-raise we shouldn't add it again. If we handled the exception then we should have set the bool back to false. We also sometimes directly check _lineNoUpdated to avoid creating this unless we have nested exceptions. A temporary variable to track the current line number Parameter base class Position of the parameter: 0-based index Parameter name Top-level ast for all Python code. Typically represents a module but could also be exec or eval code. Creates a new PythonAst without a body. ParsingFinished should be called afterwards to set the body. Called when parsing is complete, the body is built, the line mapping and language features are known. This is used in conjunction with the constructor which does not take a body. It enables creating the outer most PythonAst first so that nodes can always have a global parent. This lets an un-bound tree to still provide it's line information immediately after parsing. When we set the location of each node during construction we also set the global parent. When we name bind the global parent gets replaced with the real parent ScopeStatement. a mapping of where each line begins The body of code The language features which were set during parsing. Binds an AST and makes it capable of being reduced and compiled. Before calling Bind an AST cannot successfully be reduced. Creates a variable at the global level. Called for known globals (e.g. __name__), for variables explicitly declared global by the user, and names accessed but not defined in the lexical scope. Reduces the PythonAst to a LambdaExpression of type Type. True division is enabled in this AST. True if the with statement is enabled in this AST. True if absolute imports are enabled Returns a ScriptCode object for this PythonAst. The ScriptCode object can then be used to execute the code against it's closed over scope or to execute it against a different scope. Rewrites the tree for performing lookups against globals instead of being bound against the optimized scope. This is used if the user compiles optimied code and then runs it against a different scope. True if this is on-disk code which we don't really have an AST for. Represents a reference to a name. A PythonReference is created for each name referred to in a scope (global, class, or function). True iff there is a path in control flow graph on which the variable is used before initialized (assigned or deleted). True iff the variable is referred to from the inner scope. PythonWalker class - The Python AST Walker (default result is true) PythonWalkerNonRecursive class - The Python AST Walker (default result is false) The variable used to hold out parents closure tuple in our local scope. Gets the expression associated with the local CodeContext. If the function doesn't have a local CodeContext then this is the global context. True if this scope accesses a variable from an outer scope. True if an inner scope is accessing a variable defined in this scope. True if we are forcing the creation of a dictionary for storing locals. This occurs for calls to locals(), dir(), vars(), unqualified exec, and from ... import *. True if variables can be set in a late bound fashion that we don't know about at code gen time - for example via from foo import *. This is tracked independently of the ContainsUnqualifiedExec/NeedsLocalsDictionary Gets or creates the FunctionCode object for this FunctionDefinition. Variables that are bound in an outer scope - but not a global scope Variables that are bound to the global scope Variables that are referred to from a nested scope and need to be promoted to cells. Gets the expression for updating the dynamic stack trace at runtime when an exception is thrown. Gets the expression for the actual updating of the line number for stack traces to be available Wraps the body of a statement which should result in a frame being available during exception handling. This ensures the line number is updated as the stack is unwound. Provides a place holder for the expression which represents a FunctionCode. For functions/classes this gets updated after the AST has been generated because the FunctionCode needs to know about the tree which gets generated. For modules we immediately have the value because it always comes in as a parameter. Reducible node so that re-writing for profiling does not occur until after the script code has been completed and is ready to be compiled. Without this extra node profiling would force reduction of the node and we wouldn't have setup our constant access correctly yet. Fake ScopeStatement for FunctionCode's to hold on to after we have deserialized pre-compiled code. True if the user provided a step parameter (either providing an explicit parameter or providing an empty step parameter) false if only start and stop were provided. The statements under the try-block. Array of except (catch) blocks associated with this try. NULL if there are no except blocks. The body of the optional Else block for this try. NULL if there is no Else block. The body of the optional finally associated with this try. NULL if there is no finally block. Transform multiple python except handlers for a try block into a single catch body. The variable for the exception in the catch block. Null if there are no except handlers. Else the statement to go inside the catch handler Surrounds the body of an except block w/ the appropriate code for maintaining the traceback. Local variable. Local variables can be referenced from nested lambdas Parameter to a LambdaExpression Like locals, they can be referenced from nested lambdas Global variable Should only appear in global (top level) lambda. WithStatement is translated to the DLR AST equivalent to the following Python code snippet (from with statement spec): mgr = (EXPR) exit = mgr.__exit__ # Not calling it yet value = mgr.__enter__() exc = True try: VAR = value # Only if "as VAR" is present BLOCK except: # The exceptional case is handled here exc = False if not exit(*sys.exc_info()): raise # The exception is swallowed if exit() returns true finally: # The normal and non-local-goto cases are handled here if exc: exit(None, None, None) A global allocator that puts all of the globals into an array access. The array is an array of PythonGlobal objects. We then just close over the array for any inner functions. Once compiled a RuntimeScriptCode is produced which is closed over the entire execution environment. Provides globals for when we need to lookup into a dictionary for each global access. This is the slowest form of globals and is only used when we need to run against an arbitrary dictionary given to us by a user. Implements globals which are backed by a static type, followed by an array if the static types' slots become full. The global variables are stored in static fields on a type for fast access. The type also includes fields for constants and call sites so they can be accessed much fasetr. We don't generate any code into the type though - DynamicMethod's are much faster for code gen then normal ref emit. Implements globals which are backed by a static type, followed by an array if the static types' slots become full. The global variables are stored in static fields on a type for fast access. The type also includes fields for constants and call sites so they can be accessed much fasetr. We don't generate any code into the type though - DynamicMethod's are much faster for code gen then normal ref emit. Ensures the underlying array is long enough to accomodate the given index The context storage type corresponding to the given index Ensures the underlying array is long enough to accomodate the given index The constant storage type corresponding to the given index Ensures the underlying array is long enough to accomodate the given index The global storage type corresponding to the given index Ensures the underlying array is long enough to accomodate the given index The site storage type corresponding to the given index Small reducable node which just fetches the value from a ClosureCell object. Like w/ global variables the compiler recognizes these on sets and turns them into assignments on the python global object. Gets the expression which points at the closure cell. The original expression for the incoming parameter if this is a parameter closure. Otherwise the value is null. Gets the PythonVariable for which this closure expression was created. Creates the storage for the closure cell. If this is a closure over a parameter it captures the initial incoming parameter value. Reduces the closure cell to a read of the value stored in the cell. Assigns a value to the closure cell. Removes the current value from the closure cell. Tracking for variables lifted into closure objects. Used to store information in a function about the outer variables it accesses. Specifies the compilation mode which will be used during the AST transformation Compilation will proceed in a manner in which the resulting AST can be serialized to disk. Compilation will use a type and declare static fields for globals. The resulting type is uncollectible and therefore extended use of this will cause memory leaks. Compilation will use an array for globals. The resulting code will be fully collectible and once all references are released will be collected. Compilation will force all global accesses to do a full lookup. This will also happen for any unbound local references. This is the slowest form of code generation and is only used for exec/eval code where we can run against an arbitrary dictionary. When finding a yield return or yield break, this rewriter flattens out containing blocks, scopes, and expressions with stack state. All scopes encountered have their variables promoted to the generator's closure, so they survive yields. Spills the right side into a temp, and replaces it with its temp. Returns the expression that initializes the temp. Makes an assignment to this variable. Pushes the assignment as far into the right side as possible, to allow jumps into it. Accesses the property of a tuple. The node can be created first and then the tuple and index type can be filled in before the tree is actually generated. This enables creation of these nodes before the tuple type is actually known. Represents code which can be lazily compiled. The code is created in an AST which provides the Expression of T and whether or not the code should be interpreted. For non-pre compiled scenarios the code will not be compiled until the 1st time it is run. For pre-compiled scenarios the code is IExpressionSerializable and will turn into a normal pre-compiled method. A ScriptCode which has been loaded from an assembly which is saved on disk. Creates a fake PythonAst object which is represenative of the on-disk script code. Language features initialized on parser construction and possibly updated during parsing. The code can set the language features (e.g. "from __future__ import division"). Parse one or more lines of interactive input null if input is not yet valid but could be with more lines Given the interactive text input for a compound statement, calculate what the indentation level of the next line should be Peek if the next token is a 'yield' and parse a yield expression. Else return null. Called w/ yield already eaten. A yield expression if present, else null. Maybe eats a new line token returning true if the token was eaten. Python always tokenizes to have only 1 new line character in a row. But we also craete NLToken's and ignore them except for error reporting purposes. This gives us the same errors as CPython and also matches the behavior of the standard library tokenize module. This function eats any present NL tokens and throws them away. Eats a new line token throwing if the next token isn't a new line. Python always tokenizes to have only 1 new line character in a row. But we also craete NLToken's and ignore them except for error reporting purposes. This gives us the same errors as CPython and also matches the behavior of the standard library tokenize module. This function eats any present NL tokens and throws them away. Creates a new PythonCompilerOptions with the default language features enabled. Creates a new PythonCompilerOptions with the specified language features enabled. Creates a new PythonCompilerOptions and enables or disables true division. This overload is obsolete, instead you should use the overload which takes a ModuleOptions. Gets or sets the initial indentation. This can be set to allow parsing partial blocks of code that are already indented. For each element of the array there is an additional level of indentation. Each integer value represents the number of spaces used for the indentation. If this value is null then no indentation level is specified. Provides cached global variable for modules to enable optimized access to module globals. Both the module global value and the cached value can be held onto and the cached value can be invalidated by the providing LanguageContext. The cached value is provided by the LanguageContext.GetModuleCache API. Small reducable node which just fetches the value from a PythonGlobal object. The compiler recognizes these on sets and turns them into assignments on the python global object. A ScriptCode which can be saved to disk. We only create this when called via the clr.CompileModules API. This ScriptCode does not support running. Represents a script code which can be dynamically bound to execute against arbitrary Scope objects. This is used for code when the user runs against a particular scope as well as for exec and eval code as well. It is also used when tracing is enabled. Provides a wrapper around "dynamic" expressions which we've opened coded (for optimized code generation). This lets us recognize both normal Dynamic and our own Dynamic expressions and apply the combo binder on them. Represents a script code which can be consumed at runtime as-is. This code has no external dependencies and is closed over its scope. Summary description for Token. IronPython tokenizer Used to create tokenizer for hosting API. Equality comparer that can compare strings to our current token w/o creating a new string first. True if the last characters in the buffer are a backslash followed by a new line indicating that their is an incompletement statement which needs further input to complete. Returns whether the Resizes an array to a speficied new size and copies a portion of the original array into its beginning. Provides helpers for interacting with IronPython. Creates a new ScriptRuntime with the IronPython scipting engine pre-configured. Creates a new ScriptRuntime with the IronPython scipting engine pre-configured and additional options. Creates a new ScriptRuntime with the IronPython scripting engine pre-configured in the specified AppDomain. The remote ScriptRuntime may be manipulated from the local domain but all code will run in the remote domain. Creates a new ScriptRuntime with the IronPython scripting engine pre-configured in the specified AppDomain with additional options. The remote ScriptRuntime may be manipulated from the local domain but all code will run in the remote domain. Creates a new ScriptRuntime and returns the ScriptEngine for IronPython. If the ScriptRuntime is required it can be acquired from the Runtime property on the engine. Creates a new ScriptRuntime with the specified options and returns the ScriptEngine for IronPython. If the ScriptRuntime is required it can be acquired from the Runtime property on the engine. Creates a new ScriptRuntime and returns the ScriptEngine for IronPython. If the ScriptRuntime is required it can be acquired from the Runtime property on the engine. The remote ScriptRuntime may be manipulated from the local domain but all code will run in the remote domain. Creates a new ScriptRuntime with the specified options and returns the ScriptEngine for IronPython. If the ScriptRuntime is required it can be acquired from the Runtime property on the engine. The remote ScriptRuntime may be manipulated from the local domain but all code will run in the remote domain. Given a ScriptRuntime gets the ScriptEngine for IronPython. Gets a ScriptScope which is the Python sys module for the provided ScriptRuntime. Gets a ScriptScope which is the Python sys module for the provided ScriptEngine. Gets a ScriptScope which is the Python __builtin__ module for the provided ScriptRuntime. Gets a ScriptScope which is the Python __builtin__ module for the provided ScriptEngine. Gets a ScriptScope which is the Python clr module for the provided ScriptRuntime. Gets a ScriptScope which is the Python clr module for the provided ScriptEngine. Imports the Python module by the given name and returns its ScriptSCope. If the module does not exist an exception is raised. Imports the Python module by the given name and returns its ScriptSCope. If the module does not exist an exception is raised. Imports the Python module by the given name and inserts it into the ScriptScope as that name. If the module does not exist an exception is raised. Sets sys.exec_prefix, sys.executable and sys.version and adds the prefix to sys.path Sets sys.exec_prefix, sys.executable and sys.version and adds the prefix to sys.path Enables call tracing for the current thread in this ScriptEngine. TracebackDelegate will be called back for each function entry, exit, exception, and line change. Enables call tracing for the current thread for the Python engine in this ScriptRuntime. TracebackDelegate will be called back for each function entry, exit, exception, and line change. Provides nested level debugging support when SetTrace or SetProfile are used. This saves the current tracing information and then calls the provided object. Provides nested level debugging support when SetTrace or SetProfile are used. This saves the current tracing information and then calls the provided object. Creates a ScriptRuntimeSetup object which includes the Python script engine with the specified options. The ScriptRuntimeSetup object can then be additional configured and used to create a ScriptRuntime. Creates a LanguageSetup object which includes the Python script engine with the specified options. The LanguageSetup object can be used with other LanguageSetup objects from other languages to configure a ScriptRuntimeSetup object. Creates a new PythonModule with the specified name and published it in sys.modules. Returns the ScriptScope associated with the module. Creates a new PythonModule with the specified name and filename published it in sys.modules. Returns the ScriptScope associated with the module. Creates a new PythonModule with the specified name, filename, and doc string and published it in sys.modules. Returns the ScriptScope associated with the module. Gets the list of loaded Python module files names which are available in the provided ScriptEngine. A simple Python command-line should mimic the standard python.exe Returns the display look for IronPython. The returned string uses This \n instead of Environment.NewLine for it's line seperator because it is intended to be outputted through the Python I/O system. Loads any extension DLLs present in sys.prefix\DLLs directory and adds references to them. This provides an easy drop-in location for .NET assemblies which should be automatically referenced (exposed via import), COM libraries, and pre-compiled Python code. Attempts to run a single interaction and handle any language-specific exceptions. Base classes can override this and call the base implementation surrounded with their own exception handling. Returns null if successful and execution should continue, or an exit code. Parses a single interactive command and executes it. Returns null if successful and execution should continue, or the appropiate exit code. Skip the first line of the code to execute. This is useful for executing Unix scripts which have the command to execute specified in the first line. This only apply to the script code executed by the ScriptEngine APIs, but not for other script code that happens to get called as a result of the execution. On error. Helper class for implementing the Python class. This is exposed as a service through PythonEngine and the helper class uses this service to get the correct remoting semantics. Returns an ObjectHandle to a delegate of type Action[Action] which calls the current command dispatcher. The error involved an incomplete statement due to an unexpected EOF. The error involved an incomplete token. The mask for the actual error values The error was a general syntax error The error was an indentation error. The error was a tab error. syntax error shouldn't include a caret (no column offset should be included) Marks that the return value of a function might include NotImplemented. This is added to an operator method to ensure that all necessary methods are called if one cannot guarantee that it can perform the comparison. Specialized version because enumerating tuples by Python's definition doesn't call __getitem__, but filter does! Opens a file and returns a new file object. name -> the name of the file to open. mode -> the mode to open the file (r for reading, w for writing, a for appending, default is r). bufsize -> the size of the buffer to be used (<= 0 indicates to use the default size) Creates a new Python file object from a .NET stream object. stream -> the stream to wrap in a file object. object overload of range - attempts to convert via __int__, and __trunc__ if arg is an OldInstance object overload of range - attempts to convert via __int__, and __trunc__ if arg is an OldInstance Gets the appropriate LanguageContext to be used for code compiled with Python's compile, eval, execfile, etc... Returns true if we should inherit our callers context (true division, etc...), false otherwise Returns the default compiler flags or the flags the user specified. Gets a scope used for executing new code in optionally replacing the globals and locals dictionaries. Returns detailed call statistics. Not implemented in IronPython and always returns None. Handles output of the expression statement. Prints the value and sets the __builtin__._ Not used. Not used. Not an actual node. We don't create this, but it's here for compatibility. A strongly-typed resource class, for looking up localized strings, etc. Returns the cached ResourceManager instance used by this class. Overrides the current thread's CurrentUICulture property for all resource lookups using this strongly typed resource class. Looks up a localized string similar to couldn't find member {0}. Looks up a localized string similar to default value must be specified here. Looks up a localized string similar to duplicate argument '{0}' in function definition. Looks up a localized string similar to duplicate keyword argument. Looks up a localized string similar to <eof> while reading string. Looks up a localized string similar to EOF while scanning triple-quoted string. Looks up a localized string similar to EOL while scanning single-quoted string. Looks up a localized string similar to expected an indented block. Looks up a localized string similar to expected name. Looks up a localized string similar to Expecting identifier:. Looks up a localized string similar to inconsistent use of tabs and spaces in indentation. Looks up a localized string similar to unindent does not match any outer indentation level. Looks up a localized string similar to Invalid argument value.. Looks up a localized string similar to MakeGenericType on non-generic type. Looks up a localized string similar to Invalid parameter collection for the function.. Looks up a localized string similar to invalid token Looks up a localized string similar to invalid syntax. Looks up a localized string similar to object ({0}) is not creatable w/ keyword arguments. Looks up a localized string similar to keywords must come before * args. Looks up a localized string similar to type does not have {0} field. Looks up a localized string similar to from __future__ imports must occur at the beginning of the file. Looks up a localized string similar to 'return' outside function. Looks up a localized string similar to 'yield' outside function. Looks up a localized string similar to NEWLINE in double-quoted string. Looks up a localized string similar to NEWLINE in single-quoted string. Looks up a localized string similar to future statement does not support import *. Looks up a localized string similar to non-keyword arg after keyword arg. Looks up a localized string similar to not a chance. Looks up a localized string similar to The method or operation is not implemented.. Looks up a localized string similar to only one ** allowed. Looks up a localized string similar to only one * allowed. Looks up a localized string similar to Context must be PythonCompilerContext. Looks up a localized string similar to cannot delete slot. Looks up a localized string similar to cannot get slot. Looks up a localized string similar to cannot set slot. Looks up a localized string similar to static property '{0}' of '{1}' can only be read through a type, not an instance. Looks up a localized string similar to static property '{0}' of '{1}' can only be assigned to through a type, not an instance. Looks up a localized string similar to no value for this token. Looks up a localized string similar to too many versions. Looks up a localized string similar to unexpected token '{0}'. Looks up a localized string similar to future feature is not defined:. Provides support for emitting warnings when built in methods are invoked at runtime. Backwards compatible Convert for the old sites that need to flow CodeContext Creates a new InvokeBinder which will call with positional splatting. The signature of the target site should be object(function), object[], retType Creates a new InvokeBinder which will call with positional and keyword splatting. The signature of the target site should be object(function), object[], dictionary, retType Common helpers used by the various binding logic. Tries to get the BuiltinFunction for the given name on the type of the provided MetaObject. Succeeds if the MetaObject is a BuiltinFunction or BuiltinMethodDescriptor. Gets the best CallSignature from a MetaAction. The MetaAction should be either a Python InvokeBinder, or a DLR InvokeAction or CreateAction. For Python we can use a full-fidelity Transforms an invoke member into a Python GetMember/Invoke. The caller should verify that the given attribute is not resolved against a normal .NET class before calling this. If it is a normal .NET member then a fallback InvokeMember is preferred. Determines if the type associated with the first MetaObject is a subclass of the type associated with the second MetaObject. Adds a try/finally which enforces recursion limits around the target method. Helper to do fallback for Invoke's so we can handle both StandardAction and Python's InvokeBinder. Converts arguments into a form which can be used for COM interop. The argument is only converted if we have an IronPython specific conversion when calling COM methods. Converts a single argument into a form which can be used for COM interop. The argument is only converted if we have an IronPython specific conversion when calling COM methods. Fallback action for performing an invoke from Python. We translate the CallSignature which supports splatting position and keyword args into their expanded form. Builds up a series of conditionals when the False clause isn't yet known. We can keep appending conditions and if true's. Each subsequent true branch becomes the false branch of the previous condition and body. Finally a non-conditional terminating branch must be added. Adds a new conditional and body. The first call this becomes the top-level conditional, subsequent calls will have it added as false statement of the previous conditional. If present, converts the finish condition body be a normal conditional body. The builder instance will become unfinished again. If no finish condition body is available, this extends the last condition check with the new condition. Adds the non-conditional terminating node. Returns true if no conditions have been added Returns true if a final, non-conditional, body has been added. Gets the resulting meta object for the full body. FinishCondition must have been called. Adds a variable which will be scoped at the level of the final expression. ArgBuilder which provides the CodeContext parameter to a method. Fallback action for performing a new() on a foreign IDynamicMetaObjectProvider. used when call falls back. Base class for all of our fast get delegates. This holds onto the delegate and provides the Update function. Updates the call site when the current rule is no longer applicable. Base class for all of our fast set delegates. This holds onto the delegate and provides the Update and Optimize functions. Updates the call site when the current rule is no longer applicable. An interface that is implemented on DynamicMetaObjects. This allows objects to opt-into custom conversions when calling COM APIs. The IronPython binders all call this interface before doing any COM binding. Interface used to mark objects which contain a dictionary of custom attributes that shadow their existing attributes in a dynamic fashion. Ensures that a non-null IDictionary instance is created for CustomAttributes and returns it. Meta-object which allows IPythonExpandable objects to behave like Python objects in their ability to dynamically add and remove new or existing custom attributes, generally shadowing existing built-in members. Getting: Member accesses first consult the object's CustomAttributes dictionary, then fall through to the underlying object. Setting: Values can be bound to any member name, shadowing any existing attributes except public non-PythonHidden fields and properties, which will bypass the dictionary. Thus, it is possible for SetMember to fail, for example if the property is read-only or of the wrong type. Deleting: Any member represented in the dictionary can be deleted, re-exposing the underlying member if it exists. Any other deletions will fail. Interface used to mark objects as being invokable from Python. These objects support calling with splatted positional and keyword arguments. Gets the PythonContext which the CallSiteBinder is associated with. Provides a MetaObject for instances of Python's old-style classes. TODO: Lots of CodeConetxt references, need to move CodeContext onto OldClass and pull it from there. Performs the actual work of binding to the function. Overall this works by going through the arguments and attempting to bind all the outstanding known arguments - position arguments and named arguments which map to parameters are easy and handled in the 1st pass for GetArgumentsForRule. We also pick up any extra named or position arguments which will need to be passed off to a kw argument or a params array. After all the normal args have been assigned to do a 2nd pass in FinishArguments. Here we assign a value to either a value from the params list, kw-dict, or defaults. If there is ambiguity between this (e.g. we have a splatted params list, kw-dict, and defaults) we call a helper which extracts them in the proper order (first try the list, then the dict, then the defaults). Makes the test for our rule. Makes the test when we just have simple positional arguments. Makes the test when we have a keyword argument call or splatting. Gets the array of expressions which correspond to each argument for the function. These correspond with the function as it's defined in Python and must be transformed for our delegate type before being used. Binds any missing arguments to values from params array, kw dictionary, or default values. Creates the argument for the list expansion parameter. Adds extra positional arguments to the start of the expanded list. Creates the argument for the dictionary expansion parameter. Adds an unbound keyword argument into the dictionary. Adds a check to the last parameter (so it's evaluated after we've extracted all the parameters) to ensure that we don't have any extra params or kw-params when we don't have a params array or params dict to expand them into. Helper function to validate that a named arg isn't duplicated with by a params list or the dictionary (or both). Helper function to get a value (which has no default) from either the params list or the dictionary (or both). Helper function to get the specified variable from the dictionary. Helper function to extract the variable from defaults, or to call a helper to check params / kw-dict / defaults to see which one contains the actual value. Helper function to extract from the params list or dictionary depending upon which one has an available value. Helper function to extract the next argument from the params list. Fixes up the argument list for the appropriate target delegate type. Helper function to get the function argument strongly typed. Called when the user is expanding a dictionary - we copy the user dictionary and verify that it contains only valid string names. Called when the user is expanding a params argument Called when the user hasn't supplied a dictionary to be expanded but the function takes a dictionary to be expanded. Helper function to create the expression for creating the actual tuple passed through. Creates the code to invoke the target delegate function w/ the specified arguments. Appends the initialization code for the call to the function if any exists. Creates a target which creates a new dynamic method which contains a single dynamic site that invokes the callable object. TODO: This should be specialized for each callable object Creating a standard .NET type is easy - we just call it's constructor with the provided arguments. Creating a Python type involves calling __new__ and __init__. We resolve them and generate calls to either the builtin funcions directly or embed sites which call the slots at runtime. Checks if we have a default new and init - in this case if we have any arguments we don't allow the call. Creates a test which tests the specific version of the type. Base class for performing member binding. Derived classes override Add methods to produce the actual final result based upon what the GetBinderHelper resolves. Provides the normal meta binder binding. Provides delegate based fast binding. Various helpers related to calling Python __*__ conversion methods Helper for falling back - if we have a base object fallback to it first (which can then fallback to the calling site), otherwise fallback to the calling site. Helper for falling back - if we have a base object fallback to it first (which can then fallback to the calling site), otherwise fallback to the calling site. Provides the lookup logic for resolving a Python object. Subclasses provide the actual logic for producing the binding result. Currently there are two forms of the binding result: one is the DynamicMetaObject form used for non-optimized bindings. The other is the Func of CallSite, object, CodeContext, object form which is used for fast binding and pre-compiled rules. GetBinder which produces a DynamicMetaObject. This binder always successfully produces a DynamicMetaObject which can perform the requested get. Makes a rule which calls a user-defined __getattribute__ function and falls back to __getattr__ if that raises an AttributeError. slot is the __getattribute__ method to be called. Checks a range of the MRO to perform old-style class lookups if any old-style classes are present. We will call this twice to produce a search before a slot and after a slot. Checks to see if this type has __getattribute__ that overrides all other attribute lookup. This is more complex then it needs to be. The problem is that when we have a mixed new-style/old-style class we have a weird __getattribute__ defined. When we always dispatch through rules instead of PythonTypes it should be easy to remove this. Helper for falling back - if we have a base object fallback to it first (which can then fallback to the calling site), otherwise fallback to the calling site. Looks up the associated PythonTypeSlot from the object. Indicates if the result came from a standard .NET type in which case we will fallback to the sites binder. Helper for falling back - if we have a base object fallback to it first (which can then fallback to the calling site), otherwise fallback to the calling site. Helper for falling back - if we have a base object fallback to it first (which can then fallback to the calling site), otherwise fallback to the calling site. Provides a way for the binder to provide a custom error message when lookup fails. Just doing this for the time being until we get a more robust error return mechanism. Provides a way for the binder to provide a custom error message when lookup fails. Just doing this for the time being until we get a more robust error return mechanism. Gets the PythonBinder associated with tihs CodeContext Performs .NET member resolution. This looks within the given type and also includes any extension members. Base classes and their extension members are not searched. Performs .NET member resolution. This looks within the given type and also includes any extension members. Base classes and their extension members are not searched. This version allows PythonType's for protected member resolution. It shouldn't be called externally for other purposes. Performs .NET member resolution. This looks the type and any base types for members. It also searches for extension members in the type and any base types. Gets the member names which are defined in this type and any extension members. This search does not include members in any subtypes or their extension members. Gets the member names which are defined in the type and any subtypes. This search includes members in the type and any subtypes as well as extension types of the type and its subtypes. Creates the initial table of extension types. These are standard extension that we apply to well known .NET types to make working with them better. Being added to this table does not make a type a Python type though so that it's members are generally accessible w/o an import clr and their type is not re-named. Creates a table of standard .NET types which are also standard Python types. These types have a standard set of extension types which are shared between all runtimes. Event handler for when our domain manager has an assembly loaded by the user hosting the script runtime. Here we can gather any information regarding extension methods. Currently DLR-style extension methods become immediately available w/o an explicit import step. Provides a cache from Type/name -> PythonTypeSlot and also allows access to all members (and remembering whether all members are cached). Writes to a cache the result of a type lookup. Null values are allowed for the slots and they indicate that the value does not exist. Looks up a cached type slot for the specified member and type. This may return true and return a null slot - that indicates that a cached result for a member which doesn't exist has been stored. Otherwise it returns true if a slot is found or false if it is not. Looks up a cached member group for the specified member and type. This may return true and return a null group - that indicates that a cached result for a member which doesn't exist has been stored. Otherwise it returns true if a group is found or false if it is not. Checks to see if all members have been populated for the provided type. Populates the type with all the provided members and marks the type as being fully cached. The dictionary is used for the internal storage and should not be modified after providing it to the cache. Returns an enumerable object which provides access to all the members of the provided type. The caller must check that the type is fully cached and populate the cache if it isn't before calling this method. Python's Invoke is a non-standard action. Here we first try to bind through a Python internal interface (IPythonInvokable) which supports CallSigantures. If that fails and we have an IDO then we translate to the DLR protocol through a nested dynamic site - this includes unsplatting any keyword / position arguments. Finally if it's just a plain old .NET type we use the default binder which supports CallSignatures. The Action used for Python call sites. This supports both splatting of position and keyword arguments. When a foreign object is encountered the arguments are expanded into normal position/keyword arguments. Python's Invoke is a non-standard action. Here we first try to bind through a Python internal interface (IPythonInvokable) which supports CallSigantures. If that fails and we have an IDO then we translate to the DLR protocol through a nested dynamic site - this includes unsplatting any keyword / position arguments. Finally if it's just a plain old .NET type we use the default binder which supports CallSignatures. Fallback - performs the default binding operation if the object isn't recognized as being invokable. Gets the CallSignature for this invocation which describes how the MetaObject array is to be mapped. Creates a nested dynamic site which uses the unpacked arguments. Translates our CallSignature into a DLR Argument list and gives the simple MetaObject's which are extracted from the tuple or dictionary parameters being splatted. The result type of the operation. Custom dynamic site kinds for simple sites that just take a fixed set of parameters. Unary operator. Gets various documentation about the object returned as a string Unary operator. Gets information about the type of parameters, returned as a string. Unary operator. Checks whether the object is callable or not, returns true if it is. Binary operator. Checks to see if the instance contains another object. Returns true or false. Unary operator. Returns the number of items stored in the object. Binary operator. Compares two instances returning an integer indicating the relationship between them. May throw if the object types are uncomparable. Binary operator. Returns both the dividend and quotioent of x / y. Unary operator. Get the absolute value of the instance. Unary operator. Gets the positive value of the instance. Unary operator. Negates the instance and return the new value. Unary operator. Returns the ones complement of the instance. Unary operator. Boolean negation Unary operator. Negation, returns object Get enumerator for iteration binder. Returns a KeyValuePair<IEnumerator, IDisposable> The IEnumerator is used for iteration. The IDisposable is provided if the object was an IEnumerable or IEnumerable<T> and is a disposable object. Operator for performing add Operator for performing sub Operator for performing pow Operator for performing mul Operator for performing floordiv Operator for performing div Operator for performing truediv Operator for performing mod Operator for performing lshift Operator for performing rshift Operator for performing and Operator for performing or Operator for performing xor Operator for performing lt Operator for performing gt Operator for performing le Operator for performing ge Operator for performing eq Operator for performing ne Operator for performing lg Operator for performing in-place add Operator for performing in-place sub Operator for performing in-place pow Operator for performing in-place mul Operator for performing in-place floordiv Operator for performing in-place div Operator for performing in-place truediv Operator for performing in-place mod Operator for performing in-place lshift Operator for performing in-place rshift Operator for performing in-place and Operator for performing in-place or Operator for performing in-place xor Operator for performing reverse add Operator for performing reverse sub Operator for performing reverse pow Operator for performing reverse mul Operator for performing reverse floordiv Operator for performing reverse div Operator for performing reverse truediv Operator for performing reverse mod Operator for performing reverse lshift Operator for performing reverse rshift Operator for performing reverse and Operator for performing reverse or Operator for performing reverse xor Operator for performing reverse divmod Provides binding logic which is implemented to follow various Python protocols. This includes things such as calling __call__ to perform calls, calling __nonzero__/__len__ to convert to bool, calling __add__/__radd__ to do addition, etc... This logic gets shared between both the IDynamicMetaObjectProvider implementation for Python objects as well as the Python sites. This ensures the logic we follow for our builtin types and user defined types is identical and properly conforming to the various protocols. Gets a MetaObject which converts the provided object to a bool using __nonzero__ or __len__ protocol methods. This code is shared between both our fallback for a site and our MetaObject for user defined objects. Used for conversions to bool Creates a rule for the contains operator. This is exposed via "x in y" in IronPython. It is implemented by calling the __contains__ method on x and passing in y. If a type doesn't define __contains__ but does define __getitem__ then __getitem__ is called repeatedly in order to see if the object is there. For normal .NET enumerables we'll walk the iterator and see if it's present. Delegate for finishing the comparison. This takes in a condition and a return value and needs to update the ConditionalBuilder with the appropriate resulting body. The condition may be null. Helper to handle a comparison operator call. Checks to see if the call can return NotImplemented and allows the caller to modify the expression that is ultimately returned (e.g. to turn __cmp__ into a bool after a comparison) calls __coerce__ for old-style classes and performs the operation if the coercion is successful. Makes the comparison rule which returns an int (-1, 0, 1). TODO: Better name? Python has three protocols for slicing: Simple Slicing x[i:j] Extended slicing x[i,j,k,...] Long Slice x[start:stop:step] The first maps to __*slice__ (get, set, and del). This takes indexes - i, j - which specify the range of elements to be returned. In the slice variants both i, j must be numeric data types. The 2nd and 3rd are both __*item__. This receives a single index which is either a Tuple or a Slice object (which encapsulates the start, stop, and step values) This is in addition to a simple indexing x[y]. For simple slicing and long slicing Python generates Operators.*Slice. For the extended slicing and simple indexing Python generates a Operators.*Item action. Extended slicing maps to the normal .NET multi-parameter input. So our job here is to first determine if we're to call a __*slice__ method or a __*item__ method. Helper to convert all of the arguments to their known types. Gets the arguments that need to be provided to __*item__ when we need to pass a slice object. Base class for calling indexers. We have two subclasses that target built-in functions and user defined callable objects. The Callable objects get handed off to ItemBuilder's which then call them with the appropriate arguments. Creates a new CallableObject. If BuiltinFunction is available we'll create a BuiltinCallable otherwise we create a SlotCallable. Gets the arguments in a form that should be used for extended slicing. Python defines that multiple tuple arguments received (x[1,2,3]) get packed into a Tuple. For most .NET methods we just want to expand this into the multiple index arguments. For slots and old-instances we want to pass in the tuple Adds the target of the call to the rule. Subclass of Callable for a built-in function. This calls a .NET method performing the appropriate bindings. Callable to a user-defined callable object. This could be a Python function, a class defining __call__, etc... Base class for building a __*item__ or __*slice__ call. Derived IndexBuilder for calling __*slice__ methods Derived IndexBuilder for calling __*item__ methods. Helper to get the symbols for __*item__ and __*slice__ based upon if we're doing a get/set/delete and the minimum number of arguments required for each of those. Checks if a coercion check should be performed. We perform coercion under the following situations: 1. Old instances performing a binary operator (excluding rich comparisons) 2. User-defined new instances calling __cmp__ but only if we wouldn't dispatch to a built-in __coerce__ on the parent type This matches the behavior of CPython. Produces an error message for the provided message and type names. The error message should contain string formatting characters ({0}, {1}, etc...) for each of the type names. Provides an abstraction for calling something which might be a builtin function or might be some arbitrary user defined slot. If the object is a builtin function the call will go directly to the underlying .NET method. If the object is an arbitrary callable object we will setup a nested dynamic site for performing the additional dispatch. TODO: We could probably do a specific binding to the object if it's another IDyanmicObject. Combines two methods, which came from two different binary types, selecting the method which has the best set of conversions (the conversions which result in the least narrowing). Tries to get a MethodBinder associated with the slot for the specified type. If a method is found the binder is set and true is returned. If nothing is found binder is null and true is returned. If something other than a method is found false is returned. TODO: Remove rop Implements a built-in module which is instanced per PythonContext. Implementers can subclass this type and then have a module which has efficient access to internal state (this doesn't need to go through PythonContext.GetModuleState). These modules can also declare module level globals which they'd like to provide efficient access to by overloading GetGlobalVariableNames. When Initialize is called these globals are provided and can be cached in the instance for fast global access. Just like normal static modules these modules are registered with the PythonModuleAttribute. Initializes the module for it's first usage. By default this calls PerformModuleReload with the the dictionary. The CodeContext for the module. A list of globals which have optimize access. Contains at least all of the global variables reutrned by GetGlobalVariableNames. Gets a list of variable names which should have optimized storage (instances of PythonGlobal objects). The module receives the global objects during the Initialize call and can hold onto them for direct access to global members. Called when the user attempts to reload() on your module and by the base class Initialize method. This provides an opportunity to allocate any per-module data which is not simply function definitions. A common usage here is to create exception objects which are allocated by the module using PythonExceptions.CreateSubType. Provides access to the PythonContext which this module was created for. Provides access to the CodeContext for the module. Returns null before Initialize() is called. bytearray(string, encoding[, errors]) -> bytearray bytearray(iterable) -> bytearray Construct a mutable bytearray object from: - an iterable yielding values in range(256), including: + a list of integer values + a bytes, bytearray, buffer, or array object - a text string encoded using the specified encoding bytearray([int]) -> bytearray Construct a zero-ititialized bytearray of the specified length. (default=0) return true if self is a titlecased string and there is at least one character in self; also, uppercase characters may only follow uncased characters (e.g. whitespace) and lowercase characters only cased ones. return false otherwise. Return a string which is the concatenation of the strings in the sequence seq. The separator between elements is the string providing this method This overload is specifically implemented because in IronPython strings are unicode return true if self is a titlecased string and there is at least one character in self; also, uppercase characters may only follow uncased characters (e.g. whitespace) and lowercase characters only cased ones. return false otherwise. Return a string which is the concatenation of the strings in the sequence seq. The separator between elements is the string providing this method Returns a copy of the internal byte array. System.Byte[] This method returns the underlying byte array directly. It should be used sparingly! System.Byte[] Marks a method as being a class method. The PythonType which was used to access the method will then be passed as the first argument. this class contains objecs and static methods used for .NET/CLS interop with Python. Gets the current ScriptDomainManager that IronPython is loaded into. The ScriptDomainManager can then be used to work with the language portion of the DLR hosting APIs. Use(name) -> module Attempts to load the specified module searching all languages in the loaded ScriptRuntime. Use(path, language) -> module Attempts to load the specified module belonging to a specific language loaded into the current ScriptRuntime. SetCommandDispatcher(commandDispatcher) Sets the current command dispatcher for the Python command line. The command dispatcher will be called with a delegate to be executed. The command dispatcher should invoke the target delegate in the desired context. A common use for this is to enable running all REPL commands on the UI thread while the REPL continues to run on a non-UI thread. LoadTypeLibrary(rcw) -> type lib desc Gets an ITypeLib object from OLE Automation compatible RCW , reads definitions of CoClass'es and Enum's from this library and creates an object that allows to instantiate coclasses and get actual values for the enums. LoadTypeLibrary(guid) -> type lib desc Reads the latest registered type library for the corresponding GUID, reads definitions of CoClass'es and Enum's from this library and creates a IDynamicMetaObjectProvider that allows to instantiate coclasses and get actual values for the enums. AddReferenceToTypeLibrary(rcw) -> None Makes the type lib desc available for importing. See also LoadTypeLibrary. AddReferenceToTypeLibrary(guid) -> None Makes the type lib desc available for importing. See also LoadTypeLibrary. Gets the CLR Type object from a given Python type object. Gets the Python type object from a given CLR Type object. OBSOLETE: Gets the Python type object from a given CLR Type object. Use clr.GetPythonType instead. accepts(*types) -> ArgChecker Decorator that returns a new callable object which will validate the arguments are of the specified types. returns(type) -> ReturnChecker Returns a new callable object which will validate the return type is of the specified type. Decorator for verifying the arguments to a function are of a specified type. Returned value when using clr.accepts/ArgChecker. Validates the argument types and then calls the original function. Decorator for verifying the return type of functions. Returned value when using clr.returns/ReturnChecker. Calls the original function and validates the return type is of a specified type. returns the result of dir(o) as-if "import clr" has not been performed. Returns the result of dir(o) as-if "import clr" has been performed. Attempts to convert the provided object to the specified type. Conversions that will be attempted include standard Python conversions as well as .NET implicit and explicit conversions. If the conversion cannot be performed a TypeError will be raised. Provides a helper for compiling a group of modules into a single assembly. The assembly can later be reloaded using the clr.AddReference API. clr.CompileSubclassTypes(assemblyName, *typeDescription) Provides a helper for creating an assembly which contains pre-generated .NET base types for new-style types. This assembly can then be AddReferenced or put sys.prefix\DLLs and the cached types will be used instead of generating the types at runtime. This function takes the name of the assembly to save to and then an arbitrary number of parameters describing the types to be created. Each of those parameter can either be a plain type or a sequence of base types. clr.CompileSubclassTypes(object) -> create a base type for object clr.CompileSubclassTypes(object, str, System.Collections.ArrayList) -> create base types for both object and ArrayList. clr.CompileSubclassTypes(object, (object, IComparable)) -> create base types for object and an object which implements IComparable. clr.GetSubclassedTypes() -> tuple Returns a tuple of information about the types which have been subclassed. This tuple can be passed to clr.CompileSubclassTypes to cache these types on disk such as: clr.CompileSubclassTypes('assembly', *clr.GetSubclassedTypes()) Provides a StreamContentProvider for a stream of content backed by a file on disk. Goes through the list of files identifying the relationship between packages and subpackages. Returns a dictionary with all of the package filenames (minus __init__.py) mapping to their full name. For example given a structure: C:\ someDir\ package\ __init__.py a.py b\ __init.py c.py Returns: {r'C:\somedir\package' : 'package', r'C:\somedir\package\b', 'package.b'} This can then be used for calculating the full module name of individual files and packages. For example a's full name is "package.a" and c's full name is "package.b.c". Returns a list of profile data. The values are tuples of Profiler.Data objects All times are expressed in the same unit of measure as DateTime.Ticks Resets all profiler counters back to zero Enable or disable profiling for the current ScriptEngine. This will only affect code that is compiled after the setting is changed; previously-compiled code will retain whatever setting was active when the code was originally compiled. The easiest way to recompile a module is to reload() it. Serializes data using the .NET serialization formatter for complex types. Returns a tuple identifying the serialization format and the serialized data which can be fed back into clr.Deserialize. Current serialization formats include custom formats for primitive .NET types which aren't already recognized as tuples. None is used to indicate that the Binary .NET formatter is used. Deserializes the result of a Serialize call. This can be used to perform serialization for .NET types which are serializable. This method is the callable object provided from __reduce_ex__ for .serializable .NET types. The first parameter indicates the serialization format and is the first tuple element returned from the Serialize call. The second parameter is the serialized data. Captures and flows the state of executing code from the generated Python code into the IronPython runtime. Creates a new CodeContext which is backed by the specified Python dictionary. Gets the module state for top-level code. Gets the DLR scope object that corresponds to the global variables of this context. Gets the PythonContext which created the CodeContext. Gets the dictionary for the global variables from the ModuleContext. True if this global context should display CLR members on shared types (for example .ToString on int/bool/etc...) False if these attributes should be hidden. Attempts to lookup the provided name in this scope or any outer scope. Looks up a global variable. If the variable is not defined in the global scope then built-ins is consulted. Gets the dictionary used for storage of local variables. Attempts to lookup the variable in the local scope. Removes a variable from the local scope. Sets a variable in the local scope. Gets a variable from the global scope. Sets a variable in the global scope. Removes a variable from the global scope. Returns the dictionary associated with __builtins__ if one is set or null if it's not available. If __builtins__ is a module the module's dictionary is returned. General purpose storage used for most PythonDictionarys. This dictionary storage is thread safe for multiple readers or writers. Mutations to the dictionary involves a simple locking strategy of locking on the DictionaryStorage object to ensure that only one mutation happens at a time. Reads against the dictionary happen lock free. When the dictionary is mutated it is either adding or removing buckets in a thread-safe manner so that the readers will either see a consistent picture as if the read occured before or after the mutation. When resizing the dictionary the buckets are replaced atomically so that the reader sees the new buckets or the old buckets. When reading the reader first reads the buckets and then calls a static helper function to do the read from the bucket array to ensure that readers are not seeing multiple bucket arrays. Creates a new dictionary storage with no buckets Creates a new dictionary storage with no buckets Creates a new dictionary geting values/keys from the items arary Creates a new dictionary storage with the given set of buckets and size. Used when cloning the dictionary storage. Adds a new item to the dictionary, replacing an existing one if it already exists. Initializes the buckets to their initial capacity, the caller must check if the buckets are empty first. Add helper that works over a single set of buckets. Used for both the normal add case as well as the resize case. Add helper which adds the given key/value (where the key is not null) with a pre-computed hash code. Removes an entry from the dictionary and returns true if the entry was removed or false. Removes an entry from the dictionary and returns true if the entry was removed or false. The key will always be hashed so if it is unhashable an exception will be thrown - even if the dictionary has no buckets. Checks to see if the key exists in the dictionary. Trys to get the value associated with the given key and returns true if it's found or false if it's not present. Static helper to try and get the value from the dictionary. Used so the value lookup can run against a buckets while a writer replaces the buckets. Returns the number of key/value pairs currently in the dictionary. Clears the contents of the dictionary. Clones the storage returning a new DictionaryStorage object. Helper to hash the given key w/ support for null. Used to store a single hashed key/value. Bucket is not serializable because it stores the computed hash code which could change between serialization and deserialization. Special marker NullValue used during deserialization to not add an extra field to the dictionary storage type. Copy on write constant dictionary storage used for dictionaries created with constant items. General conversion routine TryConvert - tries to convert the object to the desired type. Try to avoid using this method, the goal is to ultimately remove it! This function tries to convert an object to IEnumerator, or wraps it into an adapter Do not use this function directly. It is only meant to be used by Ops.GetEnumerator. This function tries to convert an object to IEnumerator, or wraps it into an adapter Do not use this function directly. It is only meant to be used by Ops.GetEnumerator. Attempts to convert value into a index usable for slicing and return the integer value. If the conversion fails false is returned. If throwOverflowError is true then BigInteger's outside the normal range of integers will result in an OverflowError. Attempts to convert value into a index usable for slicing and return the integer value. If the conversion fails false is returned. If throwOverflowError is true then BigInteger's outside the normal range of integers will result in an OverflowError. Converts a value to int ignoring floats Gets all of the extra names and values stored in the dictionary. Attemps to sets a value in the extra keys. Returns true if the value is set, false if the value is not an extra key. Attempts to get a value from the extra keys. Returns true if the value is an extra key and has a value. False if it is not an extra key or doesn't have a value. Attempts to remove the key. Returns true if the key is removed, false if the key was not removed, or null if the key is not an extra key. Adapts an IDictionary[object, object] for use as a PythonDictionary used for our debug frames. Also hides the special locals which start with $. Provides both helpers for implementing Python dictionaries as well as providing public methods that should be exposed on all dictionary types. Currently these are published on IDictionary<object, object> Abstract base class for all PythonDictionary storage. Defined as a class instead of an interface for performance reasons. Also not using IDictionary* for keeping a simple interface. Full locking is defined as being on the DictionaryStorage object it's self, not an internal member. This enables subclasses to provide their own locking aruond large operations and call lock free functions. Adds items from this dictionary into the other dictionary Provides fast access to the __path__ attribute if the dictionary storage supports caching it. Provides fast access to the __package__ attribute if the dictionary storage supports caching it. Provides fast access to the __builtins__ attribute if the dictionary storage supports caching it. Provides fast access to the __name__ attribute if the dictionary storage supports caching it. Provides fast access to the __import__ attribute if the dictionary storage supports caching it. Marks a type so that IronPython will not expose types which have GetMemberNames as having a __dir__ method. Also suppresses __dir__ on something which implements IDynamicMetaObjectProvider but is not an IPythonObject. Marks a type so that IronPython will not expose the ICollection interface out as __len__. Marks a type so that IronPython will not expose the IDisposable interface out as __enter__ and __exit__ methods of a context manager. Marks a type so that IronPython will not expose the IEnumerable interface out as __contains__ Marks a type so that IronPython will not expose the IEnumerable interface out as __iter__ Singleton used for dictionaries which contain no items. GeneratorExitException is a standard exception raised by Generator.Close() to allow a caller to close out a generator. GeneratorExit is introduced in Pep342 for Python2.5. .NET exception thrown when a Python syntax error is related to incorrect indentation. Implementation of the Python exceptions module and the IronPython/CLR exception mapping mechanism. The exception module is the parent module for all Python exception classes and therefore is built-in to IronPython.dll instead of IronPython.Modules.dll. The exception mapping mechanism is exposed as internal surface area available to only IronPython / IronPython.Modules.dll. The actual exceptions themselves are all public. Because the oddity of the built-in exception types all sharing the same physical layout (see also PythonExceptions.BaseException) some classes are defined as classes w/ their proper name and some classes are defined as PythonType fields. When a class is defined for convenience their's also an _TypeName version which is the PythonType. Base class for all Python exception objects. When users throw exceptions they typically throw an exception which is a subtype of this. A mapping is maintained between Python exceptions and .NET exceptions and a corresponding .NET exception is thrown which is associated with the Python exception. This class represents the base class for the Python exception hierarchy. Users can catch exceptions rooted in either hierarchy. The hierarchy determines whether the user catches the .NET exception object or the Python exception object. Most built-in Python exception classes are actually instances of the BaseException class here. This is important because in CPython the exceptions do not add new members and therefore their layouts are compatible for multiple inheritance. The exceptions to this rule are the classes which define their own fields within their type, therefore altering their layout: EnvironmentError SyntaxError IndentationError (same layout as SyntaxError) TabError (same layout as SyntaxError) SystemExit UnicodeDecodeError UnicodeEncodeError UnicodeTranslateError These exceptions cannot be combined in multiple inheritance, e.g.: class foo(EnvironmentError, IndentationError): pass fails but they can be combined with anything which is just a BaseException: class foo(UnicodeDecodeError, SystemError): pass Therefore the majority of the classes are just BaseException instances with a custom PythonType object. The specialized ones have their own .NET class which inherits from BaseException. User defined exceptions likewise inherit from this and have their own .NET class. Initializes the Exception object with an unlimited number of arguments Returns the exception 'message' if only a single argument was provided during creation or an empty string. Gets or sets the arguments used for creating the exception Returns a tuple of (type, (arg0, ..., argN)) for implementing pickling/copying Returns a tuple of (type, (arg0, ..., argN)) for implementing pickling/copying Gets the nth member of the args property Gets or sets the dictionary which is used for storing members not declared to have space reserved within the exception object. Updates the exception's state (dictionary) with the new values Gets the CLR exception associated w/ this Python exception. Not visible until a .NET namespace is imported. Provides custom member lookup access that fallbacks to the dictionary Provides custom member assignment which stores values in the dictionary Provides custom member deletion which deletes values from the dictionary or allows clearing 'message'. Implements __repr__ which returns the type name + the args tuple code formatted. Initializes the Python exception from a .NET exception Helper to get the CLR exception associated w/ this Python exception creating it if one has not already been created. Creates a new throwable exception of type type where the type is an new-style exception. Used at runtime when creating the exception from a user provided type via the raise statement. Creates a throwable exception of type type where the type is an OldClass. Used at runtime when creating the exception form a user provided type that's an old class (via the raise statement). Returns the CLR exception associated with a Python exception creating a new exception if necessary Given a CLR exception returns the Python exception which most closely maps to the CLR exception. Creates a new style Python exception from the .NET exception Internal helper to associate a .NET exception and a Python exception. Internal helper to get the associated Python exception from a .NET exception. Converts the DLR SyntaxErrorException into a Python new-style SyntaxError instance. Creates a PythonType for a built-in module. These types are mutable like normal user types. Creates a PythonType for a built-in module. These types are mutable like normal user types. Creates a PythonType for a built-in module, where the type may inherit from multiple bases. These types are mutable like normal user types. Creates a new type for a built-in exception which derives from another Python type. . These types are built-in and immutable like any other normal type. For example StandardError.x = 3 is illegal. This isn't for module exceptions which are like user defined types. thread.error.x = 3 is legal. Creates a new type for a built-in exception which is the root concrete type. Gets the list of DynamicStackFrames for the current exception. .NET exception that is thrown to signal the end of iteration in Python .NET exception that is thrown to shutdown the interpretter and exit the system. Result of sys.exit(n) null if the script exited using "sys.exit(int_value)" null if the script exited using "sys.exit(None)" x if the script exited using "sys.exit(x)" where isinstance(x, int) == False int_value if the script exited using "sys.exit(int_value)" 1 otherwise .NET Exception thrown when a Python syntax error is related to incorrect tabs. returns string containing human readable representation of traceback Represents the set of extension methods which are loaded into a module. This set is immutable (as far the external viewer is considered). When a new extension method set is loaded into a module we create a new ExtensionMethodsSet object. Multiple modules which have the same set of extension methods use the same set. Tracks the extension types that are loaded for a given assembly. We can have either types, namespaces, or a full assembly added as a reference. When the user just adds types we just add them to the type hash set. When the user adds namespaces we add them to the namespaces hashset. On the next lookup we'll lazily load the types from that namespace and put them in Types. When the user adds assemblies we set the value to the NotYetLoadedButFullAssembly value. The next load request will load the types from that namespace and put them in Types. When we do that we'll mark the assembly as FullyLoaded so we don't have to go through that again if the user adds a namespace. Returns all of the extension methods with the given name. Returns all of the extension methods which are applicable for the given type. Helper NumberFormatInfo for use by int/BigInteger __format__ routines for width specified leading zero support that contains ','s every 3 digits. i.e. For use by d/g/G format specifiers. NOT for use by n format specifiers. Set if the function includes a *args argument list. Set if the function includes a **kwargs argument dictionary. Set if the function is a generator. Set if the function was compiled with future division. IronPython specific: Set if the function includes nested exception handling and therefore can alter sys.exc_info(). IronPython specific: Set if the function includes a try/finally block. Represents a piece of code. This can reference either a CompiledCode object or a Function. The user can explicitly call FunctionCode by passing it into exec or eval. This is both the lock that is held while enumerating the threads or updating the thread accounting information. It's also a marker CodeList which is put in place when we are enumerating the thread list and all additions need to block. This lock is also acquired whenever we need to calculate how a function's delegate should be created so that we don't race against sys.settrace/sys.setprofile. Constructor used to create a FunctionCode for code that's been serialized to disk. Code constructed this way cannot be interpreted or debugged using sys.settrace/sys.setprofile. Function codes created this way do support recursion enforcement and are therefore registered in the global function code registry. Constructor to create a FunctionCode at runtime. Code constructed this way supports both being interpreted and debugged. When necessary the code will be re-compiled or re-interpreted for that specific purpose. Function codes created this way do support recursion enforcement and are therefore registered in the global function code registry. the initial delegate provided here should NOT be the actual code. It should always be a delegate which updates our Target lazily. Registers the current function code in our global weak list of all function codes. The weak list can be enumerated with GetAllCode(). Ultimately there are 3 types of threads we care about races with: 1. Other threads which are registering function codes 2. Threads calling sys.settrace which require the world to stop and get updated 3. Threads running cleanup (thread pool thread, or call to gc.collect). The 1st two must have perfect synchronization. We cannot have a thread registering a new function which another thread is trying to update all of the functions in the world. Doing so would mean we could miss adding tracing to a thread. But the cleanup thread can run in parallel to either registrying or sys.settrace. The only thing it needs to take a lock for is updating our accounting information about the number of code objects are alive. Enumerates all function codes for updating the current type of targets we generate. While enumerating we hold a lock so that users cannot change sys.settrace/sys.setprofile until the lock is released. Returns a list of variable names which are accessed from nested functions. Returns the byte code. IronPython does not implement this and always returns an empty string for byte code. Returns a list of constants used by the function. The first constant is the doc string, or None if no doc string is provided. IronPython currently does not include any other constants than the doc string. Returns the filename that the code object was defined in. Returns the 1st line number of the code object. Returns a set of flags for the function. 0x04 is set if the function used *args 0x08 is set if the function used **args 0x20 is set if the function is a generator Returns a list of free variables (variables accessed from an outer scope). This does not include variables accessed in the global scope. Returns a mapping between byte code and line numbers. IronPython does not implement this because byte code is not available. Returns the name of the code (function name, class name, or <module>). Returns a list of global variable names accessed by the code. Returns the number of local varaibles defined in the function. Returns the stack size. IronPython does not implement this because byte code is not supported. Creates a FunctionCode object for exec/eval/execfile'd/compile'd code. The code is then executed in a specific CodeContext by calling the .Call method. If the code is being used for compile (vs. exec/eval/execfile) then it needs to be registered in case our tracing mode changes. Called the 1st time a function is invoked by our OriginalCallTarget* methods over in PythonCallTargets. This computes the real delegate which needs to be created for the function. Usually this means starting off interpretering. It also involves adding the wrapper function for recursion enforcement. Because this can race against sys.settrace/setprofile we need to take our _ThreadIsEnumeratingAndAccountingLock to ensure no one is actively changing all of the live functions. Updates the delegate based upon current Python context settings for recursion enforcement and for tracing. Called to set the initial target delegate when the user has passed -X:Debug to enable .NET style debugging. Gets the LambdaExpression for tracing. If this is a generator function code then the lambda gets tranformed into the correct generator code. Gets the correct final LambdaExpression for this piece of code. This is either just _lambda or _lambda re-written to be a generator expression. Extremely light weight linked list of weak references used for tracking all of the FunctionCode objects which get created and need to be updated for purposes of recursion enforcement or tracing. True iff the thread is currently inside the generator (ie, invoking the _next delegate). This can be used to enforce that a generator does not call back into itself. Pep255 says that a generator should throw a ValueError if called reentrantly. We cache the GeneratorFinalizer of generators that were closed on the user thread, and did not get finalized on the finalizer thread. We can then reuse the object. Reusing objects with a finalizer is good because it reduces the load on the GC's finalizer queue. Fields set by Throw() to communicate an exception to the yield point. These are plumbed through the generator to become parameters to Raise(...) invoked at the yield suspension point in the generator. Value sent by generator.send(). Since send() could send an exception, we need to keep this different from throwable's value. See PEP 342 (http://python.org/dev/peps/pep-0342/) for details of new methods on Generator. Full signature including default params for throw is: throw(type, value=None, traceback=None) Use multiple overloads to resolve the default parameters. Throw(...) is like Raise(...) being called from the yield point within the generator. Note it must come from inside the generator so that the traceback matches, and so that it can properly cooperate with any try/catch/finallys inside the generator body. If the generator catches the exception and yields another value, that is the return value of g.throw(). send() was added in Pep342. It sends a result back into the generator, and the expression becomes the result of yield when used as an expression. Close introduced in Pep 342. Gets the name of the function that produced this generator object. Core implementation of IEnumerator.MoveNext() Core implementation of Python's next() method. Helper called from PythonOps after the yield statement Keepin this in a helper method: - reduces generated code size - allows better coupling with PythonGenerator.Throw() - avoids throws from emitted code (which can be harder to debug). Called to throw an exception set by Throw(). True if the generator has finished (is "closed"), else false. Python language spec mandates that calling Next on a closed generator gracefully throws a StopIterationException. This can never be reset. True if the generator can set sys exc info and therefore needs exception save/restore. Importer class - used for importing modules. Used by Ops and __builtin__ Singleton living on Python engine. Gateway into importing ... called from Ops. Performs the initial import of a module and returns the module. Gateway into importing ... called from Ops. Performs the initial import of a module and returns the module. This version returns light exceptions instead of throwing. Gateway into importing ... called from Ops. This is called after importing the module and is used to return individual items from the module. The outer modules dictionary is then updated with the result. Called by the __builtin__.__import__ functions (general importing) and ScriptEngine (for site.py) level indiciates whether to perform absolute or relative imports. -1 indicates both should be performed 0 indicates only absolute imports should be performed Positive numbers indicate the # of parent directories to search relative to the calling module Interrogates the importing module for __name__ and __path__, which determine whether the imported module (whose name is 'name') is being imported as nested module (__path__ is present) or as sibling. For sibling import, the full name of the imported module is parent.sibling For nested import, the full name of the imported module is parent.module.nested where parent.module is the mod.__name__ the globals dictionary Name of the module to be imported Output - full name of the module being imported Path to use to search for "full" the import level for relaive imports the parent module the global __package__ value Given the parent module name looks up the __path__ property. Trys to get an existing module and if that fails fall backs to searching Attempts to load a module from sys.meta_path as defined in PEP 302. The meta_path provides a list of importer objects which can be used to load modules before searching sys.path but after searching built-in modules. Given a user defined importer object as defined in PEP 302 tries to load a module. First the find_module(fullName, path) is invoked to get a loader, then load_module(fullName) is invoked Finds a user defined importer for the given path or returns null if no importer handles this path. Wrapper class used when a user defined type (new-style or old-style) defines __index__. We provide a conversion from all user defined types to the Index type so they can be used for determing and method bind time the most appropriate method to dispatch to. ModuleDictionaryStorage for a built-in module which is bound to a specific instance. These modules don't need to use PythonContext.GetModuleState() for storage and therefore can provide efficient access to internal variables. They can also cache PythonGlobal objects and provide efficient access to module globals. To the end user these modules appear just like any other module. These modules are implemented by subclassing the BuiltinPythonModule class. Defines the internal interface used for accessing weak references and adding finalizers to user-defined types. Gets the current WeakRefTracker for an object that can be used to append additional weak references. Attempts to set the WeakRefTracker for an object. Used on the first addition of a weak ref tracker to an object. If the object doesn't support adding weak references then it returns false. Sets a WeakRefTracker on an object for the purposes of supporting finalization. All user types (new-style and old-style) support finalization even if they don't support weak-references, and therefore this function always succeeds. Note the slot used to store the WeakRefTracker is still shared between SetWeakRef and SetFinalizer if a type supports both. Allow types to implement weakvreference tracking by returning a proxy. The proxy can refer to the current Python context, whihc is the main purpose. Provides a list of all the members of an instance. ie. all the keys in the dictionary of the object. Note that it can contain objects that are not strings. Such keys can be added in IronPython using syntax like: obj.__dict__[100] = someOtherObject This Python specific version also supports filtering based upon the show cls flag by flowing in the code context. Represents a sequence which may have been provided as a set of parameters to an indexer. TODO: This should be removed, and all uses of this should go to [SpecialName]object GetItem(..., params object[] keys) and [SpecialName]void SetItem(..., params object [] keys) or this[params object[]xyz] which is also legal. currently this exists for backwards compatibility w/ IronPython's "expandable tuples". Creates a new list with the data in the array and a size the same as the length of the array. The array is held onto and may be mutated in the future by the list. params array to use for lists storage Gets a reasonable size for the addition of two arrays. We round to a power of two so that we usually have some extra space if the resulting array gets added to. Non-thread safe adder, should only be used by internal callers that haven't yet exposed their list. Compares the two specified keys Supports __index__ on arbitrary types, also prevents __float__ we need to lock both objects (or copy all of one's data w/ it's lock held, and then compare, which is bad). Therefore we have a strong order for locking on the two objects based upon the hash code or object identity in case of a collision Summary description for ConstantValue. MemoryView slicing is somewhat different and more restricted than standard slicing. Validates that the current self object is usable for this method. Captures the globals and other state of module code. Creates a new ModuleContext which is backed by the specified dictionary. Creates a new ModuleContext for the specified module. Gets the dictionary used for the global variables in the module Gets the language context which created this module. Gets the DLR Scope object which is associated with the modules dictionary. Gets the global CodeContext object which is used for execution of top-level code. Gets the module object which this code is executing in. This module may or may not be published in sys.modules. For user defined code typically the module gets published at the start of execution. But if this ModuleContext is attached to a Scope, or if we've just created a new module context for executing code it will not be in sys.modules. Gets the features that code has been compiled with in the module. Gets or sets whether code running in this context should display CLR members (for example .ToString on objects). Initializes __builtins__ for the module scope. Enables lazy initialization of module dictionaries. Cached global value. Created and maintained on a per-language basis. Default implementation returns a singleton which indicates caching is not occuring. Creates a new ModuleGlobalCache with the specified value. True if the ModuleGlobalCache is participating in a caching strategy. True if there is currently a value associated with this global variable. False if it is currently unassigned. Gets or sets the current cached value Event handler for when the value has changed. Language implementors should call this when the cached value is invalidated. Enable true division (1/2 == .5) Indicates that .NET methods such as .ToString should be available on Python objects. Indicates that the module should be generated in an optimal form which will result in it being uncollectable. Indicates when the module should be executed immedatiately upon creation. Enable usage of the with statement Enable absolute imports Indiciates that __builtins__ should not be set in the module Indiciates that when the module is initialized it should set __builtins__ to the __builtin__ module instead of the __builtin__ dictionary. Marks code as being created for exec, eval. Code generated this way will be capable of running against different scopes and will do lookups at runtime for free global variables. Indiciates that the first line of code should be skipped. Enable usage of print as a function for better compatibility with Python 3.0. Forces the code to be interpreted rather than compiled String Literals should be parsed as Unicode strings Include comments in the parse tree Generated code should support light exceptions New string formatter for 'str'.format(...) calls and support for the Formatter library via the _formatter_parser / _formatter_field_name_split methods. We parse this format: replacement_field = "{" field_name ["!" conversion] [":" format_spec] "}" field_name = (identifier | integer) ("." attribute_name | "[" element_index "]")* attribute_name = identifier element_index = identifier conversion = "r" | "s" format_spec = any char, { must be balanced (for computed values), passed to __format__ method on object Runs the formatting operation on the given format and keyword arguments Gets the formatting information for the given format. This is a list of tuples. The tuples include: text, field name, format spec, conversion Parses a field name returning the argument name and an iterable object which can be used to access the individual attribute or element accesses. The iterator yields tuples of: bool (true if attribute, false if element index), attribute/index value Base class used for parsing the format. Subclasss override Text/ReplacementField methods. Those methods get called when they call Parse and then they can do the appropriate actions for the format. Gets an enumerable object for walking the parsed format. TODO: object array? struct? Provides an enumerable of the parsed format. The elements of the tuple are: the text preceding the format information the field name the format spec the conversion Handles {{ and }} within the string. Returns true if a double bracket is found and yields the text Parses the conversion character and returns it Checks to see if we're at the end of the format. If there's no more characters left we report the error, otherwise if we hit a } we return true to indicate parsing should stop. Parses the format spec string and returns it. Parses the field name and returns it. Handles parsing the field name and the format spec and returns it. At the parse level these are basically the same - field names just have more terminating characters. The most complex part of parsing them is they both allow nested braces and require the braces are matched. Strangely though the braces need to be matched across the combined field and format spec - not within each format. Provides the built-in string formatter which is exposed to Python via the str.format API. Inspects a format spec to see if it contains nested format specs which we need to compute. If so runs another string formatter on the format spec to compute those values. Given the field name gets the object from our arguments running any of the member/index accessors. Applies the known built-in conversions to the object if a conversion is specified. Gets the initial object represented by the field name - e.g. the 0 or keyword name. Given the object value runs the accessors in the field name (if any) against the object. Parses the field name including attribute access or element indexing. Parses the field name including attribute access or element indexing. Converts accessors from our internal structure into a PythonTuple matching how CPython exposes these Parses an identifier and returns it Encodes all the information about the field name. Encodes a single field accessor (.b or [number] or [str]) Multiply two object[] arrays - slow version, we need to get the type, etc... Multiply two object[] arrays - internal version used for objects backed by arrays Add two arrays - internal versions for objects backed by arrays We override the behavior of equals, compare and hashcode to make chars seem as much like strings as possible. In Python there is no difference between these types. Helper class that all custom type descriptor implementations call for the bulk of their implementation. Returns the digits for the format spec, no sign is included. Interface used for things which can convert to delegates w/o code gen. Currently this is just non-overloaded builtin functions and bound builtin functions. Avoiding the code gen is not only nice for compilation but it also enables delegates to be added in C# and removed in Python. Returns the digits for the format spec, no sign is included. InstanceOps contains methods that get added to CLS types depending on what methods and constructors they define. These have not been added directly to PythonType since they need to be added conditionally. Possibilities include: __new__, one of 3 __new__ sets can be added: DefaultNew - This is the __new__ used for a PythonType (list, dict, object, etc...) that has only 1 default public constructor that takes no parameters. These types are mutable types, and __new__ returns a new instance of the type, and __init__ can be used to re-initialize the types. This __new__ allows an unlimited number of arguments to be passed if a non-default __init__ is also defined. NonDefaultNew - This is used when a type has more than one constructor, or only has one that takes more than zero parameters. This __new__ does not allow an arbitrary # of extra arguments. DefaultNewCls - This is the default new used for CLS types that have only a single ctor w/ an arbitray number of arguments. This constructor allows setting of properties based upon an extra set of kw-args, e.g.: System.Windows.Forms.Button(Text='abc'). It is only used on non-Python types. __init__: For types that do not define __init__ we have an __init__ function that takes an unlimited number of arguments and does nothing. All types share the same reference to 1 instance of this. next: Defined when a type is an enumerator to expose the Python iter protocol. repr: Added for types that override ToString get: added for types that implement IDescriptor __dir__(self) -> Returns the list of members defined on a foreign IDynamicMetaObjectProvider. Provides the implementation of __enter__ for objects which implement IDisposable. Provides the implementation of __exit__ for objects which implement IDisposable. Determines if a type member can be imported. This is used to treat static types like modules. Implements __contains__ for types implementing IEnumerable of T. Implements __contains__ for types implementing IEnumerable Implements __contains__ for types implementing IEnumerable of T. Implements __contains__ for types implementing IEnumerable Implements __reduce_ex__ for .NET types which are serializable. This uses the .NET serializer to get a string of raw data which can be serialized. Contains Python extension methods that are added to object Types for which the pickle module has built-in support (from PEP 307 case 2) __class__, a custom slot so that it works for both objects and types. Removes an attribute from the provided member Returns the hash code of the given object Gets the specified attribute from the object without running any custom lookup behavior (__getattr__ and __getattribute__) Initializes the object. The base class does nothing. Initializes the object. The base class does nothing. Initializes the object. The base class does nothing. Creates a new instance of the type Creates a new instance of the type Creates a new instance of the type Runs the pickle protocol Runs the pickle protocol Runs the pickle protocol Returns the code representation of the object. The default implementation returns a string which consists of the type and a unique numerical identifier. Sets an attribute on the object without running any custom object defined behavior. Returns the number of bytes of memory required to allocate the object. Returns a friendly string representation of the object. Return a dict that maps slot names to slot values, but only include slots that have been assigned to. Looks up slots in base types as well as the current type. Sort-of Python equivalent (doesn't look up base slots, while the real code does): return dict([(slot, getattr(self, slot)) for slot in type(self).__slots__ if hasattr(self, slot)]) Return null if the object has no __slots__, or empty dict if it has __slots__ but none are initialized. Implements the default __reduce_ex__ method as specified by PEP 307 case 2 (new-style instance, protocol 0 or 1) Returns the closest base class (in terms of MRO) that isn't defined in Python code Implements the default __reduce_ex__ method as specified by PEP 307 case 3 (new-style instance, protocol 2) Contains functions that are called directly from generated code to perform low-level runtime functionality. Creates a new dictionary extracting the keys and values from the provided data array. Keys/values are adjacent in the array with the value coming first. Creates a new dictionary extracting the keys and values from the provided data array. Keys/values are adjacent in the array with the value coming first. Wraps up all the semantics of multiplying sequences so that all of our sequences don't duplicate the same logic. When multiplying sequences we need to deal with only multiplying by valid sequence types (ints, not floats), support coercion to integers if the type supports it, not multiplying by None, and getting the right semantics for multiplying by negative numbers and 1 (w/ and w/o subclasses). This function assumes that it is only called for case where count is not implicitly coercible to int so that check is skipped. Supports calling of functions that require an explicit 'this' Currently, we check if the function object implements the interface that supports calling with 'this'. If not, the 'this' object is dropped and a normal call is made. Called from generated code emitted by NewTypeMaker. Handles the descriptor protocol for user-defined objects that may implement __get__ Handles the descriptor protocol for user-defined objects that may implement __set__ Handles the descriptor protocol for user-defined objects that may implement __delete__ Python runtime helper for raising assertions. Used by AssertStatement. Python runtime helper for raising assertions. Used by AssertStatement. Object representing the assertion message Python runtime helper to create instance of Python List object. New instance of List Python runtime helper to create a populated instance of Python List object. Python runtime helper to create a populated instance of Python List object w/o copying the array contents. Python runtime helper to create a populated instance of Python List object. List is populated by arbitrary user defined object. Python runtime helper to create an instance of Python List object. List has the initial provided capacity. Python runtime helper to create an instance of Tuple Python runtime helper to create an instance of Tuple Python Runtime Helper for enumerator unpacking (tuple assignments, ...) Creates enumerator from the input parameter e, and then extracts expected number of values, returning them as array If the input is a Python tuple returns the tuples underlying data array. Callers should not mutate the resulting tuple. The code context of the AST getting enumerator values. object to enumerate expected number of objects to extract from the enumerator array of objects (.Lengh == expected) if exactly expected objects are in the enumerator. Otherwise throws exception Python runtime helper to create instance of Slice object Start of the slice. End of the slice. Step of the slice. Slice Prints newline into default standard output Prints newline into specified destination. Sets softspace property to false. Prints value into default standard output with Python comma semantics. Prints value into specified destination with Python comma semantics. Called from generated code when we are supposed to print an expression value Called from generated code for: import spam.eggs Python helper method called from generated code for: import spam.eggs as ham Called from generated code for: from spam import eggs1, eggs2 Imports one element from the module in the context of: from module import a, b, c, d Called repeatedly for all elements being imported (a, b, c, d above) Called from generated code for: from spam import * Unqualified exec statement support. A Python helper which will be called for the statement: exec code Qualified exec statement support, Python helper which will be called for the statement: exec code in globals [, locals ] Called from generated code at the start of a catch block. Get an exception tuple for the "current" exception. This is used for sys.exc_info() Get an exception tuple for a given exception. This is like the inverse of MakeException. the code context the exception to create a tuple for. a tuple of (type, value, traceback) This is called directly by the With statement so that it can get an exception tuple in its own private except handler without disturbing the thread-wide sys.exc_info(). helper function for re-raised exceptions. helper function for re-raised exception. This entry point is used by 'raise' inside 'with' statement helper function for non-re-raise exceptions. type is the type of exception to throw or an instance. If it is an instance then value should be null. If type is a type then value can either be an instance of type, a Tuple, or a single value. This case is handled by EC.CreateThrowable. Extracts an argument from either the dictionary or params Creates a new array the values set to Uninitialized.Instance. The array is large enough to hold for all of the slots allocated for the type and its sub types. Helper to determine if the value is a simple numeric type (int or big int or bool) - used for OldInstance deprecated form of slicing. Helper to determine if the type is a simple numeric type (int or big int or bool) - used for OldInstance deprecated form of slicing. Helper to determine if the type is a simple numeric type (int or big int or bool) but not a subclass For slicing. Fixes up a BigInteger and returns an integer w/ the length of the object added if the value is negative. For slicing. Gets the length of the object, used to only get the length once. Helper method for DynamicSite rules that check the version of their dynamic object TODO - Remove this method for more direct field accesses Called from generated code. Gets a builtin function and the BuiltinFunctionData associated with the object. Tests to see if the function is bound and has the same data for the generated rule. Convert object to a given type. This code is equivalent to NewTypeMaker.EmitConvertFromObject except that it happens at runtime instead of compile time. Provides access to AppDomain.DefineDynamicAssembly which cannot be called from a DynamicMethod Generates a new delegate type. The last type in the array is the return type. Generates a new delegate type. The last type in the array is the return type. Provides the entry point for a compiled module. The stub exe calls into InitializeModule which does the actual work of adding references and importing the main module. Upon completion it returns the exit code that the program reported via SystemExit or 0. Provides the entry point for a compiled module. The stub exe calls into InitializeModule which does the actual work of adding references and importing the main module. Upon completion it returns the exit code that the program reported via SystemExit or 0. Called from generated code, helper to remove a name Called from generated code, helper to do name lookup Called from generated code, helper to do name assignment Returns an IntPtr in the proper way to CPython - an int or a Python long Create at TypeError exception for when Raise() can't create the exception requested. original type of exception requested a TypeEror exception Gets a list of DynamicStackFrames for the given exception. These stack frames can be programmatically inspected to understand the frames the exception crossed through including Python frames. Dynamic stack frames are not preserved when an exception crosses an app domain boundary. Helper clas for calls to unicode(...). We generate code which checks if unicode is str and if it is we redirect those calls to the unicode function defined on this class. Looks up __init__ avoiding calls to __getattribute__ and handling both new-style and old-style classes in the MRO. Gets a builtin function for the given declaring type and member infos. Given the same inputs this always returns the same object ensuring there's only 1 builtinfunction for each .NET method. This method takes both a cacheName and a pythonName. The cache name is the real method name. The pythonName is the name of the method as exposed to Python. Checks to see if the provided members are always visible for the given type. This filters out methods such as GetHashCode and Equals on standard .NET types that we expose directly as Python types (e.g. object, string, etc...). It also filters out the base helper overrides that are added for supporting super calls on user defined types. a function is static if it's a static .NET method and it's defined on the type or is an extension method with StaticExtensionMethod decoration. If we have only interfaces, we'll need to insert object's base ExtensibleString is the base class that is used for types the user defines that derive from string. It carries along with it the string's value and our converter recognizes it as a string. StringOps is the static class that contains the methods defined on strings, i.e. 'abc' Here we define all of the methods that a Python user would see when doing dir('abc'). If the user is running in a CLS aware context they will also see all of the methods defined in the CLS System.String type. Returns a copy of this string converted to uppercase return true if self is a titlecased string and there is at least one character in self; also, uppercase characters may only follow uncased characters (e.g. whitespace) and lowercase characters only cased ones. return false otherwise. Return a string which is the concatenation of the strings in the sequence seq. The separator between elements is the string providing this method Replaces each replacement field in the string with the provided arguments. replacement_field = "{" field_name ["!" conversion] [":" format_spec] "}" field_name = (identifier | integer) ("." identifier | "[" element_index "]")* format_spec: [[fill]align][sign][#][0][width][,][.precision][type] Conversion can be 'r' for repr or 's' for string. Replaces each replacement field in the string with the provided arguments. replacement_field = "{" field_name ["!" conversion] [":" format_spec] "}" field_name = (identifier | integer) ("." identifier | "[" element_index "]")* format_spec: [[fill]align][sign][#][0][width][.precision][type] Conversion can be 'r' for repr or 's' for string. Gets the starting offset checking to see if the incoming bytes already include a preamble. When encoding or decoding strings if an error occurs CPython supports several different behaviors, in addition it supports user-extensible behaviors as well. For the default behavior we're ok - both of us support throwing and replacing. For custom behaviors we define a single fallback for decoding and encoding that calls the python function to do the replacement. When we do the replacement we call the provided handler w/ a UnicodeEncodeError or UnicodeDecodeError object which contains: encoding (string, the encoding the user requested) end (the end of the invalid characters) object (the original string being decoded) reason (the error, e.g. 'unexpected byte code', not sure of others) start (the start of the invalid sequence) The decoder returns a tuple of (unicode, int) where unicode is the replacement string and int is an index where encoding should continue. Indexer for generic parameter resolution. We bind to one of the generic versions available in this type collision. A user can also do someType[()] to force to bind to the non-generic version, but we will always present the non-generic version when no bindings are available. Object.ToString() displays the CLI type name. But we want to display the class name (e.g. '<foo object at 0x000000000000002C>' unless we've overridden __repr__ but not __str__ in which case we'll display the result of __repr__. Provides a debug view for user defined types. This class is declared as public because it is referred to from generated code. You should not use this class. Manages the acquisition of profiling data for a single ScriptRuntime Get the unique Profiler instance for this ScriptRuntime Given a MethodBase, return an index into the array of perf data. Treat each CLR method as unique. Given the unique name of something we're profiling, return an index into the array of perf data. Add a new profiler entry. Not all names are unique. Gets the current summary of profile data Resets the current summary of profile data back to zero Adds profiling calls to a Python method. Calculates both the time spent only in this method Wraps a call to a MethodInfo with profiling capture for that MethodInfo Encapsulates profiler data to return to clients Marks that this built-in method should be treated as external by the profiler. When placed on a call emitted into a Python method, all the time spent in this call will still show up in its parent's inclusive time, but will not be part of its exclusive time. Simple implementation of ASCII encoding/decoding. The default instance (PythonAsciiEncoding.Instance) is setup to always convert even values outside of the ASCII range. The EncoderFallback/DecoderFallbacks can be replaced with versions that will throw exceptions instead though. A DynamicMetaObject which is just used to support custom conversions to COM. A marker interface so we can recognize and access sequence members on our array objects. stored for copy_reg module, used for reduce protocol stored for copy_reg module, used for reduce protocol Creates a new PythonContext not bound to Engine. Gets or sets the maximum depth of function calls. Equivalent to sys.getrecursionlimit and sys.setrecursionlimit. Gets or sets the main thread which should be interupted by thread.interrupt_main Checks to see if module state has the current value stored already. Gets per-runtime state used by a module. The module should have a unique key for each piece of state it needs to store. Sets per-runtime state used by a module. The module should have a unique key for each piece of state it needs to store. Sets per-runtime state used by a module and returns the previous value. The module should have a unique key for each piece of state it needs to store. Sets per-runtime state used by a module and returns the previous value. The module should have a unique key for each piece of state it needs to store. Initializes the sys module on startup. Called both to load and reload sys Reads one line keeping track of the # of bytes read We use Assembly.LoadFile to load assemblies from a path specified by the script (in LoadAssemblyFromFileWithPath). However, when the CLR loader tries to resolve any of assembly references, it will not be able to find the dependencies, unless we can hook into the CLR loader. Returns (and creates if necessary) the PythonService that is associated with this PythonContext. The PythonService is used for providing remoted convenience helpers for the DLR hosting APIs. Gets or sets the default encoding for this system state / engine. Dictionary from name to type of all known built-in module names. Dictionary from type to name of all built-in modules. TODO: Remove me, or stop caching built-ins. This is broken if the user changes __builtin__ Gets the member names associated with the object TODO: Move "GetMemberNames" functionality into MetaObject implementations Dictionary of error handlers for string codecs. Table of functions used for looking for additional codecs. Gets a SiteLocalStorage when no call site is available. Invokes the specified operation on the provided arguments and returns the new resulting value. operation is usually a value from StandardOperators (standard CLR/DLR operator) or OperatorStrings (a Python specific operator) Returns a shared code context for the current PythonContext. This shared context can be used for performing general operations which usually require a CodeContext. Returns an overload resolver for the current PythonContext. The overload resolver will flow the shared context through as it's CodeContext. Returns a shared code context for the current PythonContext. This shared context can be used for doing lookups which need to occur as if they happened in a module which has done "import clr". Sets the current command dispatcher for the Python command line. The previous dispatcher is returned. Null can be passed to remove the current command dispatcher. The command dispatcher will be called with a delegate to be executed. The command dispatcher should invoke the target delegate in the desired context. A common use for this is to enable running all REPL commands on the UI thread while the REPL continues to run on a non-UI thread. The ipy.exe REPL will call into PythonContext.DispatchCommand to dispatch each execution to the correct thread. Other REPLs can do the same to support this functionality as well. Dispatches the command to the current command dispatcher. If there is no current command dispatcher the command is executed immediately on the current thread. Gets a function which can be used for comparing two values. If cmp is not null then the comparison will use the provided comparison function. Otherwise it will use the normal Python semantics. If type is null then a generic comparison function is returned. If type is not null a comparison function is returned that's used for just that type. Performs a GC collection including the possibility of freeing weak data structures held onto by the Python runtime. Gets a PythonContext given a DynamicMetaObjectBinder. List of unary operators which we have sites for to enable fast dispatch that doesn't collide with other operators. Note: IEnumerator innerEnum = Dictionary<K,V>.KeysCollections.GetEnumerator(); innerEnum.MoveNext() will throw InvalidOperation even if the values get changed, which is supported in python Note: IEnumerator innerEnum = Dictionary<K,V>.KeysCollections.GetEnumerator(); innerEnum.MoveNext() will throw InvalidOperation even if the values get changed, which is supported in python Note: IEnumerator innerEnum = Dictionary<K,V>.KeysCollections.GetEnumerator(); innerEnum.MoveNext() will throw InvalidOperation even if the values get changed, which is supported in python A DynamicStackFrame which has Python specific data. Currently this includes the code context which may provide access to locals and the function code object which is needed to build frame objects from. Gets the code context of the function. If the function included a call to locals() or the FullFrames option is enabled then the code context includes all local variables. Null if deserialized. Gets the code object for this frame. This is used in creating the trace back. Null if deserialized. Sets the mode to text or binary. Returns true if previously set to text, false if previously set to binary. Truncates the file to the current length as indicated by tell(). Truncates the file to the specified length. Created for a user-defined function. Python ctor - maps to function.__new__ y = func(x.__code__, globals(), 'foo', None, (a, )) The parent CodeContext in which this function was declared. Captures the # of args and whether we have kw / arg lists. This enables us to share sites for simple calls (calls that don't directly provide named arguments or the list/dict params). Calculates the _compat value which is used for call-compatibility checks for simple calls. Whenver any of the dependent values are updated this must be called again. The dependent values include: _nparams - this is readonly, and never requies an update _defaults - the user can mutate this (func_defaults) and that forces an update expand dict/list - based on nparams and flags, both read-only Bits are allocated as: 00003fff - Normal argument count 0fffb000 - Default count 10000000 - unused 20000000 - expand list 40000000 - expand dict 80000000 - unused Enforce recursion is added at runtime. Generators w/ exception handling need to have some data stored on them so that we appropriately set/restore the exception state. Returns an ID for the function if one has been assigned, or zero if the function has not yet required the use of an ID. Gets the position for the expand list argument or -1 if the function doesn't have an expand list parameter. Gets the position for the expand dictionary argument or -1 if the function doesn't have an expand dictionary parameter. Gets the number of normal (not params or kw-params) parameters. Gets the number of extra arguments (params or kw-params) Marks a member as being hidden from Python code. Marks a class as being hidden from the Python hierarchy. This is applied to the base class and then all derived types will not see the base class in their hierarchy and will not be able to access members declaredo on the base class. Python module. Stores classes, functions, and data. Usually a module is created by importing a file or package from disk. But a module can also be directly created by calling the module type and providing a name or optionally a documentation string. Creates a new module backed by a Scope. Used for creating modules for foreign Scope's. Creates a new PythonModule with the specified dictionary. Used for creating modules for builtin modules which don't have any code associated with them. This assembly-level attribute specifies which types in the engine represent built-in Python modules. Members of a built-in module type should all be static as an instance is never created. Creates a new PythonModuleAttribute that can be used to specify a built-in module that exists within an assembly. The built-in module name The type that implements the built-in module. The valid platform identifiers for this module. The built-in module name The type that implements the built-in module Provides human readable names for how Python maps the various DLR NarrowingLevel's. No narrowing conversions are performed Double/Single to Decimal PythonTuple to Array Generic conversions BigInteger to Int64 Numeric conversions excluding from floating point values Boolean conversions Delegate conversions Enumeration conversions Enables Python protocol conversions (__int__, etc...) Provides storage of IronPython specific data in the DLR Scope ScopeExtension. This enables IronPython to track code compilation flags such as from __future__ flags and import clr flags across multiple executions of user-provided scopes. Return a copy of this tuple's data array. public class to get optimized Marks a type as being a PythonType for purposes of member lookup, creating instances, etc... If defined a PythonType will use __new__ / __init__ when creating instances. This allows the object to match the native Python behavior such as returning cached values from __new__ or supporting initialization to run multiple times via __init__. The attribute also allows you to specify an alternate type name. This allows the .NET name to be different from the Python name so they can follow .NET naming conventions. Types defining this attribute also don't show CLR methods such as Equals, GetHashCode, etc... until the user has done an import clr. Provides dictionary based storage which is backed by a Scope object. Provides more specific type information for Python lists which are not strongly typed. This attribute can be applied to fields, parameters, proeprties, and return values. It can be inspected to get type information about the types of the values of the expected list or the returned list. Mutable set class Appends an IEnumerable to an existing set Immutable set class Iterator over sets General-purpose storage used for Python sets and frozensets. The set storage is thread-safe for multiple readers or writers. Mutations to the set involve a simple locking strategy of locking on the SetStorage object itself to ensure mutual exclusion. Reads against the set happen lock-free. When the set is mutated, it adds or removes buckets in an atomic manner so that the readers will see a consistent picture as if the read occurred either before or after the mutation. Creates a new set storage with no buckets Creates a new set storage with no buckets Returns the number of items currently in the set Adds a new item to the set, unless an equivalent item is already present Static helper which adds the given non-null item with a precomputed hash code. Returns true if the item was added, false if it was already present in the set. Lock-free helper on a non-null item with a pre-calculated hash code. Removes the item if it is present in the set, otherwise adds it. Clears the contents of the set Clones the set, returning a new SetStorage object Checks to see if the given item exists in the set Checks to see if the given item exists in the set, and tries to hash it even if it is known not to be in the set. Adds items from this set into the other set Removes the first set element in the iteration order. true if an item was removed, false if the set was empty Removes an item from the set and returns true if it was present, otherwise returns false Removes an item from the set and returns true if it was removed. The item will always be hashed, throwing if it is unhashable - even if the set has no buckets. Lock-free helper to remove a non-null item Determines whether the current set shares no elements with the given set Determines whether the current set is a subset of the given set Determines whether the current set is a strict subset of the given set Mutates this set to contain its union with 'other'. The caller must lock the current set if synchronization is desired. Mutates this set to contain its intersection with 'other'. The caller must lock the current set if synchronization is desired. Mutates this set to contain its symmetric difference with 'other'. The caller must lock the current set if synchronization is desired. Mutates this set to contain its difference with 'other'. The caller must lock the current set if synchronization is desired. Computes the union of self and other, returning an entirely new set. This method is thread-safe and makes no modifications to self or other. Computes the intersection of self and other, returning an entirely new set. This method is thread-safe and makes no modifications to self or other. Computes the symmetric difference of self and other, returning an entirely new set. This method is thread-safe and makes no modifications to self or other. Computes the difference of self and other, returning an entirely new set. This method is thread-safe and makes no modifications to self or other. Used to store a single hashed item. Bucket is not serializable because it stores the computed hash code, which could change between serialization and deserialization. Helper to hash the given item w/ support for null Helper which ensures that the first argument x requires the least work to enumerate A factory which creates a SetStorage object from any Python iterable. It extracts the underlying storage of a set or frozen set without copying, which is left to the caller if necessary. A factory which creates a SetStorage object from any Python iterable. It extracts the underlying storage of a set or frozen set without copying, which is left to the caller if necessary. Returns true if the given object was a set or frozen set, false otherwise. A factory which creates a SetStorage object from any Python iterable. It extracts the underlying storage of a set or frozen set, copying in the former case, to return a SetStorage object that is guaranteed not to receive any outside mutations. Extracts the SetStorage object from o if it is a set or frozenset and returns true. Otherwise returns false. Creates a hashable set from the given set, or does nothing if the given object is not a set. True if o is a set or frozenset, false otherwise Provides storage which is flowed into a callers site. The same storage object is flowed for multiple calls enabling the callee to cache data that can be re-used across multiple calls. Data is a public field so that this works properly with DynamicSite's as the reference type (and EnsureInitialize) Gets the indices for the deprecated __getslice__, __setslice__, __delslice__ functions This form is deprecated in favor of using __getitem__ w/ a slice object as an index. This form also has subtly different mechanisms for fixing the slice index before calling the function. If an index is negative and __len__ is not defined on the object than an AttributeError is raised. Provides a representation and parsing for the default formatting specification. This is used by object.__format__, int.__format__, long.__format__, and float.__format__ to do the common format spec parsing. The default specification is: format_spec = [[fill]align][sign][#][0][width][,][.precision][type] fill = a character other than } align = "<" | ">" | "=" | "^" sign = "+" | "-" | " " width = integer precision = integer type = "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "x" | "X" | "%" Parses a format spec and returns a new StringFormatSpec object. StringFormatter provides Python's % style string formatting services. Read a possible mapping key for %(key)s. The key name enclosed between the '%(key)s', or null if there are no paranthesis such as '%s'. AppendBase appends an integer at the specified radix doing all the special forms for Python. We have a copy and paste version of this for BigInteger below that should be kept in sync. BigInteger version of AppendBase. Should be kept in sync w/ AppendBase Optimized storage for setting exc_type, exc_value, and exc_traceback. This optimization can go away in Python 3.0 when these attributes are no longer used. BuiltinFunction represents any standard CLR function exposed to Python. This is used for both methods on standard Python types such as list or tuple and for methods from arbitrary .NET assemblies. All calls are made through the optimizedTarget which is created lazily. TODO: Back BuiltinFunction's by MethodGroup's. Creates a new builtin function for a static .NET function. This is used for module methods and well-known __new__ methods. Creates a built-in function for a .NET method declared on a type. Creates a bound built-in function. The instance may be null for built-in functions accessed for None. Returns a BuiltinFunction bound to the provided type arguments. Returns null if the binding cannot be performed. Returns a descriptor for the built-in function if one is neededed Gets the target methods that we'll be calling. True if the method should be visible to non-CLS opt-in callers Makes a test for the built-in function against the private _data which is unique per built-in function. Helper for generating the call to a builtin function. This is used for calls from built-in method descriptors and built-in functions w/ and w/o a bound instance. This provides all sorts of common checks on top of the call while the caller provides a delegate to do the actual call. The common checks include: check for generic-only methods reversed operator support transforming arguments so the default binder can understand them (currently user defined mapping types to PythonDictionary) returning NotImplemented from binary operators Warning when calling certain built-in functions The call binder we're doing the call for An expression which points to the code context the meta object for the built in function true if we're calling with an instance The arguments being passed to the function A restriction for the built-in function, method desc, etc... A delegate to perform the actual call to the method. Provides (for reflected methods) a mapping from a signature to the exact target which takes this signature. signature with syntax like the following: someClass.SomeMethod.Overloads[str, int]("Foo", 123) Gets the overload dictionary for the logical function. These overloads are never bound to an instance. Returns the instance used for binding. This differs on module functions implemented using instance methods so the built-in functions there don't expose the instance. A custom built-in function which supports indexing Use indexing on generic methods to provide a new reflected method with targets bound with the supplied type arguments. Find matching overloads by checking signature against available targets Given signature List of possible targets If set to true, the method will check whether the first paramter of the target is of the type CodeContext and removes it Possible overloads Throws a formatted exception if no overload matchs. Passed signature which should be used Given targets, which does not fit to the signature Provides a CustomTracker which handles special fields which have custom behavior on get/set. Provides custom, versioned, dictionary access for instances. Used for both new-style and old-style instances. Each class can allocate a version for instance storage using the CustomInstanceDictionaryStorage.AllocateInstance method. The version allocated is dependent upon the names which are likely to appear in the instance dictionary. Currently these names are calculated by collecting the names that are assigned to during the __init__ method and combining these with all such names in the types MRO. When creating the dictionary for storing instance values the class can then create a PythonDictionary backed by a CustomInstanceDictionaryStorage with it's version. When doing a get/set optimized code can then be produced that verifies we have CustomInstanceDictionaryStorage and it has the correct version. If we have a matching dictionary then gets/sets can turn into simple array accesses rather than dictionary gets/sets. For programs which access a large number of instance variables this can dramatically speed up the program. TODO: Should we attempt to unify all versions which share the same keys? Creates a DLR OverloadDoc object which describes information about this overload. The method to document The name of the method if it should override the name in the MethodBase Parameters to skip at the end - used for removing the value on a setter method true to include self on instance methods Converts a Type object into a string suitable for lookup in the help file. All generic types are converted down to their generic type definition. Gets the XPathDocument for the specified assembly, or null if one is not available. Gets the Xml documentation for the specified MethodBase. Gets the Xml documentation for the specified Type. Gets the Xml documentation for the specified Field. Gets the Xml documentation for the specified Field. Converts the XML as stored in the config file into a human readable string. Marks a type as being a suitable type to be used for user-defined classes. The requirements for this are that a type has to follow the patterns that NewTypeMaker derived types follow. This includes: The type's constructors must all take PythonType as the 1st parameter which sets the underlying type for the actual object The type needs to implement IPythonObject Dictionary-based storage needs to be provided for setting individual members Virtual methods exposed to Python need to support checking the types dictionary for invocations Represents a set of attributes that different functions can have. No flags have been set This is a function w/ no instance pointer This is a method that requires an instance Built-in functions can encapsulate both methods and functions, in which case both bits are set True is the function/method should be visible from pure-Python code True if this is a __r*__ method for a CLS overloaded operator method This method represents a binary operator method for a CLS overloaded operator method. Being a binary operator causes the following special behaviors to kick in: A failed binding at call time returns NotImplemented instead of raising an exception A reversed operator will automatically be created if: 1. The parameters are both of the instance type 2. The parameters are in reversed order (other, this) This enables simple .NET operator methods to be mapped into the Python semantics. A method declared on a built-in module Base class for helper which creates instances. We have two derived types: One for user defined types which prepends the type before calling, and one for .NET types which doesn't prepend the type. This interface is used for implementing parts of the IronPython type system. It is not intended for consumption from user programs. Thread-safe dictionary set. Returns the dictionary set or the previous value if already set or null if the dictionary set isn't supported. Dictionary replacement. Returns true if replaced, false if the dictionary set isn't supported. Calculates the method resolution order for a Python class the rules are: If A is a subtype of B, then A has precedence (A > B) If C appears before D in the list of bases then C > D If E > F in one __mro__ then E > F in all __mro__'s for our subtype class A(object): pass class B(object): pass class C(B): pass class N(A,B,C): pass # illegal This is because: C.__mro__ == (C, B, object) N.__mro__ == (N, A, B, C, object) which would conflict, but: N(B,A) is ok (N, B, a, object) N(C, B, A) is ok (N, C, B, A, object) Calculates a C3 MRO as described in "The Python 2.3 Method Resolution Order" plus support for old-style classes. We build up a list of our base classes MRO's plus our base classes themselves. We go through the list in order. Look at the 1st class in the current list, and if it's not the non-first class in any other list then remove it from all the lists and append it to the mro. Otherwise continue to the next list. If all the classes at the start are no-good then the MRO is bad and we throw. For old-style classes if the old-style class is the only one in the list of bases add it as a depth-first old-style MRO, otherwise compute a new-style mro for all the classes and use that. Contains helper methods for converting C# names into Python names. TypeInfo captures the minimal CLI information required by NewTypeMaker for a Python object that inherits from a CLI type. "bases" contains a set of PythonTypes. These can include types defined in Python (say cpy1, cpy2), CLI types (say cCLI1, cCLI2), and CLI interfaces (say iCLI1, iCLI2). Here are some examples of how this works: (bases) => baseType, {interfaceTypes} (cpy1) => System.Object, {} (cpy1, cpy2) => System.Object, {} (cpy1, cCLI1, iCLI1, iCLI2) => cCLI1, {iCLI1, iCLI2} [some type that satisfies the line above] => cCLI1, {iCLI1, iCLI2} (cCLI1, cCLI2) => error Filters out old-classes and throws if any non-types are included, returning a yielding the remaining PythonType objects. Python class hierarchy is represented using the __class__ field in the object. It does not use the CLI type system for pure Python types. However, Python types which inherit from a CLI type, or from a builtin Python type which is implemented in the engine by a CLI type, do have to use the CLI type system to interoperate with the CLI world. This means that objects of different Python types, but with the same CLI base type, can use the same CLI type - they will just have different values for the __class__ field. The easiest way to inspect the functionality implemented by NewTypeMaker is to persist the generated IL using "ipy.exe -X:SaveAssemblies", and then inspect the persisted IL using ildasm. Loads any available new types from the provided assembly and makes them available via the GetNewType API. Is this a type used for instances Python types (and not for the types themselves)? Gets the position for the parameter which we are overriding. Defines an interface on the type that forwards all calls to a helper method in UserType. The method names all will have Helper appended to them to get the name for UserType. The UserType version should take 1 extra parameter (self). Overrides methods - this includes all accessible virtual methods as well as protected non-virtual members including statics and non-statics. Loads all the incoming arguments and forwards them to mi which has the same signature and then returns the result Emits code to check if the class has overridden this specific function. For example: MyDerivedType.SomeVirtualFunction = ... or class MyDerivedType(MyBaseType): def SomeVirtualFunction(self, ...): Emit code to convert object to a given type. This code is semantically equivalent to PythonBinder.EmitConvertFromObject, except this version accepts ILGen whereas PythonBinder accepts Compiler. The Binder will chagne soon and the two will merge. Emits code to check if the class has overridden this specific function. For example: MyDerivedType.SomeVirtualFunction = ... or class MyDerivedType(MyBaseType): def SomeVirtualFunction(self, ...): Emits the call to lookup a member defined in the user's type. Returns the local which stores the resulting value and leaves a value on the stack indicating the success of the lookup. Creates a method for doing a base method dispatch. This is used to support super(type, obj) calls. Generates stub to receive the CLR call and then call the dynamic language code. This code is same as StubGenerator.cs in the Microsoft.Scripting, except it accepts ILGen instead of Compiler. Called from PythonTypeOps - the BuiltinFunction._function lock must be held. Same as the DLR ReturnFixer, but accepts lower level constructs, such as LocalBuilder, ParameterInfos and ILGen. Returns the dictionary used to store state for this object OperatorMapping provides a mapping from DLR operators to their associated .NET methods. Given an operator returns the OperatorMapping associated with the operator or null The operator the OperatorMapping provides info for. The primary method name associated with the method. This method name is usally in the form of op_Operator (e.g. op_Addition). The secondary method name associated with the method. This method name is usually a standard .NET method name with pascal casing (e.g. Add). The return type that must match for the alternate operator to be valid. This is available alternate operators don't have special names and therefore could be confused for a normal method which isn't fulfilling the contract. Cached CallSites. User types are cached on the PythonType and System types are cached on the PythonContext to avoid cross-runtime contamination due to the binder on the site. Represents a PythonType. Instances of PythonType are created via PythonTypeBuilder. Provides delegates that will invoke a parameterless type ctor. The first key provides the dictionary for a specific type, the 2nd key provides the delegate for a specific call site type used in conjunction w/ our IFastInvokable implementation. Shared built-in functions for creating instances of user defined types. Because all types w/ the same UnderlyingSystemType share the same constructors these can be shared across multiple types. Creates a new type for a user defined type. The name, base classes (a tuple of type objects), and a dictionary of members is provided. Creates a new type for a user defined type. The name, base classes (a tuple of type objects), and a dictionary of members is provided. Creates a new PythonType object which is backed by the specified .NET type for storage. The type is considered a system type which can not be modified by the user. Creates a new PythonType which is a subclass of the specified PythonType. Used for runtime defined new-style classes which require multiple inheritance. The primary example of this is the exception system. Creates a new PythonType which is a subclass of the specified PythonTypes. Used for runtime defined new-style classes which require multiple inheritance. The primary example of this is the exception system. Creates a new PythonType which is a subclass of the specified PythonTypes. Used for runtime defined new-style classes which require multiple inheritance. The primary example of this is the exception system. Creates a new PythonType which is a subclass of the specified PythonType. Used for runtime defined new-style classes which require multiple inheritance. The primary example of this is the exception system. Creates a new PythonType which is a subclass of the specified PythonTypes. Used for runtime defined new-style classes which require multiple inheritance. The primary example of this is the exception system. Creates a new PythonType which is a subclass of the specified PythonTypes. Used for runtime defined new-style classes which require multiple inheritance. The primary example of this is the exception system. Creates a new PythonType object which represents an Old-style class. Used in copy_reg which is the only consumer of __flags__ in the standard library. Set if the type is user defined Set if the type has __abstractmethods__ defined Check whether the current type is iterabel True if it is iterable Returns true if the specified object is an instance of this type. Gets the name of the dynamic type Gets the resolution order used for attribute lookup Gets the dynamic type that corresponds with the provided static type. Returns null if no type is available. TODO: In the future this will always return a PythonType created by the DLR. Sets the python type that corresponds with the provided static type. This is used for built-in types which have a metaclass. Currently only used by ctypes. Allocates the storage for the instance running the .NET constructor. This provides the creation functionality for __new__ implementations. Allocates the storage for the instance running the .NET constructor. This provides the creation functionality for __new__ implementations. Allocates the storage for the instance running the .NET constructor. This provides the creation functionality for __new__ implementations. Allocates the storage for the instance running the .NET constructor. This provides the creation functionality for __new__ implementations. Allocates the storage for the instance running the .NET constructor. This provides the creation functionality for __new__ implementations. Allocates the storage for the instance running the .NET constructor. This provides the creation functionality for __new__ implementations. Gets the underlying system type that is backing this type. All instances of this type are an instance of the underlying system type. Gets the extension type for this type. The extension type provides a .NET type which can be inherited from to extend sealed classes or value types which Python allows inheritance from. Gets the base types from which this type inherits. Returns true if this type is a subclass of other True if the type is a system type. A system type is a type which represents an underlying .NET type and not a subtype of one of these types. Looks up a slot on the dynamic type Searches the resolution order for a slot matching by name Searches the resolution order for a slot matching by name. Includes searching for methods in old-style classes Internal helper to add a new slot to the type Gets a value from a dynamic type and any sub-types. Values are stored in slots (which serve as a level of indirection). This searches the types resolution order and returns the first slot that contains the value. Attempts to lookup a member w/o using the customizer. Equivelent to object.__getattribute__ but it doens't throw an exception. Gets a value from a dynamic type and any sub-types. Values are stored in slots (which serve as a level of indirection). This searches the types resolution order and returns the first slot that contains the value. Attempts to lookup a member w/o using the customizer. Sets a value on an instance. If a slot is available in the most derived type the slot is set there, otherwise the value is stored directly in the instance. Attempst to set a value w/o going through the customizer. This enables languages to provide the "base" implementation for setting attributes so that the customizer can call back here. Returns a list of all slot names for the type and any subtypes. The context that is doing the inquiry of InvariantContext.Instance. Returns a list of all slot names for the type, any subtypes, and the instance. The context that is doing the inquiry of InvariantContext.Instance. the instance to get instance members from, or null. Adds members from a user defined type. Adds members from a user defined type instance Gets the .NET type which is used for instances of the Python type. When overridden by a metaclass enables a customization of the .NET type which is used for instances of the Python type. Meta-classes can construct custom types at runtime which include new .NET methods, fields, custom attributes or other features to better interoperate with .NET. Initializes a PythonType that represents a standard .NET type. The same .NET type can be shared with the Python type system. For example object, string, int, etc... are all the same types. Creates a __new__ method for the type. If the type defines interesting constructors then the __new__ method will call that. Otherwise if it has only a single argless This will return a unique integer for every version of every type in the system. This means that DynamicSite code can generate a check to see if it has the correct PythonType and version with a single integer compare. TODO - This method and related code should fail gracefully on overflow. Internal helper function to add a subtype Gets a list of weak references to all the subtypes of this class. May return null if there are no subtypes of the class. The type has a ctor which does not accept PythonTypes. This is used for user defined types which implement __clrtype__ Returns a CLR WeakReference object to this PythonType that can be shared between anyone who needs a weak reference to the type. Implements fast binding for user defined types. This ensures that common highly dynamic scenarios will run fast (for instance creating new types repeatedly and only creating a limited number of instances of them). It also gives better code sharing amongst different subclasses of the same types and improved startup time due to reduced code generation. Base class for doing fast type invoke binding. Subclasses are created using reflection once during the binding. The subclasses can then proceed to do the binding w/o using reflection. Otherwise we'd have lots more reflection calls which would slow the binding up. Gets or creates delegate for calling the constructor function. Used when a type overrides __new__ with a Python function or other object that can return an arbitrary value. If the return value is not the same type as the type which had __new__ then we need to lookup __init__ on the type and invoke it. Also handles initialization for finalization when __del__ is defined for the same reasons. target is the newly initialized value. args are the arguments to be passed to __init__ Provides a slot object for the dictionary to allow setting of the dictionary. Helpers for interacting w/ .NET types. This includes: Member resolution via GetMember/GetMembers. This performs a member lookup which includes the registered extension types in the PythonBinder. Internally the class has many MemberResolver's which provide the various resolution behaviors. Cached member access - this is via static classes such as Object and provides various MemberInfo's so we're not constantly looking up via reflection. list of resolvers which we run to resolve items Gets the statically known member from the type with the specific name. Searches the entire type hierarchy to find the specified member. Gets all the statically known members from the specified type. Searches the entire type hierarchy to get all possible members. The result may include multiple resolution. It is the callers responsibility to only treat the 1st one by name as existing. Gets the statically known member from the type with the specific name. Searches only the specified type to find the member. Gets all the statically known members from the specified type. Searches only the specified type to find the members. The result may include multiple resolution. It is the callers responsibility to only treat the 1st one by name as existing. Abstract class used for resolving members. This provides two methods of member look. The first is looking up a single member by name. The other is getting all of the members. There are various subclasses of this which have different methods of resolving the members. The primary function of the resolvers are to provide the name->value lookup. They also need to provide a simple name enumerator. The enumerator is kept simple because it's allowed to return duplicate names as well as return names of members that don't exist. The base MemberResolver will then verify their existance as well as filter duplicates. Looks up an individual member and returns a MemberGroup with the given members. Returns a list of members that exist on the type. The ResolvedMember structure indicates both the name and provides the MemberGroup. Returns a list of possible members which could exist. ResolveMember needs to be called to verify their existance. Duplicate names can also be returned. One off resolver for various special methods which are known by name. A delegate is provided to provide the actual member which will be resolved. Standard resolver for looking up .NET members. Uses reflection to get the members by name. Resolves methods mapped to __eq__ and __ne__ from IStructuralEquatable.Equals Resolves methods mapped to __gt__, __lt__, __ge__, __le__, as well as providing an alternate resolution for __eq__ and __ne__, from the comparable type's CompareTo method. This should be run after the EqualityResolver. Resolves methods mapped to __*__ methods automatically from the .NET operator. Filters alternative methods out that don't match the expected signature and therefore are just sharing a common method name. Removes Object.Equals methods as we never return these for PythonOperationKind. Provides bindings to private members when that global option is enabled. Provides resolutions for protected members that haven't yet been subclassed by NewTypeMaker. Creates the resolver table which includes all the possible resolutions. Provides a resolution for __complex__ Provides a resolution for __float__ Provides a resolution for __int__ Provides a resolution for __long__ Provides a resolution for __getitem__ Provides a resolution for __setitem__ Provides a resolution for __str__. Provides a resolution for __repr__ Helper to see if the type explicitly overrides the method. This ignores members defined on object. Provides a resolution for __hash__ looking for IStructuralEquatable.GetHashCode. Provides a resolution for __new__. For standard .NET types __new__ resolves to their constructor. For Python types they inherit __new__ from their base class. TODO: Can we just always fallback to object.__new__? If not why not? Provides a resolution for next Provides a resolution for __len__ Provides a resolution for __iter__ Looks for an Equals overload defined on the type and if one is present binds __ne__ to an InstanceOps helper. Provides an implementation of __contains__. We can pull contains from: ICollection of T which defines Contains directly IList which defines Contains directly IDictionary which defines Contains directly IDictionary of K,V which defines Contains directly IEnumerable of K which we have an InstaceOps helper for IEnumerable which we have an instance ops helper for IEnumerator of K which we have an InstanceOps helper for IEnumerator which we have an instance ops helper for String is ignored here because it defines __contains__ via extension methods already. The lookup is well ordered and not dependent upon the order of values returned by reflection. Helper for IEnumerable/IEnumerator __contains__ Base class used for resolving a name into a member on the type. Gets an instance op method for the given type and name. Instance ops methods appaer on the base most class that's required to expose it. So if we have: Array[int], Array, object we'd only add an instance op method to Array and Array[int] inherits it. It's obviously not on object because if it was there we'd just put the method in ObjectOps. Therefore the different binders expose this at the appropriate times. MemberBinder which searches the entire type hierarchy and their extension types to find a member. MemberBinder which searches only the current type and it's extension types to find a member. Primary worker for getting the member(s) associated with a single name. Can be called with different MemberBinder's to alter the scope of the search. Primary worker for returning a list of all members in a type. Can be called with different MemberBinder's to alter the scope of the search. Helper to get a MemberGroup for methods declared on InstanceOps Helper to get the proper typecasting method, according to the following precedence rules: 1. Strongest (most specific) declaring type 2. Strongest (most specific) parameter type 3. Type of conversion i. Implicit ii. Explicit 4. Return type (order specified in toTypes) Helper for creating a typecast resolver Helper for creating __getitem__/__setitem__ resolvers false for a getter, true for a setter Filters out methods which are present on standard .NET types but shouldn't be there in Python When private binding is enabled we can have a collision between the private Event and private field backing the event. We filter this out and favor the event. This matches the v1.0 behavior of private binding. Filters down to include only protected methods If an operator is a reverisble operator (e.g. addition) then we need to filter down to just the forward/reverse versions of the .NET method. For example consider: String.op_Multiplication(int, string) String.op_Multiplication(string, int) If this method were defined on string it defines that you can do: 2 * 'abc' or: 'abc' * 2 either of which will produce 'abcabc'. The 1st form is considered the reverse form because it is declared on string but takes a non-string for the 1st argument. The 2nd is considered the forward form because it takes a string as the 1st argument. When dynamically dispatching for 2 * 'abc' we'll first try __mul__ on int, which will fail with a string argument. Then we'll try __rmul__ on a string which will succeed and dispatch to the (int, string) overload. For multiplication in this case it's not too interesting because it's commutative. For addition this might be more interesting if, for example, we had unicode and ASCII strings. In that case Unicode strings would define addition taking both unicode and ASCII strings in both forms. Checks to see if the parameter type and the declaring type are compatible to determine if an operator is forward or reverse. Checks to see if this is an operator method which Python recognizes. For example op_Comma is not recognized by Python and therefore should exposed to the user as a method that is callable by name. A TypeSlot is an item that gets stored in a type's dictionary. Slots provide an opportunity to customize access at runtime when a value is get or set from a dictionary. Gets the value stored in the slot for the given instance binding it to an instance if one is provided and the slot binds to instances. Sets the value of the slot for the given instance. true if the value was set, false if it can't be set Deletes the value stored in the slot from the instance. true if the value was deleted, false if it can't be deleted True if generating code for gets can result in more optimal accesses. Gets an expression which is used for accessing this slot. If the slot lookup fails the error expression is used again. The default implementation just calls the TryGetValue method. Subtypes of PythonTypeSlot can override this and provide a more optimal implementation. True if TryGetValue will always succeed, false if it may fail. This is used to optimize away error generation code. The unbound representation of an event property BoundEvent is the object that gets returned when the user gets an event object. An BoundEvent tracks where the event was received from and is used to verify we get a proper add when dealing w/ statics events. Represents a ReflectedProperty created for an extension method. Logically the property is an instance property but the method implementing it is static. Convenience function for users to call directly This function can be used to set a field on a value type without emitting a warning. Otherwise it is provided only to have symmetry with properties which have GetValue/SetValue for supporting explicitly implemented interfaces. Setting fields on value types usually warns because it can silently fail to update the value you expect. For example consider this example where Point is a value type with the public fields X and Y: arr = System.Array.CreateInstance(Point, 10) arr[0].X = 42 print arr[0].X prints 0. This is because reading the value from the array creates a copy of the value. Setting the value then mutates the copy and the array does not get updated. The same problem exists when accessing members of a class. Base class for properties backed by methods. These include our slot properties, indexers, and normal properties. This class provides the storage of these as well as the storage of our optimized getter/setter methods, documentation for the property, etc... Provides access to non-default .NET indexers (aka properties w/ parameters). C# doesn't support these, but both COM and VB.NET do. The types dictionary gets populated w/a ReflectedGetterSetter indexer which is a descriptor. Getting the descriptor returns a bound indexer. The bound indexer supports indexing. We support multiple indexer parameters via expandable tuples. True if generating code for gets can result in more optimal accesses. Convenience function for users to call directly Convenience function for users to call directly Represents a member of a user-defined type which defines __slots__. The names listed in __slots__ have storage allocated for them with the type and provide fast get/set access. Gets the index into the object array to be used for the slot storage. Couples a MemberGroup and the name which produces the member group together Represents an ops-extension which adds a new slot. The slot can have arbitrary get/set behavior above and beyond normal .NET methods or properties. This is typically in regards to how it processes access from instances or subtypes. single finalizable instance used to track and deliver all the callbacks for a single object that has been weakly referenced by one or more references and proxies. The reference to this object is held in objects that implement IWeakReferenceable. Finalizable object used to hook up finalization calls for OldInstances. We create one of these each time an object w/ a finalizer gets created. The only reference to this object is the instance so when that goes out of context this does as well and this will get finalized. Marks a method/field/property as being a wrapper descriptor. A wrapper desriptor is a member defined on PythonType but is available both for type and other instances of type. For example type.__bases__. For IList arguments: Marks that the argument is typed to accept a bytes or bytearray object. This attribute disallows passing a Python list object and auto-applying our generic conversion. It also enables conversion of a string to a IList of byte in IronPython 2.6. For string arguments: Marks that the argument is typed to accept a bytes object as well. (2.6 only) Provides more specific type information for Python dictionaries which are not strongly typed. This attribute can be applied to fields, parameters, proeprties, and return values. It can be inspected to get type information about the types of the keys and values of the expected dictionary or the returned dictionary. Gets the collection of command line arguments. Should we strip out all doc strings (the -O command line option). Should we strip out all doc strings (the -OO command line option). List of -W (warning filter) options collected from the command line. Enables warnings related to Python 3.0 features. Enables 3.0 features that are implemented in IronPython. Enables debugging support. When enabled a .NET debugger can be attached to the process to step through Python code. Enables inspect mode. After running the main module the REPL will be started within that modules context. Suppresses addition of the user site directory. This is ignored by IronPython except for updating sys.flags. Disables import site on startup. Ignore environment variables that configure the IronPython context. Enables the verbose option which traces import statements. This is ignored by IronPython except for setting sys.flags. Sets the maximum recursion depth. Setting to Int32.MaxValue will disable recursion enforcement. Makes available sys._getframe. Local variables will not be available in frames unless the function calls locals(), dir(), vars(), etc... For ensuring locals are always available use the FullFrames option. Makes available sys._getframe. All locals variables will live on the heap (for a considerable performance cost) enabling introspection of all code. Tracing is always available. Without this option tracing is only enabled when sys.settrace is called. This means code that was already running before sys.settrace will not be debuggable. With this option pdb.set_trace and pdb.post_mortem will always work properly. Severity of a warning that indentation is formatted inconsistently. The division options (old, new, warn, warnall) Forces all code to be compiled in a mode in which the code can be reliably collected by the CLR. Enable profiling code Returns a regular expression of Python files which should not be emitted in debug mode. Gets the CPython version which IronPython will emulate. Currently limited to either 2.6 or 3.0.