[Pyrex] validity of \0 as null-byte representation in pyrex python def?

cmulcahy at avesi.com cmulcahy at avesi.com
Sun Apr 20 16:40:56 CEST 2003


I have the following code in a .pyx file ( see bottom ) 

In testing, the code raises expection at line 41
( except Exception,e:) complaining about an 'empty seperator'. 

the code, fromaddr = recipline.split('\0')[0][1:] et.al
works fine in vanilla python, but pyrex doesn't seem
to like "split('\0')" or recognize it as "split on null-bytes".
Is there a special way to specify null-bytes in Pyrex code? 

-------------- next part --------------
cdef extern from "Python.h":
	object PyString_FromStringAndSize(char *, int)

cdef extern from "mystralloc.h":
	ctypedef struct stralloc:
		char *s
		unsigned int len
		unsigned int a

cdef extern from "xget_recipline.h":
	cdef stralloc xget_recipline(int s, int timeout)

cdef object cget_recipline(int s, int timeout):
	cdef stralloc recipline 
	recipline = xget_recipline(s,timeout)

	try:
		return PyString_FromStringAndSize(recipline.s,recipline.len)
	except:
		return None

def get_recipline(conn,timeout):
	try:
		s = conn.fileno()
		t = int(timeout)
	except Exception, e:
		raise e

	recipline = cget_recipline(s,t)
	if not recipline:
		raise "cget_recipline failed"
	if recipline != str(recipline):
		raise "cget_recipline did not return a string-object"

	try:
		fromaddr = recipline.split('\0')[0][1:].lower()
		recipients = []
		for i in recipline.split('\0')[1:]:
			if i: recipients.append(i[1:].lower())
	except Exception, e:
		raise "Invalid envelope string: %s\n%s" % (recipline,e)
	if not fromaddr or not len(recipients):
			raise "Invalid envelope string: %s" % recipline	

	return (fromaddr,recipients)






	





More information about the Pyrex mailing list