13 import Control.Arrow.ArrowList
14 import qualified Data.ByteString.Lazy as Lazy (ByteString)
15 import qualified Data.ByteString.Lazy.Char8 as L8 hiding (ByteString)
17 import Network.HTTP.Lucu
18 import System.IO.Unsafe
21 yesOrNo :: Bool -> String
26 trueOrFalse :: Bool -> String
27 trueOrFalse True = "true"
28 trueOrFalse False = "false"
31 parseYesOrNo :: ArrowChoice a => a String Bool
33 = proc str -> do case str of
34 "yes" -> returnA -< True
35 "no" -> returnA -< False
36 _ -> returnA -< error ("Expected yes or no: " ++ str)
39 maybeA :: (ArrowList a, ArrowChoice a) => a b c -> a b (Maybe c)
43 [] -> returnA -< Nothing
44 (x:_) -> returnA -< Just x
47 deleteIfEmpty :: (ArrowList a, ArrowChoice a) => a String String
49 = proc str -> do case str of
54 chomp :: String -> String
55 chomp = reverse . snd . break (/= '\n') . reverse
58 guessMIMEType :: Lazy.ByteString -> MIMEType
59 guessMIMEType = read . unsafePerformIO . magicString magic . L8.unpack
62 magic = unsafePerformIO
63 $ do m <- magicOpen [MagicMime]