Commits

Ronald Oussoren committed 905b253

Migrate to new metadata

Comments (0)

Files changed (3)

pyobjc-framework-SearchKit/Lib/SearchKit/__init__.py

 This module does not contain docstrings for the wrapped code, check Apple's
 documentation for details on how to use these functions and classes. 
 '''
+import objc, sys
 
-import objc as _objc
-from CoreFoundation import *
+import CoreFoundation
+from SearchKit import _metadata
 
-__bundle__ = _objc.initFrameworkWrapper("SearchKit",
-    frameworkIdentifier="com.apple.SearchKit",
-    frameworkPath=_objc.pathForFramework(
+mod = objc.ObjCLazyModule(
+    "SearchKit", "com.apple.SearchKit",
+    objc.pathForFramework(
         "/System/Library/Frameworks/CoreServices.framework/Frameworks/SearchKit.framework"),
-    globals=globals())
+    _metadata.__dict__, None, {
+        '__doc__': __doc__,
+        'objc': objc,
+        '__path__': __path__,
+    }, (CoreFoundation,))
+
+
 
 try:
-    SKIndexGetTypeID
-    SKDocumentRef
+    mod.SKIndexGetTypeID
+    mod.SKDocumentRef
 
 except NameError:
     # SKIndexGetTypeID is documented, but not actually exported by Leopard. Try to
 
         pool = NSAutoreleasePool.alloc().init()
         try:
-            rI = SKIndexCreateWithMutableData(NSMutableData.data(),
+            rI = mod.SKIndexCreateWithMutableData(NSMutableData.data(),
                     None, kSKIndexInverted, None)
 
-            indexID = CFGetTypeID(rI)
+            indexID = mod.CFGetTypeID(rI)
 
-            r = SKIndexDocumentIteratorCreate(rI, None)
-            iterID = CFGetTypeID(r)
+            r = mod.SKIndexDocumentIteratorCreate(rI, None)
+            iterID = mod.CFGetTypeID(r)
             del r
 
-            r = SKSearchGroupCreate([rI])
-            groupID = CFGetTypeID(r)
+            r = mod.SKSearchGroupCreate([rI])
+            groupID = mod.CFGetTypeID(r)
 
-            r = SKSearchResultsCreateWithQuery(r, ".*", kSKSearchRanked, 1, None, None)
-            resultID = CFGetTypeID(r)
+            r = mod.SKSearchResultsCreateWithQuery(r, ".*", mod.kSKSearchRanked, 1, None, None)
+            resultID = mod.CFGetTypeID(r)
 
-            if SKSearchGetTypeID() == 0:
+            if mod.SKSearchGetTypeID() == 0:
                 # Type doesn't get registered unless you try to use it.
                 # That's no good for PyObjC, therefore forcefully create
                 # a SKSearch object
-                SKSearchCreate(rI, "q", 0)
+                mod.SKSearchCreate(rI, "q", 0)
                 searchref = objc.registerCFSignature(
-                        "SKSearchRef", b"^{__SKSearch=}", SKSearchGetTypeID())
+                        "SKSearchRef", b"^{__SKSearch=}", mod.SKSearchGetTypeID())
             else:
-                searchref = SKSearchRef
+                searchref = mod.SKSearchRef
 
             del r
             del rI
 
-            r = SKSummaryCreateWithString("foo")
-            summaryID = CFGetTypeID(r)
+            r = mod.SKSummaryCreateWithString("foo")
+            summaryID = mod.CFGetTypeID(r)
             del r
 
         finally:
         # when the framework loader calls it the first time around,
         # by this time the framework is fully initialized and we get
         # the correct result.
-        SKDocumentRef = objc.registerCFSignature(
-                "SKDocumentRef", b"@", SKDocumentGetTypeID())
+        mod.SKDocumentRef = objc.registerCFSignature(
+                "SKDocumentRef", b"@", mod.SKDocumentGetTypeID())
 
 
         return (SKIndexGetTypeID, indexType, SKIndexDocumentIteratorGetTypeID, iterType, 
                 SKSummaryGetTypeID, summaryType, iterType,
                 SKDocumentRef, searchref)
 
-    (SKIndexGetTypeID, SKIndexRef, 
-        SKIndexDocumentIteratorGetTypeID, SKIndexDocumentRef, 
-        SKSearchGroupGetTypeID, SKSearchGroupRef,
-        SKSearchResultsGetTypeID, SKSearchResultsRef,
-        SKSummaryGetTypeID, SKSummaryRef,
-        SKIndexDocumentIteratorRef,
-        SKDocumentRef, SKSearchRef,
+    (mod.SKIndexGetTypeID, mod.SKIndexRef, 
+        mod.SKIndexDocumentIteratorGetTypeID, mod.SKIndexDocumentRef, 
+        mod.SKSearchGroupGetTypeID, mod.SKSearchGroupRef,
+        mod.SKSearchResultsGetTypeID, mod.SKSearchResultsRef,
+        mod.SKSummaryGetTypeID, mod.SKSummaryRef,
+        mod.SKIndexDocumentIteratorRef,
+        mod.SKDocumentRef, mod.SKSearchRef,
     ) = workaround()
 
     del workaround
+
+sys.modules['SearchKit']  = mod

pyobjc-framework-SearchKit/PyObjCTest/test_skindex.py

         self.assertArgIsBOOL(SKIndexAddDocumentWithText, 3)
 
 
+        fn = u"/Library/Documentation/Acknowledgements.rtf"
+        if not os.path.exists(fn):
+            fn = u"/Library/Documentation/AirPort Acknowledgements.rtf"
+
         doc = SKDocumentCreateWithURL(
                 CFURLCreateWithFileSystemPath(
-                    None, u"/Library/Documentation/Acknowledgements.rtf",
+                    None, fn,
                     kCFURLPOSIXPathStyle, False))
 
-
         v = SKIndexAddDocumentWithText(ref, 
                 doc, "hello world", True)
         self.failUnless(v)
 
-
         self.assertResultIsBOOL(SKIndexAddDocument)
         self.assertArgIsBOOL(SKIndexAddDocument, 3)
         v = SKIndexAddDocument(ref, doc, None, True)
         v = SKIndexCopyDocumentForDocumentID(ref, v)
         self.failUnless(v is doc)
 
-        v = SKIndexRenameDocument(ref, doc, "osx-acks.rtf")
-        self.failUnless(v is True)
-
-        v = SKIndexMoveDocument(ref, doc, None)
-        self.failUnless(v is True)
+        r = SKIndexFlush(ref)
+        self.assertIs(r, True)
 
         self.assertResultIsCFRetained(SKIndexDocumentIteratorCreate)
         it = SKIndexDocumentIteratorCreate(ref, None)
         v = SKIndexGetDocumentTermCount(ref, docID)
         self.assertIsInstance(v, (int, long))
 
+
         v = SKIndexCopyTermIDArrayForDocumentID(ref, docID)
         self.assertIsInstance(v, CFArrayRef)
-        tID = v[0]
+
+        tID =  SKIndexGetMaximumTermID(ref) - 1
+
 
         v = SKIndexGetDocumentTermFrequency(ref, docID, tID)
         self.assertIsInstance(v, (int, long))
         self.assertIsInstance(v, (int, long))
 
         v = SKIndexCopyDocumentIDArrayForTermID(ref, tID)
-        self.assertIsInstance(v, CFArrayRef)
+        self.assertIsInstance(v, (CFArrayRef, type(None)))
 
         v = SKIndexCopyTermStringForTermID(ref, tID)
-        self.assertIsInstance(v, unicode)
+        self.assertIsInstance(v, (unicode, type(None)))
 
         v = SKIndexGetTermIDForTermString(ref, v)
         self.assertIsInstance(v, (int, long))
 
         SKLoadDefaultExtractorPlugIns()
 
+        v = SKIndexRenameDocument(ref, doc, "osx-acks.rtf")
+        self.failUnless(v is True)
+
+        v = SKIndexMoveDocument(ref, doc, None)
+        self.failUnless(v is True)
+
         v = SKIndexRemoveDocument(ref, doc)
         self.failUnless(v)
 

pyobjc-framework-SearchKit/PyObjCTest/test_sksearch.py

         ctx = 10
 
         res = SKSearchResultsCreateWithQuery(
-                grp, u"apache", kSKSearchRequiredRanked, 2, ctx, callback)
+                grp, u"copyright", kSKSearchRequiredRanked, 2, ctx, callback)
         self.assertIsInstance(res, SKSearchResultsRef)
 
         res = SKSearchResultsCreateWithDocuments(