[Pythonmac-SIG] Spotlight and Python

Jonathan Wight jwight_lists at toxicsoftware.com
Wed May 11 20:12:48 CEST 2005


For me it worked:

     "org_python_functions" = ("get_bits", "set_lsb", "get_lsb",  
"value_from_bits");

But then I just made a new BBEdit Bits.py file and pasted your code  
into it.

The importer does seem to be crashing, but I'm not sure whether the  
python or the ObjC is dying. Is there a crash log in either ~/Library/ 
Logs/Crash Logs or /Library/Logs/Crash Logs.

I'm working on version 0.2 with slightly better error handling and a  
lot less leaking of PyObject pointers.

     Jon.

On May 11, 2005, at 13:21, David Reed wrote:

> It doesn't appear to be working:
>
> 510 mac:~/src/CS160/ImageMessage $ mdimport -d 2 bits.py
> 2005-05-11 13:17:48.498 mdimport[3670] Import '/Users/dreed/src/ 
> CS160/ImageMessage/bits.py' type 'public.python-script' using  
> 'file://localhost/Library/Spotlight/Python%20Metadata% 
> 20Importer.mdimporter/'
> 2005-05-11 13:17:48.879 mdimport[3670] -[FileProcessor  
> importMetadataFromFileAtPì¤í¸ íìot exception Conversion to encoding  
> 30 failed for string "ì
> 2005-05-11 13:17:48.897 mdimport[3670] Import '/Users/dreed/src/ 
> CS160/ImageMessage/bits.py' type 'public.python-script' no mdimporter
> 2005-05-11 13:17:48.900 mdimport[3670] Sending attributes of '/ 
> Users/dreed/src/CS160/ImageMessage/bits.py' to server.  Attributes: '{
>     "_kMDItemImporterCrashed" = 1;
>     "com_apple_metadata_modtime" = 137504114;
>     kMDItemContentCreationDate = 2005-05-11 07:35:14 -0400;
>     kMDItemContentModificationDate = 2005-05-11 07:35:14 -0400;
>     kMDItemContentType = "public.python-script";
>     kMDItemContentTypeTree = (
>         "public.python-script",
>         "public.shell-script",
>         "public.script",
>         "public.source-code",
>         "public.plain-text",
>         "public.text",
>         "public.data",
>         "public.item",
>         "public.content"
>     );
>     kMDItemDisplayName = {"" = "bits.py"; };
>     kMDItemKind = {
>         "" = PlainTextType;
>         ca = "Fitxer de Text Planer";
>         da = "Almindeligt tekstdokument";
>         de = "Reine Text-Datei";
>         en = "Plain Text File";
>         fr = "Fichier texte brut";
>         ja = "\U6a19\U6e96\U30c6\U30ad\U30b9\U30c8\U66f8\U985e";
>         ko = "\Uc77c\Ubc18 \Ud14d\Uc2a4\Ud2b8 \Ud30c\Uc77c";
>         ru = "\U041f\U0440\U043e\U0441\U0442\U043e\U0439 \U0442 
> \U0435\U043a\U0441\U0442";
>         "zh-Hant" = "\U7d14\U6587\U5b57\U6a94";
>     };
> }'
>
>
> The bits.py file is just:
>
> #!/usr/bin/env python
>
> #--------------------------------------------------------------------- 
> -
> # bits.py
> # Dave Reed
> # 05/09/2005
> #--------------------------------------------------------------------- 
> -
>
> def get_bits(value, n=8):
>
>     '''get_bits(value, n):
>
>     generator to return individual bits in a value of n bits'''
>
>     pos_value = 2 ** (n-1)
>
>     # if a single character string, convert to ASCII code
>     try:
>         value = ord(value)
>     except:
>         pass
>
>     # for each bit
>     for i in range(n):
>         # get bit n
>         bit = value & pos_value
>         # shift so we can get next bit
>         value = value << 1
>         # if bit is pos_value, that bit was 1
>         if bit == pos_value:
>             yield 1
>         else:
>             yield 0
>
> #--------------------------------------------------------------------- 
> -
>
> def set_lsb(x, b):
>
>     '''set_lsb(x, b):
>
>     returns x with lsb of x set to b (b is 0 or 1)'''
>
>     return (x & 254) | b
>
> #--------------------------------------------------------------------- 
> -
>
> def get_lsb(x):
>
>     '''get_lsb(x):
>
>     returns lsb of x (0 or 1)'''
>
>     return x & 1
>
> #--------------------------------------------------------------------- 
> -
>
> def value_from_bits(bits):
>
>     '''value_from_bits(bits):
>
>     takes a sequence of bit values (each item is 0 or 1) and  
> returns the
>     integer corresponding to that sequence'''
>
>     value = 0
>     for b in bits:
>         value = 2 * value + b
>     return value
>
> #--------------------------------------------------------------------- 
> -
>
>
> Dave
>
>
>



More information about the Pythonmac-SIG mailing list