Skip to content

Commit

Permalink
fix deprecated stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
narimiran authored and dom96 committed Apr 26, 2020
1 parent d8a03aa commit 405be2e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions jester.nim
@@ -1,6 +1,6 @@
# Copyright (C) 2015 Dominik Picheta
# MIT License - Look at license.txt for details.
import net, strtabs, re, tables, parseutils, os, strutils, uri,
import net, strtabs, re, tables, os, strutils, uri,
times, mimetypes, asyncnet, asyncdispatch, macros, md5,
logging, httpcore, asyncfile, macrocache, json, options,
strformat
Expand Down Expand Up @@ -400,7 +400,7 @@ proc handleRequest(jes: Jester, httpReq: NativeRequest): Future[void] =
let exc = getCurrentException()
let respDataFut = dispatchError(jes, req, initRouteError(exc))
return handleRequestSlow(jes, req, respDataFut, true)

assert(not result.isNil, "Expected handleRequest to return a valid future.")

proc newSettings*(
Expand Down Expand Up @@ -712,11 +712,11 @@ template uri*(address = "", absolute = true, addScriptName = true): untyped =

proc daysForward*(days: int): DateTime =
## Returns a DateTime object referring to the current time plus ``days``.
return getTime().utc + initInterval(days = days)
return getTime().utc + initTimeInterval(days = days)

template setCookie*(name, value: string, expires="",
sameSite: SameSite=Lax, secure = false,
httpOnly = false, domain = "", path = ""): typed =
httpOnly = false, domain = "", path = "") =
## Creates a cookie which stores ``value`` under ``name``.
##
## The SameSite argument determines the level of CSRF protection that
Expand All @@ -733,7 +733,7 @@ template setCookie*(name, value: string, expires="",

template setCookie*(name, value: string, expires: DateTime,
sameSite: SameSite=Lax, secure = false,
httpOnly = false, domain = "", path = ""): typed =
httpOnly = false, domain = "", path = "") =
## Creates a cookie which stores ``value`` under ``name``.
setCookie(name, value,
format(expires.utc, "ddd',' dd MMM yyyy HH:mm:ss 'GMT'"),
Expand Down Expand Up @@ -799,14 +799,14 @@ proc ctParsePattern(pattern, pathPrefix: string): NimNode {.compiletime.} =
newStrLitNode(node.text),
newIdentNode(if node.optional: "true" else: "false"))

template setDefaultResp*(): typed =
template setDefaultResp*() =
# TODO: bindSym this in the 'routes' macro and put it in each route
bind TCActionNothing, newHttpHeaders
result.action = TCActionNothing
result.code = Http200
result.content = ""

template declareSettings(): typed {.dirty.} =
template declareSettings() {.dirty.} =
when not declaredInScope(settings):
var settings = newSettings()

Expand Down Expand Up @@ -1348,7 +1348,7 @@ proc routesEx(name: string, body: NimNode): NimNode =
# echo toStrLit(result)
# echo treeRepr(result)

macro routes*(body: untyped): typed =
macro routes*(body: untyped) =
result = routesEx("match", body)
let jesIdent = genSym(nskVar, "jes")
let matchIdent = newIdentNode("match")
Expand All @@ -1364,13 +1364,13 @@ macro routes*(body: untyped): typed =
serve(`jesIdent`)
)

macro router*(name: untyped, body: untyped): typed =
macro router*(name: untyped, body: untyped) =
if name.kind != nnkIdent:
error("Need an ident.", name)

routesEx($name.ident, body)
routesEx(strVal(name), body)

macro settings*(body: untyped): typed =
macro settings*(body: untyped) =
#echo(treeRepr(body))
expectKind(body, nnkStmtList)

Expand Down
2 changes: 1 addition & 1 deletion jester/patterns.nim
Expand Up @@ -15,7 +15,7 @@ type
proc parsePattern*(pattern: string): Pattern =
result = @[]
template addNode(result: var Pattern, theT: NodeType, theText: string,
isOptional: bool): typed =
isOptional: bool) =
block:
var newNode: Node
newNode.typ = theT
Expand Down
4 changes: 2 additions & 2 deletions tests/alltest.nim
Expand Up @@ -57,7 +57,7 @@ routes:
redirect(uri(@"url"))

get "/win":
cond random(5) < 3
cond rand(5) < 3
resp "<b>You won!</b>"

get "/win":
Expand Down Expand Up @@ -203,4 +203,4 @@ routes:
resp $request.params

get "/issue157":
resp(Http200, [("Content-Type","text/css")] , "foo")
resp(Http200, [("Content-Type","text/css")] , "foo")

0 comments on commit 405be2e

Please sign in to comment.