Commit f5319a2c authored by Andrew Gibiansky's avatar Andrew Gibiansky

Switching to aeson >= 0.6 && < 0.8, as per @aavgt's PR

parent c2437394
...@@ -27,7 +27,7 @@ library ...@@ -27,7 +27,7 @@ library
hs-source-dirs: src hs-source-dirs: src
default-language: Haskell2010 default-language: Haskell2010
build-depends: base >=4.6 && <4.7, build-depends: base >=4.6 && <4.7,
aeson >=0.7, aeson >=0.6 && <0.8,
bytestring >=0.10, bytestring >=0.10,
cereal >=0.3, cereal >=0.3,
containers >=0.5, containers >=0.5,
......
...@@ -11,9 +11,9 @@ import Control.Applicative ((<|>)) ...@@ -11,9 +11,9 @@ import Control.Applicative ((<|>))
import Data.Aeson.Types (parse) import Data.Aeson.Types (parse)
import Data.ByteString import Data.ByteString
import Data.Map (Map) import Data.Map (Map)
import Data.Text (Text)
import qualified Data.ByteString.Lazy as Lazy import qualified Data.ByteString.Lazy as Lazy
import qualified Data.ByteString.Char8 as Char
import qualified Data.Map as Map
import IPython.Types import IPython.Types
...@@ -45,10 +45,10 @@ parseHeader :: [ByteString] -- ^ The list of identifiers. ...@@ -45,10 +45,10 @@ parseHeader :: [ByteString] -- ^ The list of identifiers.
parseHeader idents headerData parentHeader metadata = MessageHeader { parseHeader idents headerData parentHeader metadata = MessageHeader {
identifiers = idents, identifiers = idents,
parentHeader = parentResult, parentHeader = parentResult,
metadata = Map.map Char.pack $ Map.mapKeys Char.pack metadataMap, metadata = metadataMap,
messageId = messageUUID, messageId = messageUUID,
sessionId = sessionUUID, sessionId = sessionUUID,
username = Char.pack username, username = username,
msgType = messageType msgType = messageType
} where } where
-- Decode the header data and the parent header data into JSON objects. -- Decode the header data and the parent header data into JSON objects.
...@@ -67,7 +67,7 @@ parseHeader idents headerData parentHeader metadata = MessageHeader { ...@@ -67,7 +67,7 @@ parseHeader idents headerData parentHeader metadata = MessageHeader {
return (messType, username, message, session) return (messType, username, message, session)
-- Get metadata as a simple map. -- Get metadata as a simple map.
Just metadataMap = decode $ Lazy.fromStrict metadata :: Maybe (Map String String) Just metadataMap = decode $ Lazy.fromStrict metadata :: Maybe (Map Text Text)
noHeader :: MessageHeader noHeader :: MessageHeader
noHeader = error "No header created" noHeader = error "No header created"
...@@ -108,7 +108,7 @@ executeRequestParser content = ...@@ -108,7 +108,7 @@ executeRequestParser content =
Success (code, silent, storeHistory, allowStdin) = parse parser decoded in Success (code, silent, storeHistory, allowStdin) = parse parser decoded in
ExecuteRequest { ExecuteRequest {
header = noHeader, header = noHeader,
getCode = Char.pack code, getCode = code,
getSilent = silent, getSilent = silent,
getAllowStdin = allowStdin, getAllowStdin = allowStdin,
getStoreHistory = storeHistory, getStoreHistory = storeHistory,
...@@ -123,7 +123,7 @@ completeRequestParser content = parsed ...@@ -123,7 +123,7 @@ completeRequestParser content = parsed
code <- obj .: "block" <|> return "" code <- obj .: "block" <|> return ""
codeLine <- obj .: "line" codeLine <- obj .: "line"
pos <- obj .: "cursor_pos" pos <- obj .: "cursor_pos"
return $ CompleteRequest noHeader (Char.pack code) (Char.pack codeLine) pos return $ CompleteRequest noHeader code codeLine pos
Just decoded = decode content Just decoded = decode content
......
...@@ -11,8 +11,9 @@ import Data.Map (Map) ...@@ -11,8 +11,9 @@ import Data.Map (Map)
import Data.Text (Text, pack) import Data.Text (Text, pack)
import Data.Monoid (mempty) import Data.Monoid (mempty)
import qualified Data.ByteString.Char8 as Char import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString as B
import Data.Text.Encoding
import IPython.Types import IPython.Types
...@@ -103,7 +104,8 @@ instance ToJSON StreamType where ...@@ -103,7 +104,8 @@ instance ToJSON StreamType where
-- | Convert a MIME type and value into a JSON dictionary pair. -- | Convert a MIME type and value into a JSON dictionary pair.
displayDataToJson :: DisplayData -> (Text, Value) displayDataToJson :: DisplayData -> (Text, Value)
displayDataToJson (DisplayData mimeType dataStr) = pack (show mimeType) .= Char.unpack dataStr displayDataToJson (DisplayData mimeType dataStr) =
pack (show mimeType) .= String dataStr
----- Constants ----- ----- Constants -----
......
...@@ -30,8 +30,9 @@ module IPython.Types ( ...@@ -30,8 +30,9 @@ module IPython.Types (
import Data.Aeson import Data.Aeson
import Control.Applicative ((<$>), (<*>)) import Control.Applicative ((<$>), (<*>))
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as Char
import qualified Data.Text as Text import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Data.Text (Text)
import Data.Serialize import Data.Serialize
import IPython.Message.UUID import IPython.Message.UUID
import GHC.Generics (Generic) import GHC.Generics (Generic)
...@@ -60,7 +61,7 @@ data Profile = Profile { ...@@ -60,7 +61,7 @@ data Profile = Profile {
hbPort :: Port, -- ^ The heartbeat channel port. hbPort :: Port, -- ^ The heartbeat channel port.
shellPort :: Port, -- ^ The shell command port. shellPort :: Port, -- ^ The shell command port.
iopubPort :: Port, -- ^ The IOPub port. iopubPort :: Port, -- ^ The IOPub port.
key :: ByteString -- ^ The HMAC encryption key. key :: Text -- ^ The HMAC encryption key.
} deriving (Show, Read) } deriving (Show, Read)
-- Convert the kernel profile to and from JSON. -- Convert the kernel profile to and from JSON.
...@@ -73,7 +74,7 @@ instance FromJSON Profile where ...@@ -73,7 +74,7 @@ instance FromJSON Profile where
<*> v .: "hb_port" <*> v .: "hb_port"
<*> v .: "shell_port" <*> v .: "shell_port"
<*> v .: "iopub_port" <*> v .: "iopub_port"
<*> (Char.pack <$> v .: "key") <*> v .: "key"
parseJSON _ = fail "Expecting JSON object." parseJSON _ = fail "Expecting JSON object."
instance ToJSON Profile where instance ToJSON Profile where
...@@ -85,15 +86,14 @@ instance ToJSON Profile where ...@@ -85,15 +86,14 @@ instance ToJSON Profile where
"hb_port" .= hbPort profile, "hb_port" .= hbPort profile,
"shell_port" .= shellPort profile, "shell_port" .= shellPort profile,
"iopub_port" .= iopubPort profile, "iopub_port" .= iopubPort profile,
"key" .= Char.unpack (key profile) "key" .= key profile
] ]
instance FromJSON Transport where instance FromJSON Transport where
parseJSON (String str) = do parseJSON (String mech) = do
let mech = Text.unpack str
case mech of case mech of
"tcp" -> return TCP "tcp" -> return TCP
_ -> fail $ "Unknown transport mechanism " ++ mech _ -> fail $ "Unknown transport mechanism " ++ Text.unpack mech
parseJSON _ = fail "Expected JSON string as transport." parseJSON _ = fail "Expected JSON string as transport."
instance ToJSON Transport where instance ToJSON Transport where
...@@ -119,15 +119,15 @@ instance ToJSON MessageHeader where ...@@ -119,15 +119,15 @@ instance ToJSON MessageHeader where
toJSON header = object [ toJSON header = object [
"msg_id" .= messageId header, "msg_id" .= messageId header,
"session" .= sessionId header, "session" .= sessionId header,
"username" .= Char.unpack (username header), "username" .= username header,
"msg_type" .= showMessageType (msgType header) "msg_type" .= showMessageType (msgType header)
] ]
-- | A username for the source of a message. -- | A username for the source of a message.
type Username = ByteString type Username = Text
-- | A metadata dictionary. -- | A metadata dictionary.
type Metadata = Map ByteString ByteString type Metadata = Map Text Text
-- | The type of a message, corresponding to IPython message types. -- | The type of a message, corresponding to IPython message types.
data MessageType = KernelInfoReplyMessage data MessageType = KernelInfoReplyMessage
...@@ -209,13 +209,13 @@ data Message ...@@ -209,13 +209,13 @@ data Message
-- | A request from a frontend to execute some code. -- | A request from a frontend to execute some code.
| ExecuteRequest { | ExecuteRequest {
header :: MessageHeader, header :: MessageHeader,
getCode :: ByteString, -- ^ The code string. getCode :: Text, -- ^ The code string.
getSilent :: Bool, -- ^ Whether this should be silently executed. getSilent :: Bool, -- ^ Whether this should be silently executed.
getStoreHistory :: Bool, -- ^ Whether to store this in history. getStoreHistory :: Bool, -- ^ Whether to store this in history.
getAllowStdin :: Bool, -- ^ Whether this code can use stdin. getAllowStdin :: Bool, -- ^ Whether this code can use stdin.
getUserVariables :: [ByteString], -- ^ Unused. getUserVariables :: [Text], -- ^ Unused.
getUserExpressions :: [ByteString] -- ^ Unused. getUserExpressions :: [Text] -- ^ Unused.
} }
-- | A reply to an execute request. -- | A reply to an execute request.
...@@ -257,27 +257,27 @@ data Message ...@@ -257,27 +257,27 @@ data Message
| CompleteRequest { | CompleteRequest {
header :: MessageHeader, header :: MessageHeader,
getCode :: ByteString, {- ^ getCode :: Text, {- ^
The entire block of text where the line is. This may be useful in the The entire block of text where the line is. This may be useful in the
case of multiline completions where more context may be needed. Note: if case of multiline completions where more context may be needed. Note: if
in practice this field proves unnecessary, remove it to lighten the in practice this field proves unnecessary, remove it to lighten the
messages. json field @block@ -} messages. json field @block@ -}
getCodeLine :: ByteString, -- ^ just the line with the cursor. json field @line@ getCodeLine :: Text, -- ^ just the line with the cursor. json field @line@
getCursorPos :: Int -- ^ position of the cursor (index into the line?). json field @cursor_pos@ getCursorPos :: Int -- ^ position of the cursor (index into the line?). json field @cursor_pos@
} }
| CompleteReply { | CompleteReply {
header :: MessageHeader, header :: MessageHeader,
completionMatches :: [String], completionMatches :: [Text],
completionMatchedText :: String, completionMatchedText :: Text,
completionText :: String, completionText :: Text,
completionStatus :: Bool completionStatus :: Bool
} }
| ObjectInfoRequest { | ObjectInfoRequest {
header :: MessageHeader, header :: MessageHeader,
objectName :: String, -- ^ Name of object being searched for. objectName :: Text, -- ^ Name of object being searched for.
detailLevel :: Int -- ^ Level of detail desired (defaults to 0). detailLevel :: Int -- ^ Level of detail desired (defaults to 0).
-- 0 is equivalent to foo?, 1 is equivalent -- 0 is equivalent to foo?, 1 is equivalent
-- to foo??. -- to foo??.
...@@ -285,10 +285,10 @@ data Message ...@@ -285,10 +285,10 @@ data Message
| ObjectInfoReply { | ObjectInfoReply {
header :: MessageHeader, header :: MessageHeader,
objectName :: String, -- ^ Name of object which was searched for. objectName :: Text, -- ^ Name of object which was searched for.
objectFound :: Bool, -- ^ Whether the object was found. objectFound :: Bool, -- ^ Whether the object was found.
objectTypeString :: String, -- ^ Object type. objectTypeString :: Text, -- ^ Object type.
objectDocString :: String objectDocString :: Text
} }
| ShutdownRequest { | ShutdownRequest {
...@@ -341,7 +341,7 @@ replyType ShutdownRequestMessage = Just ShutdownReplyMessage ...@@ -341,7 +341,7 @@ replyType ShutdownRequestMessage = Just ShutdownReplyMessage
replyType _ = Nothing replyType _ = Nothing
-- | Data for display: a string with associated MIME type. -- | Data for display: a string with associated MIME type.
data DisplayData = DisplayData MimeType ByteString deriving (Typeable, Generic) data DisplayData = DisplayData MimeType Text deriving (Typeable, Generic)
-- We can't print the actual data, otherwise this will be printed every -- We can't print the actual data, otherwise this will be printed every
-- time it gets computed because of the way the evaluator is structured. -- time it gets computed because of the way the evaluator is structured.
...@@ -350,6 +350,9 @@ instance Show DisplayData where ...@@ -350,6 +350,9 @@ instance Show DisplayData where
show _ = "DisplayData" show _ = "DisplayData"
-- Allow DisplayData serialization -- Allow DisplayData serialization
instance Serialize Text where
put str = put (Text.encodeUtf8 str)
get = Text.decodeUtf8 <$> get
instance Serialize DisplayData instance Serialize DisplayData
instance Serialize MimeType instance Serialize MimeType
...@@ -369,7 +372,7 @@ extractPlain :: [DisplayData] -> String ...@@ -369,7 +372,7 @@ extractPlain :: [DisplayData] -> String
extractPlain disps = extractPlain disps =
case find isPlain disps of case find isPlain disps of
Nothing -> "" Nothing -> ""
Just (DisplayData PlainText bytestr) -> Char.unpack bytestr Just (DisplayData PlainText bytestr) -> Text.unpack bytestr
where where
isPlain (DisplayData mime _) = mime == PlainText isPlain (DisplayData mime _) = mime == PlainText
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment