MCPcopy Index your code
hub / github.com/RustPython/RustPython / new

Method new

crates/vm/src/codecs.rs:166–207  ·  view source on GitHub ↗
(ctx: &Context)

Source from the content-addressed store, hash-verified

164 }
165
166 pub(crate) fn new(ctx: &Context) -> Self {
167 ::rustpython_vm::common::static_cell! {
168 static METHODS: Box<[PyMethodDef]>;
169 }
170
171 let methods = METHODS.get_or_init(|| {
172 crate::define_methods![
173 "strict_errors" => strict_errors as EMPTY,
174 "ignore_errors" => ignore_errors as EMPTY,
175 "replace_errors" => replace_errors as EMPTY,
176 "xmlcharrefreplace_errors" => xmlcharrefreplace_errors as EMPTY,
177 "backslashreplace_errors" => backslashreplace_errors as EMPTY,
178 "namereplace_errors" => namereplace_errors as EMPTY,
179 "surrogatepass_errors" => surrogatepass_errors as EMPTY,
180 "surrogateescape_errors" => surrogateescape_errors as EMPTY
181 ]
182 .into_boxed_slice()
183 });
184
185 let errors = [
186 ("strict", methods[0].build_function(ctx)),
187 ("ignore", methods[1].build_function(ctx)),
188 ("replace", methods[2].build_function(ctx)),
189 ("xmlcharrefreplace", methods[3].build_function(ctx)),
190 ("backslashreplace", methods[4].build_function(ctx)),
191 ("namereplace", methods[5].build_function(ctx)),
192 ("surrogatepass", methods[6].build_function(ctx)),
193 ("surrogateescape", methods[7].build_function(ctx)),
194 ];
195 let errors = errors
196 .into_iter()
197 .map(|(name, f)| (name.to_owned(), f.into()))
198 .collect();
199 let inner = RegistryInner {
200 search_path: Vec::new(),
201 search_cache: HashMap::new(),
202 errors,
203 };
204 Self {
205 inner: PyRwLock::new(inner),
206 }
207 }
208
209 pub fn register(&self, search_function: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
210 if !search_function.is_callable() {

Callers

nothing calls this directly

Calls 10

newFunction · 0.85
collectMethod · 0.80
downcast_refMethod · 0.80
get_or_initMethod · 0.45
build_functionMethod · 0.45
mapMethod · 0.45
into_iterMethod · 0.45
to_ownedMethod · 0.45
borrow_bufMethod · 0.45
as_objectMethod · 0.45

Tested by

no test coverage detected