def _retrieve_certificate(c_session, req_ca_dn, nreqs, pk_algos, pk_algos_length, retr_st): session = PyObj_FromPtr(gnutls_session_get_ptr(c_session)) identity = session.credentials.select_server_identity(session) retr_st.contents.deinit_all = 0 if identity is None: retr_st.contents.ncerts = 0 else: retr_st.contents.ncerts = 1 retr_st.contents.cert_type = GNUTLS_CRT_X509 retr_st.contents.cert.x509.contents = identity.cert._c_object retr_st.contents.key.x509 = identity.key._c_object return 0
def encode(self, obj): format_spec = self.FORMAT_SPEC json_repr = super().encode(obj) for match in self.regex.finditer(json_repr): id = int(match.group(1)) no_indent = PyObj_FromPtr(id) json_obj_repr = json.dumps(no_indent.value, sort_keys=self.__sort_keys) json_repr = json_repr.replace( '"{}"'.format(format_spec.format(id)), json_obj_repr) return json_repr
def free(smob): """ When the guile garbage collector frees the smob, remove the extra reference so Python can garbage collect the object. """ #print "PythonSMOB.free" # Get the python object we are pointing too pypointer = guile.scm_smob_data(smob) # Decrease the reference to the pypointer Py_DECREF(PyObj_FromPtr(pypointer)) return 0
def encode(self, obj): format_spec = self.FORMAT_SPEC json_repr = super(MyJSONEnc, self).encode(obj) # default JSON repr # replace any marked-up object ids in the JSON repr with the value returned from the json.dumps() of the corresponding wrapped object for match in self.regex.finditer(json_repr): id = int(match.group(1)) no_indent = PyObj_FromPtr(id) json_obj_repr = json.dumps(no_indent.value, sort_keys=self.__sort_keys) # replace the matched id string with json formatted representation of the corresponding object json_repr = json_repr.replace( '"{}"'.format(format_spec.format(id)), json_obj_repr) return json_repr
def iterencode(self, obj, **kwargs): format_spec = self.FORMAT_SPEC # Local var to expedite accesss # Replace any marked-up NoIndent wrapped values in the JSON repr # with the json.dumps() of the corresponding wrapped Python object for encoded in super(MyEncoder, self).iterencode(obj, **kwargs): match = self.regex.search(encoded) if match: id = int(match.group(1)) no_indent = PyObj_FromPtr(id) json_repr = json.dumps(no_indent.value, **self._kwargs) # Replace the matched id string with json formatted representation # of the corresponding Python object encoded = encoded.replace( '"{}"'.format(format_spec.format(id)), json_repr) yield encoded
def encode(self, obj): format_spec = self.FORMAT_SPEC # Local var to expedite access. json_repr = super(PrettyJsonEncoder, self).encode(obj) # Default JSON. # Replace any marked-up object ids in the JSON repr with the # value returned from the json.dumps() of the corresponding # wrapped Python object. for match in self.regex.finditer(json_repr): # see https://stackoverflow.com/a/15012814/355230 id = int(match.group(1)) no_indent = PyObj_FromPtr(id) json_obj_repr = json.dumps(no_indent.value, cls=PrettyJsonEncoder, sort_keys=self.__sort_keys, separators=(',', ':')) # Replace the matched id string with json formatted representation # of the corresponding Python object. json_repr = json_repr.replace('"{}"'.format(format_spec.format(id)), json_obj_repr) return json_repr
def encode(self, obj): format_spec = self.FORMAT_SPEC # Local var to expedite access. json_repr = super(VariableIndentEncoder, self).encode(obj) # Default JSON. # Replace any marked-up object ids in the JSON repr with the # value returned from the json.dumps() of the corresponding # wrapped Python object. for match in self.regex.finditer(json_repr): # Get id (memory address) of wrapper object and retrieve it id = int(match.group(1)) no_indent = PyObj_FromPtr(id) json_obj_repr = json.dumps(no_indent.value, sort_keys=self.__sort_keys) # Replace the matched id string with json formatted representation # of the corresponding Python object. json_repr = json_repr.replace( '"{}"'.format(format_spec.format(id)), json_obj_repr) return json_repr
def encode(self, obj): #pylint: disable=arguments-differ from _ctypes import PyObj_FromPtr format_spec = self.FORMAT_SPEC # Local var to expedite access. json_repr = super().encode(obj) # Default JSON. # Replace any marked-up object ids in the JSON repr with the # value returned from the json.dumps() of the corresponding # wrapped Python object. for match in self.regex.finditer(json_repr): # see https://stackoverflow.com/a/15012814/355230 id_obj = int(match.group(1)) no_indent = PyObj_FromPtr(id_obj) json_obj_repr = json.dumps(no_indent.value, sort_keys=self.__sort_keys) # Replace the matched id string with json formatted representation # of the corresponding Python object. json_repr = json_repr.replace(f'"{format_spec.format(id_obj)}"', json_obj_repr) return json_repr
def get(smob): pypointer = guile.scm_smob_data(smob) return PyObj_FromPtr(pypointer)
def hooked_dict_new(typ, args, kwargs): print('dict_new called', '\n\targs:', PyObj_FromPtr(args) if args else 'NULL', '\n\tkwargs:', PyObj_FromPtr(kwargs) if kwargs else 'NULL') return dict_new(typ, args, kwargs)
def make_dictproxy(obj): assert isinstance(obj,dict) return PyObj_FromPtr(PyDictProxy_New(obj))
def di(obj_id): """ Inverse of built-in id() function. see https://stackoverflow.com/a/15012814/355230 """ return PyObj_FromPtr(obj_id)
def PyObj_del(scm): """\ The finalizer of PyObj. Decrease the ref-count of the referenced Python object here. """ Py_DECREF(PyObj_FromPtr(PyObj.pointer(SCMRef(scm))))
def get(scm): "Return the referenced Python Object." return PyObj_FromPtr(mz.PyObj_id(scm))