[python-win32] testing ADSI GUID buffer objects

Gabriel Genellina gagsl-p32 at yahoo.com.ar
Thu Jul 27 04:25:37 CEST 2006


At Wednesday 26/7/2006 19:44, David Primmer wrote:

>I am trying to write a unit test for a function that accepts a buffer
>    object. As far as I can tell, buffer's cannot be directly represented
>in code. How do I create the object for the test? (The buffer object comes
>through ADSI in an Active Directory query of the user GUID property).
>If I print the GUID property, it prints a Unicode encoded string of the
>byte stream: u'8108fd1ac12c0d42924355c8d9987f19'. I don't believe this
>is the 'native' representation. The function I'm trying to test
>translates it to MS's hex format: '{38303138-6466-6131-6331-326330643432}'
>
>Any danger using this unicode format?

I think you are mixing many things.

You *can* create a buffer object, using the built-in function buffer():

 >>> x=buffer('hello')
 >>> print x[0]
h
 >>> print x[4]
o
 >>> print x[5]
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
IndexError: buffer index out of range

A GUID is always 16 bytes length. Your Unicode string is 32 bytes 
length; apparently it is the hex representation (two hex chars per 
byte). If you feed the function with that string, it interprets the 
first 16 bytes only, *each* hex number as a byte: 38h='8', 30h='0', 
31h='1'...64h='d' 34h='4' 32h='2'

Can you post an example showing the expected interfase?



Gabriel Genellina
Softlab SRL 


	
	
		
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas



More information about the Python-win32 mailing list