Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
ironpython3/Src/IronPython/Runtime/ModuleContext.cs at master · cppfool/ironpython3 · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
cppfool
/
ironpython3
Public
forked from
IronLanguages/ironpython3
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Files
Expand file tree
master
Breadcrumbs
ironpython3
/
Src
/
IronPython
/
Runtime
/
ModuleContext.cs
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
165 lines (150 loc) · 5.88 KB
master
Breadcrumbs
ironpython3
/
Src
/
IronPython
/
Runtime
/
ModuleContext.cs
Copy path
Top
File metadata and controls
Code
Blame
165 lines (150 loc) · 5.88 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* ****************************************************************************
*
* Copyright (c) Microsoft Corporation.
*
* This source code is subject to terms and conditions of the Apache License, Version 2.0. A
* copy of the license can be found in the License.html file at the root of this distribution. If
* you cannot locate the Apache License, Version 2.0, please send an email to
* dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
* by the terms of the Apache License, Version 2.0.
*
* You must not remove this notice, or any other, from this software.
*
*
* ***************************************************************************/
using
System
;
using
System
.
Diagnostics
;
using
Microsoft
.
Scripting
.
Runtime
;
using
Microsoft
.
Scripting
.
Utils
;
namespace
IronPython
.
Runtime
{
/// <summary>
/// Captures the globals and other state of module code.
/// </summary>
public
sealed
class
ModuleContext
{
private
readonly
PythonContext
/*!*/
_pyContext
;
private
readonly
PythonDictionary
/*!*/
_globals
;
private
readonly
CodeContext
/*!*/
_globalContext
;
private
readonly
PythonModule
_module
;
private
ExtensionMethodSet
_extensionMethods
=
ExtensionMethodSet
.
Empty
;
private
ModuleOptions
_features
;
/// <summary>
/// Creates a new ModuleContext which is backed by the specified dictionary.
/// </summary>
public
ModuleContext
(
PythonDictionary
/*!*/
globals
,
PythonContext
/*!*/
creatingContext
)
{
ContractUtils
.
RequiresNotNull
(
globals
,
"globals"
)
;
ContractUtils
.
RequiresNotNull
(
creatingContext
,
"creatingContext"
)
;
_globals
=
globals
;
_pyContext
=
creatingContext
;
_globalContext
=
new
CodeContext
(
globals
,
this
)
;
_module
=
new
PythonModule
(
globals
)
;
_module
.
Scope
.
SetExtension
(
_pyContext
.
ContextId
,
new
PythonScopeExtension
(
_pyContext
,
_module
,
this
)
)
;
}
/// <summary>
/// Creates a new ModuleContext for the specified module.
/// </summary>
public
ModuleContext
(
PythonModule
/*!*/
module
,
PythonContext
/*!*/
creatingContext
)
{
ContractUtils
.
RequiresNotNull
(
module
,
"module"
)
;
ContractUtils
.
RequiresNotNull
(
creatingContext
,
"creatingContext"
)
;
_globals
=
module
.
__dict__
;
_pyContext
=
creatingContext
;
_globalContext
=
new
CodeContext
(
_globals
,
this
)
;
_module
=
module
;
}
/// <summary>
/// Gets the dictionary used for the global variables in the module
/// </summary>
public
PythonDictionary
/*!*/
Globals
{
get
{
return
_globals
;
}
}
/// <summary>
/// Gets the language context which created this module.
/// </summary>
public
PythonContext
/*!*/
Context
{
get
{
return
_pyContext
;
}
}
/// <summary>
/// Gets the DLR Scope object which is associated with the modules dictionary.
/// </summary>
public
Scope
/*!*/
GlobalScope
{
get
{
return
_module
.
Scope
;
}
}
/// <summary>
/// Gets the global CodeContext object which is used for execution of top-level code.
/// </summary>
public
CodeContext
/*!*/
GlobalContext
{
get
{
return
_globalContext
;
}
}
/// <summary>
/// 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.
/// </summary>
public
PythonModule
Module
{
get
{
return
_module
;
}
}
/// <summary>
/// Gets the features that code has been compiled with in the module.
/// </summary>
public
ModuleOptions
Features
{
get
{
return
_features
;
}
set
{
_features
=
value
;
}
}
/// <summary>
/// Gets or sets whether code running in this context should display
/// CLR members (for example .ToString on objects).
/// </summary>
public
bool
ShowCls
{
get
{
return
(
_features
&
ModuleOptions
.
ShowClsMethods
)
!=
0
;
}
set
{
Debug
.
Assert
(
this
!=
this
.
_pyContext
.
SharedContext
.
ModuleContext
||
!
value
)
;
if
(
value
)
{
_features
|=
ModuleOptions
.
ShowClsMethods
;
}
else
{
_features
&=
~
ModuleOptions
.
ShowClsMethods
;
}
}
}
internal
ExtensionMethodSet
ExtensionMethods
{
get
{
return
_extensionMethods
;
}
set
{
_extensionMethods
=
value
;
}
}
/// <summary>
/// Initializes __builtins__ for the module scope.
/// </summary>
internal
void
InitializeBuiltins
(
bool
moduleBuiltins
)
{
// adds __builtin__ variable if necessary. Python adds the module directly to
// __main__ and __builtin__'s dictionary for all other modules. Our callers
// pass the appropriate flags to control this behavior.
if
(
!
Globals
.
ContainsKey
(
"__builtins__"
)
)
{
if
(
moduleBuiltins
)
{
Globals
[
"__builtins__"
]
=
Context
.
BuiltinModuleInstance
;
}
else
{
Globals
[
"__builtins__"
]
=
Context
.
BuiltinModuleDict
;
}
}
}
}
}
You can’t perform that action at this time.