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

Function txt2obj

crates/stdlib/src/ssl.rs:4773–4806  ·  view source on GitHub ↗
(args: Txt2ObjArgs, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

4771
4772 #[pyfunction]
4773 fn txt2obj(args: Txt2ObjArgs, vm: &VirtualMachine) -> PyResult<PyObjectRef> {
4774 let txt = args.txt.as_str();
4775 let name = args.name.unwrap_or(false);
4776
4777 // If name=False (default), only accept OID strings
4778 // If name=True, accept both names and OID strings
4779 let entry = if txt
4780 .chars()
4781 .next()
4782 .map(|c| c.is_ascii_digit())
4783 .unwrap_or(false)
4784 {
4785 // Looks like an OID string (starts with digit)
4786 oid::find_by_oid_string(txt)
4787 } else if name {
4788 // name=True: allow shortname/longname lookup
4789 oid::find_by_name(txt)
4790 } else {
4791 // name=False: only OID strings allowed, not names
4792 None
4793 };
4794
4795 let entry = entry.ok_or_else(|| vm.new_value_error(format!("unknown object '{txt}'")))?;
4796
4797 // Return tuple: (nid, shortname, longname, oid)
4798 Ok(vm
4799 .new_tuple((
4800 vm.ctx.new_int(entry.nid),
4801 vm.ctx.new_str(entry.short_name),
4802 vm.ctx.new_str(entry.long_name),
4803 vm.ctx.new_str(entry.oid_string()),
4804 ))
4805 .into())
4806 }
4807
4808 #[pyfunction]
4809 fn nid2obj(nid: i32, vm: &VirtualMachine) -> PyResult<PyObjectRef> {

Callers

nothing calls this directly

Calls 11

find_by_oid_stringFunction · 0.85
find_by_nameFunction · 0.85
charsMethod · 0.80
ok_or_elseMethod · 0.80
oid_stringMethod · 0.80
as_strMethod · 0.45
mapMethod · 0.45
nextMethod · 0.45
new_tupleMethod · 0.45
new_intMethod · 0.45
new_strMethod · 0.45

Tested by

no test coverage detected