X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fharbl.git;a=blobdiff_plain;f=harbl%2Fsrc%2FNetwork%2FDNS%2FRBL%2FSite.hs;h=c9ea26c569a525b1f541d6c0eccb9e5176eb5e56;hp=ef0df315d678a58782f343df2f9d9abe8a58bcef;hb=67a990c746599a0f64cffa8dd92157626fc4654e;hpb=d124148390284252851e2973e60d1fe85380330d diff --git a/harbl/src/Network/DNS/RBL/Site.hs b/harbl/src/Network/DNS/RBL/Site.hs index ef0df31..c9ea26c 100644 --- a/harbl/src/Network/DNS/RBL/Site.hs +++ b/harbl/src/Network/DNS/RBL/Site.hs @@ -18,82 +18,21 @@ import Data.List ( intercalate ) import Test.Tasty ( TestTree, testGroup ) import Test.Tasty.HUnit ( (@?=), testCase ) import Text.Parsec ( - (<|>), char, choice, - digit, many1, - option, optionMaybe, parse, sepBy1, - space, - try, - unexpected ) + space ) import Text.Parsec.String ( Parser ) -import Text.Read ( readMaybe ) import Network.DNS.RBL.Host ( Host, host ) import Network.DNS.RBL.IPv4Pattern ( IPv4Pattern, v4pattern ) +import Network.DNS.RBL.Weight ( Weight, weight ) import Network.DNS.RBL.Pretty ( Pretty(..) ) -newtype Weight = Weight Int deriving (Eq, Show) - -instance Pretty Weight where - pretty_show (Weight w) = show w - - --- | Parse the weight multiplier at the end of a site. --- --- ==== _Examples_ --- --- >>> import Text.Parsec ( parseTest ) --- --- Negative, zero, and positive integers are all supported: --- --- >>> parseTest weight "*-5" --- Weight (-5) --- --- >>> parseTest weight "*0" --- Weight 0 --- --- >>> parseTest weight "*17" --- Weight 17 --- --- If the weight is empty, it defaults to @1@: --- --- >>> parseTest weight "" --- Weight 1 --- --- The default is used whenever parsing fails: --- --- >>> parseTest weight "*hello" --- Weight 1 --- --- The 'Pretty' instance works as intended: --- --- >>> import Text.Parsec ( parse ) --- >>> pretty_print $ parse weight "" "*3" --- 3 --- -weight :: Parser Weight -weight = try parse_weight <|> return (Weight 1) - where - parse_weight = do - _ <- char '*' - sign <- (char '-') <|> (option '+' (char '+')) - w <- many1 digit - case ( readMaybe w :: Maybe Int ) of - -- If "many1 digit" gives us a list of digits, we should be able - -- to convert that to an Int! It will overflow rather than fail - -- if the input is too big/small, so it should really always - -- succeed. - Nothing -> unexpected "weight: readMaybe failed on a sequence of digits!" - Just k -> return $ Weight (if sign == '-' then negate k else k) - - - -- | A DNSBL as it would be input into postfix. It has a blacklist -- (DNS) name, a pattern of addresses to use for a \"hit\", and a -- weight multiplier.