{-# LINE 1 "lib/CPython/Types/Module.chs" #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module CPython.Types.Module
( Module
, moduleType
, new
, getDictionary
, getName
, getFilename
, addObject
, addIntegerConstant
, addTextConstant
, importModule
, reload
) where
import Prelude hiding (toInteger)
import Data.Text (Text)
import CPython.Internal hiding (new)
import CPython.Types.Integer (toInteger)
import CPython.Types.Unicode (toUnicode)
newtype Module = Module (ForeignPtr Module)
instance Object Module where
toObject (Module x) = SomeObject x
fromForeignPtr = Module
instance Concrete Module where
concreteType _ = moduleType
moduleType :: (Type)
moduleType =
unsafePerformIO $
let {res = moduleType'_} in
peekStaticObject res >>= \res' ->
return (res')
{-# LINE 52 "lib/CPython/Types/Module.chs" #-}
new :: (Text) -> IO ((Module))
new a1 =
withText a1 $ \a1' ->
new'_ a1' >>= \res ->
stealObject res >>= \res' ->
return (res')
{-# LINE 59 "lib/CPython/Types/Module.chs" #-}
getDictionary :: (Module) -> IO ((Dictionary))
getDictionary a1 =
withObject a1 $ \a1' ->
getDictionary'_ a1' >>= \res ->
peekObject res >>= \res' ->
return (res')
{-# LINE 67 "lib/CPython/Types/Module.chs" #-}
getName :: Module -> IO Text
getName py =
withObject py $ \py' -> do
raw <- pyModuleGetName py'
exceptionIf $ raw == nullPtr
peekText raw
getFilename :: Module -> IO Text
getFilename py =
withObject py $ \py' -> do
raw <- pyModuleGetFilename py'
exceptionIf $ raw == nullPtr
peekText raw
addObject :: Object value => Module -> Text -> value -> IO ()
addObject py name val =
withObject py $ \py' ->
withText name $ \name' ->
withObject val $ \val' ->
incref val' >>
pyModuleAddObject py' name' val'
>>= checkStatusCode
addIntegerConstant :: Module -> Text -> Integer -> IO ()
addIntegerConstant m name value = toInteger value >>= addObject m name
addTextConstant :: Module -> Text -> Text -> IO ()
addTextConstant m name value = toUnicode value >>= addObject m name
importModule :: Text -> IO Module
importModule name = do
pyName <- toUnicode name
withObject pyName $ \namePtr ->
pyImportImport namePtr
>>= stealObject
reload :: (Module) -> IO ((Module))
reload a1 =
withObject a1 $ \a1' ->
reload'_ a1' >>= \res ->
stealObject res >>= \res' ->
return (res')
{-# LINE 128 "lib/CPython/Types/Module.chs" #-}
foreign import ccall unsafe "CPython/Types/Module.chs.h hscpython_PyModule_Type"
moduleType'_ :: (Ptr ())
foreign import ccall safe "CPython/Types/Module.chs.h PyModule_New"
new'_ :: ((Ptr CChar) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Module.chs.h PyModule_GetDict"
getDictionary'_ :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Module.chs.h PyModule_GetName"
pyModuleGetName :: ((Ptr ()) -> (IO (Ptr CChar)))
foreign import ccall safe "CPython/Types/Module.chs.h PyModule_GetFilename"
pyModuleGetFilename :: ((Ptr ()) -> (IO (Ptr CChar)))
foreign import ccall safe "CPython/Types/Module.chs.h PyModule_AddObject"
pyModuleAddObject :: ((Ptr ()) -> ((Ptr CChar) -> ((Ptr ()) -> (IO CInt))))
foreign import ccall safe "CPython/Types/Module.chs.h PyImport_Import"
pyImportImport :: ((Ptr ()) -> (IO (Ptr ())))
foreign import ccall safe "CPython/Types/Module.chs.h PyImport_ReloadModule"
reload'_ :: ((Ptr ()) -> (IO (Ptr ())))