<commit_before>import Network.HTTP.Server
import Network.HTTP.Server.Logger
import Network.HTTP.Server.HtmlForm as Form
import Network.URL as URL
import Text.JSON
import Text.JSON.String(runGetJSON)
import Text.XHtml
import Codec.Binary.UTF8.String
import Control.Exception(try,SomeException)
import System.FilePath
import Data.List(isPrefixOf)

main :: IO ()
main = serverWith defaultConfig { srvLog = stdLogger, srvPort = 8888 }
     $ \_ url request ->

  case rqMethod request of

    GET ->
      do let ext = takeExtension (url_path url)
         mb_txt <- try (readFile (url_path url))
         case mb_txt of
           Right a -> return $ if ext == ".html"
                                  then sendHTML OK (primHtml a)
                                  else sendScript OK a
           Left e -> return $ sendHTML NotFound $
               thehtml $ concatHtml
                 [ thead noHtml
                 , body $ concatHtml
                    [ toHtml "I could not find"
                    , toHtml (url_path url)
                    , toHtml ", so I made this with xhtml combinators. "
                    , toHtml $ hotlink "example.html" (toHtml "Try this.")
                    ]
                 ]

                 where _hack :: SomeException
                       _hack = e   -- to specify the type
<commit_msg>Improved example/SimpleWeb.hs.<commit_after>import Network.HTTP.Server
import Network.HTTP.Server.Logger
import Network.HTTP.Server.HtmlForm as Form
import Network.URL as URL
import Text.JSON
import Text.JSON.String(runGetJSON)
import Text.XHtml
import Codec.Binary.UTF8.String
import Control.Exception(try,SomeException)
import System.FilePath
import Data.List(isPrefixOf)

main :: IO ()
main = serverWith defaultConfig { srvLog = stdLogger, srvPort = 8888 }
     $ \_ url request ->

  case rqMethod request of

    GET ->
      do let ext = takeExtension (url_path url)
         mb_txt <- try (readFile (url_path url))
         case mb_txt of
           Right a -> return $ if ext == ".html"
                                  then sendHTML OK (primHtml a)
                                  else sendScript OK a
           Left e -> return $ sendHTML NotFound $
               thehtml $ concatHtml
                 [ thead noHtml
                 , body $ concatHtml
                    [ toHtml "I could not find "
                    , toHtml $ "\"" ++ (if null (url_path url) then "/" else url_path url) ++ "\""
                    , toHtml ", so I made this with XHTML combinators. "
                    , toHtml $ hotlink "example.html" (toHtml "Try this instead.")
                    ]
                 ]

                 where _hack :: SomeException
                       _hack = e   -- to specify the type

{'fraction_non_alphanumeric': 0.08015959376133479, 'fraction_numerical': 0.003627130939426913, 'mean_word_length': 1.6166982922201139, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3352469', 'n_tokens_mistral': 747, 'n_tokens_neox': 713, 'n_words': 234}