<commit_before>package unfiltered.request

import org.specs._

object ParamsSpec extends Specification with unfiltered.spec.Served {
  import unfiltered.response._
  import unfiltered.request._
  import unfiltered.request.{Path => UFPath}
  
  import dispatch._

  class TestPlan extends unfiltered.Planify({
    case GET(UFPath("/qp", Params(params, _))) => params("foo") match {
      case Seq(foo) => ResponseString("foo is %s" format foo)
      case _ =>  ResponseString("what's foo?")
    }

    case GET(UFPath("/int", Params(params, _))) => 
      Params.Query[String](params) { q => for {
        even <- q("number") is Params.int required("missing")
      } yield ResponseString(even.get.toString) } orElse { error =>
        BadRequest ~> ResponseString(error.mkString(","))
      }

    case GET(UFPath("/even", Params(params, _))) => 
      Params.Query[String](params) { q => for {
        even <- q("number") is (Params.int, "nonnumber") is
          (Some(_).filter(_ % 2 == 0), "odd") required "missing"
        whatever <- q("what") required("bad")
      } yield ResponseString(even.get.toString) } orElse { error =>
        BadRequest ~> ResponseString(error.mkString(","))
      }
    
    case GET(UFPath("/str", Params(params, _))) => 
      Params.Query[Int](params) { q =>
        for {
          str <- (q("param") is Params.int).optional
          req <- q("req") required(400)
        } yield ResponseString(str.get.getOrElse(0).toString)
      } orElse { error =>
        BadRequest ~> Status(error.head) ~> ResponseString("fail")
      }

    case POST(UFPath("/pp", Params(params,_))) => params("foo") match {
      case Seq(foo) => ResponseString("foo is %s" format foo)
      case _ =>  ResponseString("what's foo?")
    }
  })
  <commit_msg>2.7 compat<commit_after>package unfiltered.request

import org.specs._

object ParamsSpec extends Specification with unfiltered.spec.Served {
  import unfiltered.response._
  import unfiltered.request._
  import unfiltered.request.{Path => UFPath}
  
  import dispatch._

  class TestPlan extends unfiltered.Planify({
    case GET(UFPath("/qp", Params(params, _))) => params("foo") match {
      case Seq(foo) => ResponseString("foo is %s" format foo)
      case _ =>  ResponseString("what's foo?")
    }

    case GET(UFPath("/int", Params(params, _))) => 
      Params.Query[String](params) { q => for {
        even <- q("number") is Params.int required("missing")
      } yield ResponseString(even.get.toString) } orElse { error =>
        BadRequest ~> ResponseString(error.mkString(","))
      }

    case GET(UFPath("/even", Params(params, _))) => 
      Params.Query[String](params) { q => for {
        even <- q("number") is (Params.int, "nonnumber") is
          (Some(_).filter(_ % 2 == 0), "odd") required "missing"
        whatever <- q("what") required("bad")
      } yield ResponseString(even.get.toString) } orElse { error =>
        BadRequest ~> ResponseString(error.mkString(","))
      }
    
    case GET(UFPath("/str", Params(params, _))) => 
      Params.Query[Int](params) { q =>
        for {
          str <- (q("param") is Params.int).optional
          req <- q("req") required(400)
        } yield ResponseString(str.get.getOrElse(0).toString)
      } orElse { error =>
        BadRequest ~> Status(error.first) ~> ResponseString("fail")
      }

    case POST(UFPath("/pp", Params(params,_))) => params("foo") match {
      case Seq(foo) => ResponseString("foo is %s" format foo)
      case _ =>  ResponseString("what's foo?")
    }
  })
  
{'fraction_non_alphanumeric': 0.16563205417607224, 'fraction_numerical': 0.0039503386004514675, 'mean_word_length': 2.943270300333704, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2218642', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1091, 'n_words': 235}