pyobjc / Lib / objc / _bridges.py

The branch 'pyobjc-ancient' does not exist.
from _objc import *
import warnings

__all__ = ['PyObjCStrBridgeWarning']

class PyObjCStrBridgeWarning(DeprecationWarning):
    pass

BRIDGED_STRUCTURES = {}
BRIDGED_TYPES = []

def str_to_unicode(s):
    if not getStrBridgeEnabled():
        warnings.warn("use unicode(str, encoding) for NSString", PyObjCStrBridgeWarning, stacklevel=2)
    return unicode(s)
BRIDGED_TYPES.append((str, str_to_unicode))

# XXX - these could let us remove code from OC_PythonObject
#NSNumber = lookUpClass('NSNumber')
#BRIDGED_TYPES.extend([
#    (bool, NSNumber.numberWithBool_),
#    (int, NSNumber.numberWithInt_),
#    (float, NSNumber.numberWithDouble_),
#    (long, NSNumber.numberWithLongLong_),
#])

try:
    from array import array
    from Carbon.File import FSRef
except ImportError:
    pass
else:
    def struct_to_FSRef(s):
        return FSRef(rawdata=array('B', s[0]).tostring())
    BRIDGED_STRUCTURES['{FSRef=[80C]}'] = struct_to_FSRef

    def FSRef_to_struct(fsRef):
        return (tuple(array('B').fromstring(fsRef.data)),)
    BRIDGED_TYPES.append((FSRef, FSRef_to_struct))

def _bridgePythonTypes():
    # python TO Obj-C
    OC_PythonObject = lookUpClass('OC_PythonObject')
    if BRIDGED_TYPES:
        OC_PythonObject.depythonifyTable().extend(BRIDGED_TYPES)
    if BRIDGED_STRUCTURES:
        OC_PythonObject.pythonifyStructTable().update(BRIDGED_STRUCTURES)
    
_bridgePythonTypes()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.