@@ -71,18 +71,18 @@ public void initialize(Python3Core core) {
71
71
builtinConstants .put ("QUOTE_ALL" , QUOTE_ALL .ordinal ());
72
72
builtinConstants .put ("QUOTE_NONNUMERIC" , QUOTE_NONNUMERIC .ordinal ());
73
73
builtinConstants .put ("QUOTE_NONE" , QUOTE_NONE .ordinal ());
74
- builtinConstants .put ("_dialects" , PythonObjectFactory . getUncached ().createDict ());
74
+ builtinConstants .put ("_dialects" , core . factory ().createDict ());
75
75
super .initialize (core );
76
76
}
77
77
78
- @ Builtin (name = "register_dialect" , parameterNames = {"name" ,
79
- "dialect" }, minNumOfPositionalArgs = 1 , takesVarKeywordArgs = true , doc = "Create a mapping from a string name to a dialect class.\n " +
78
+ @ Builtin (name = "register_dialect" , parameterNames = { "$mod" , "name" ,
79
+ "dialect" }, minNumOfPositionalArgs = 2 , takesVarKeywordArgs = true , declaresExplicitSelf = true , doc = "Create a mapping from a string name to a dialect class.\n " +
80
80
"dialect = csv.register_dialect(name, dialect)" )
81
81
@ GenerateNodeFactory
82
82
public abstract static class CSVRegisterDialectNode extends PythonBuiltinNode {
83
83
84
84
@ Specialization
85
- PNone register (VirtualFrame frame , Object nameObj , Object dialectObj , PKeyword [] keywords ,
85
+ PNone register (VirtualFrame frame , PythonModule module , Object nameObj , Object dialectObj , PKeyword [] keywords ,
86
86
@ Cached CastToJavaStringNode nameNode ,
87
87
@ Cached ReadAttributeFromObjectNode readNode ,
88
88
@ Cached CallNode callNode ,
@@ -97,9 +97,7 @@ PNone register(VirtualFrame frame, Object nameObj, Object dialectObj, PKeyword[]
97
97
98
98
Object result = callNode .execute (frame , PythonBuiltinClassType .CSVDialect , new Object []{dialectObj }, keywords );
99
99
100
- PythonModule module = getCore ().lookupBuiltinModule ("_csv" );
101
100
Object dialects = readNode .execute (module , "_dialects" );
102
-
103
101
// TODO: Write PyDictSetItem Node?
104
102
HashingStorage storage = library .setItem (((PDict ) dialects ).getDictStorage (), name , result );
105
103
((PDict ) dialects ).setDictStorage (storage );
@@ -108,16 +106,15 @@ PNone register(VirtualFrame frame, Object nameObj, Object dialectObj, PKeyword[]
108
106
}
109
107
}
110
108
111
- @ Builtin (name = "unregister_dialect" , parameterNames = {"name" }, minNumOfPositionalArgs = 1 , doc = "Delete the name/dialect mapping associated with a string name.\n " +
109
+ @ Builtin (name = "unregister_dialect" , parameterNames = {"$mod" , " name" }, minNumOfPositionalArgs = 2 , declaresExplicitSelf = true , doc = "Delete the name/dialect mapping associated with a string name.\n " +
112
110
"csv.unregister_dialect(name)" )
113
111
@ GenerateNodeFactory
114
112
public abstract static class CSVUnregisterDialectNode extends PythonBuiltinNode {
115
113
@ Specialization
116
- PNone unregister (Object nameObj ,
114
+ PNone unregister (PythonModule module , Object nameObj ,
117
115
@ Cached ReadAttributeFromObjectNode readNode ,
118
116
@ CachedLibrary (limit = "1" ) HashingStorageLibrary library ) {
119
117
120
- PythonModule module = getCore ().lookupBuiltinModule ("_csv" );
121
118
Object dialects = readNode .execute (module , "_dialects" );
122
119
123
120
//TODO: Should we write a PyDict_DelItem Node?
@@ -131,22 +128,21 @@ PNone unregister(Object nameObj,
131
128
}
132
129
}
133
130
134
- @ Builtin (name = "get_dialect" , parameterNames = {"name" }, minNumOfPositionalArgs = 1 , doc = "Return the dialect instance associated with name.\n " +
131
+ @ Builtin (name = "get_dialect" , parameterNames = {"$mod" , " name" }, minNumOfPositionalArgs = 2 , declaresExplicitSelf = true , doc = "Return the dialect instance associated with name.\n " +
135
132
"dialect = csv.get_dialect(name)" )
136
133
@ GenerateNodeFactory
137
134
public abstract static class CSVGetDialectNode extends PythonBuiltinNode {
138
135
139
- public abstract CSVDialect execute (VirtualFrame frame , Object name );
136
+ public abstract CSVDialect execute (VirtualFrame frame , PythonModule module , Object name );
140
137
141
138
protected static CSVGetDialectNode create () {
142
139
return CSVModuleBuiltinsFactory .CSVGetDialectNodeFactory .create (null );
143
140
}
144
141
@ Specialization
145
- CSVDialect get (VirtualFrame frame , Object nameObj ,
142
+ CSVDialect get (VirtualFrame frame , PythonModule module , Object nameObj ,
146
143
@ Cached PyDictGetItem getItemNode ,
147
144
@ Cached ReadAttributeFromObjectNode readNode ) {
148
145
149
- PythonModule module = getCore ().lookupBuiltinModule ("_csv" );
150
146
PDict dialects = (PDict ) readNode .execute (module , "_dialects" );
151
147
152
148
CSVDialect dialect = (CSVDialect ) getItemNode .execute (frame , dialects , nameObj );
@@ -159,19 +155,17 @@ CSVDialect get(VirtualFrame frame, Object nameObj,
159
155
}
160
156
}
161
157
162
- @ Builtin (name = "list_dialects" , doc = "Return a list of all known dialect names.\n " +
158
+ @ Builtin (name = "list_dialects" , parameterNames = { "$mod" }, declaresExplicitSelf = true , doc = "Return a list of all known dialect names.\n " +
163
159
"names = csv.list_dialects()" )
164
160
@ GenerateNodeFactory
165
161
public abstract static class CSVListDialectsNode extends PythonBuiltinNode {
166
162
@ Specialization
167
- PList listDialects (VirtualFrame frame ,
163
+ PList listDialects (VirtualFrame frame , PythonModule module ,
168
164
@ Cached ReadAttributeFromObjectNode readNode ,
169
165
@ CachedLibrary (limit = "1" ) HashingStorageLibrary library ,
170
166
@ Cached ListNodes .ConstructListNode constructListNode ) {
171
167
172
- PythonModule module = getCore ().lookupBuiltinModule ("_csv" );
173
168
Object dialects = readNode .execute (module , "_dialects" );
174
-
175
169
return constructListNode .execute (frame , dialects );
176
170
}
177
171
}
@@ -234,13 +228,13 @@ Object createReader(VirtualFrame frame, Object outputFile, Object dialectObj, PK
234
228
public abstract static class CSVFieldSizeLimitNode extends PythonBuiltinNode {
235
229
@ Specialization
236
230
long getOrSetFieldSizeLimit (VirtualFrame frame , Object newLimit ,
237
- @ Cached PyLongCheckExactNode checkIntNode ,
231
+ @ Cached PyLongCheckExactNode checkLongNode ,
238
232
@ Cached PyLongAsLongNode castToLong ) {
239
233
240
234
long oldLimit = fieldLimit ;
241
235
242
236
if (newLimit != PNone .NO_VALUE ) {
243
- if (!PyLongCheckExactNode . getUncached () .execute (newLimit )) {
237
+ if (!checkLongNode .execute (newLimit )) {
244
238
throw raise (PythonBuiltinClassType .TypeError , ErrorMessages .MUST_BE_INTEGER , "limit" );
245
239
}
246
240
@@ -271,7 +265,8 @@ CSVDialect doStringWithoutKeywords(VirtualFrame frame, PythonBuiltinClassType cl
271
265
@ Cached CSVModuleBuiltins .CSVGetDialectNode getDialect ,
272
266
@ Cached ReadAttributeFromObjectNode readNode ,
273
267
@ Cached PyDictGetItem getItemNode ) {
274
- return getDialect .get (frame , dialectName , getItemNode , readNode );
268
+ PythonModule module = getCore ().lookupBuiltinModule ("_csv" );
269
+ return getDialect .get (frame , module , dialectName , getItemNode , readNode );
275
270
}
276
271
277
272
@ Specialization
@@ -299,8 +294,8 @@ Object doStringWithKeywords(VirtualFrame frame, PythonBuiltinClassType cls, Stri
299
294
@ Cached PyObjectIsTrueNode isTrueNode ,
300
295
@ Cached PyLongCheckExactNode pyLongCheckExactNode ,
301
296
@ Cached PyLongAsIntNode pyLongAsIntNode ) {
302
-
303
- CSVDialect dialectObj = getDialect .get (frame , dialectName , getItemNode , readNode );
297
+ PythonModule module = getCore (). lookupBuiltinModule ( "_csv" );
298
+ CSVDialect dialectObj = getDialect .get (frame , module , dialectName , getItemNode , readNode );
304
299
305
300
if (delimiterObj == PNone .NO_VALUE ) delimiterObj = dialectObj .delimiter ;
306
301
if (doublequoteObj == PNone .NO_VALUE ) doublequoteObj = dialectObj .doubleQuote ;
@@ -355,7 +350,8 @@ Object doPStringWithKeywords(VirtualFrame frame, PythonBuiltinClassType cls, PSt
355
350
@ Cached PyLongAsIntNode pyLongAsIntNode ) {
356
351
357
352
String dialectNameStr = castToJavaStringNode .execute (dialectName );
358
- CSVDialect dialectObj = getDialect .get (frame , dialectNameStr , getItemNode , readNode );
353
+ PythonModule module = getCore ().lookupBuiltinModule ("_csv" );
354
+ CSVDialect dialectObj = getDialect .get (frame , module , dialectNameStr , getItemNode , readNode );
359
355
360
356
if (delimiterObj == PNone .NO_VALUE ) delimiterObj = dialectObj .delimiter ;
361
357
if (doublequoteObj == PNone .NO_VALUE ) doublequoteObj = dialectObj .doubleQuote ;
0 commit comments