mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
Merge branch 'devel' into araq-parser-fixes
This commit is contained in:
@@ -66,6 +66,9 @@
|
||||
fields.
|
||||
- ``system.SomeReal`` is now called ``SomeFloat`` for consistency and
|
||||
correctness.
|
||||
- ``algorithm.smartBinarySearch`` and ``algorithm.binarySearch`` is
|
||||
now joined in ``binarySearch``. ``smartbinarySearch`` is now
|
||||
deprecated.
|
||||
|
||||
### Language additions
|
||||
|
||||
|
||||
@@ -265,7 +265,7 @@ proc rdCharLoc(a: TLoc): Rope =
|
||||
|
||||
proc genObjectInit(p: BProc, section: TCProcSection, t: PType, a: TLoc,
|
||||
takeAddr: bool) =
|
||||
if p.module.compileToCpp and t.isException:
|
||||
if p.module.compileToCpp and t.isException and not isDefined("noCppExceptions"):
|
||||
# init vtable in Exception object for polymorphic exceptions
|
||||
includeHeader(p.module, "<new>")
|
||||
linefmt(p, section, "new ($1) $2;$n", rdLoc(a), getTypeDesc(p.module, t))
|
||||
|
||||
@@ -54,6 +54,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||
|
||||
const
|
||||
HelpMessage = "Nim Compiler Version $1 [$2: $3]\n" &
|
||||
"Compiled at $4 $5\n" &
|
||||
"Copyright (c) 2006-" & copyrightYear & " by Andreas Rumpf\n"
|
||||
|
||||
const
|
||||
@@ -68,7 +69,8 @@ const
|
||||
|
||||
proc getCommandLineDesc(): string =
|
||||
result = (HelpMessage % [VersionAsString, platform.OS[platform.hostOS].name,
|
||||
CPU[platform.hostCPU].name]) & Usage
|
||||
CPU[platform.hostCPU].name, CompileDate, CompileTime]) &
|
||||
Usage
|
||||
|
||||
proc helpOnError(pass: TCmdLinePass) =
|
||||
if pass == passCmd1:
|
||||
@@ -79,7 +81,8 @@ proc writeAdvancedUsage(pass: TCmdLinePass) =
|
||||
if pass == passCmd1:
|
||||
msgWriteln(`%`(HelpMessage, [VersionAsString,
|
||||
platform.OS[platform.hostOS].name,
|
||||
CPU[platform.hostCPU].name]) & AdvancedUsage,
|
||||
CPU[platform.hostCPU].name, CompileDate, CompileTime]) &
|
||||
AdvancedUsage,
|
||||
{msgStdout})
|
||||
msgQuit(0)
|
||||
|
||||
@@ -87,7 +90,8 @@ proc writeFullhelp(pass: TCmdLinePass) =
|
||||
if pass == passCmd1:
|
||||
msgWriteln(`%`(HelpMessage, [VersionAsString,
|
||||
platform.OS[platform.hostOS].name,
|
||||
CPU[platform.hostCPU].name]) & Usage & AdvancedUsage,
|
||||
CPU[platform.hostCPU].name, CompileDate, CompileTime]) &
|
||||
Usage & AdvancedUsage,
|
||||
{msgStdout})
|
||||
msgQuit(0)
|
||||
|
||||
@@ -95,7 +99,7 @@ proc writeVersionInfo(pass: TCmdLinePass) =
|
||||
if pass == passCmd1:
|
||||
msgWriteln(`%`(HelpMessage, [VersionAsString,
|
||||
platform.OS[platform.hostOS].name,
|
||||
CPU[platform.hostCPU].name]),
|
||||
CPU[platform.hostCPU].name, CompileDate, CompileTime]),
|
||||
{msgStdout})
|
||||
|
||||
const gitHash = gorge("git log -n 1 --format=%H").strip
|
||||
|
||||
@@ -45,7 +45,6 @@ proc scanPar(p: var TTmplParser, d: int) =
|
||||
let hi = p.x.len - 1
|
||||
while i <= hi:
|
||||
case p.x[i]
|
||||
of '\0': break
|
||||
of '(': inc(p.par)
|
||||
of ')': dec(p.par)
|
||||
of '[': inc(p.bracket)
|
||||
@@ -64,16 +63,22 @@ const
|
||||
|
||||
proc parseLine(p: var TTmplParser) =
|
||||
var j = 0
|
||||
while p.x[j] == ' ': inc(j)
|
||||
let hi = p.x.len - 1
|
||||
|
||||
if hi == 0:
|
||||
return
|
||||
|
||||
while j <= hi and p.x[j] == ' ': inc(j)
|
||||
|
||||
if p.x[0] == p.nimDirective and p.x[1] == '?':
|
||||
newLine(p)
|
||||
elif p.x[j] == p.nimDirective:
|
||||
newLine(p)
|
||||
inc(j)
|
||||
while p.x[j] == ' ': inc(j)
|
||||
while j <= hi and p.x[j] == ' ': inc(j)
|
||||
let d = j
|
||||
var keyw = ""
|
||||
while p.x[j] in PatternChars:
|
||||
while j <= hi and p.x[j] in PatternChars:
|
||||
add(keyw, p.x[j])
|
||||
inc(j)
|
||||
|
||||
@@ -127,10 +132,8 @@ proc parseLine(p: var TTmplParser) =
|
||||
llStreamWrite(p.outp, "(\"")
|
||||
inc(p.emitPar)
|
||||
p.state = psTempl
|
||||
while true:
|
||||
while j <= hi:
|
||||
case p.x[j]
|
||||
of '\0':
|
||||
break
|
||||
of '\x01'..'\x1F', '\x80'..'\xFF':
|
||||
llStreamWrite(p.outp, "\\x")
|
||||
llStreamWrite(p.outp, toHex(ord(p.x[j]), 2))
|
||||
@@ -157,11 +160,8 @@ proc parseLine(p: var TTmplParser) =
|
||||
llStreamWrite(p.outp, '(')
|
||||
inc(j)
|
||||
var curly = 0
|
||||
while true:
|
||||
while j <= hi:
|
||||
case p.x[j]
|
||||
of '\0':
|
||||
localError(p.info, errXExpected, "}")
|
||||
break
|
||||
of '{':
|
||||
inc(j)
|
||||
inc(curly)
|
||||
@@ -174,6 +174,9 @@ proc parseLine(p: var TTmplParser) =
|
||||
else:
|
||||
llStreamWrite(p.outp, p.x[j])
|
||||
inc(j)
|
||||
if curly > 0:
|
||||
localError(p.info, errXExpected, "}")
|
||||
break
|
||||
llStreamWrite(p.outp, ')')
|
||||
llStreamWrite(p.outp, p.conc)
|
||||
llStreamWrite(p.outp, '\"')
|
||||
@@ -182,7 +185,7 @@ proc parseLine(p: var TTmplParser) =
|
||||
llStreamWrite(p.outp, p.conc)
|
||||
llStreamWrite(p.outp, p.toStr)
|
||||
llStreamWrite(p.outp, '(')
|
||||
while p.x[j] in PatternChars:
|
||||
while j <= hi and p.x[j] in PatternChars:
|
||||
llStreamWrite(p.outp, p.x[j])
|
||||
inc(j)
|
||||
llStreamWrite(p.outp, ')')
|
||||
|
||||
@@ -12,7 +12,7 @@ import sockets, strutils, parseutils, times, os, asyncio
|
||||
|
||||
from asyncnet import nil
|
||||
from nativesockets import nil
|
||||
from asyncdispatch import PFuture
|
||||
from asyncdispatch import Future
|
||||
## **Note**: This module is deprecated since version 0.11.3.
|
||||
## You should use the async version of this module
|
||||
## `asyncftpclient <asyncftpclient.html>`_.
|
||||
|
||||
@@ -853,7 +853,6 @@ type
|
||||
DirKind = enum # must be ordered alphabetically!
|
||||
dkNone, dkAuthor, dkAuthors, dkCode, dkCodeBlock, dkContainer, dkContents,
|
||||
dkFigure, dkImage, dkInclude, dkIndex, dkRaw, dkTitle
|
||||
{.deprecated: [TDirKind: DirKind].}
|
||||
|
||||
const
|
||||
DirIds: array[0..12, string] = ["", "author", "authors", "code",
|
||||
@@ -1114,7 +1113,6 @@ proc parseHeadline(p: var RstParser): PRstNode =
|
||||
|
||||
type
|
||||
IntSeq = seq[int]
|
||||
{.deprecated: [TIntSeq: IntSeq].}
|
||||
|
||||
proc tokEnd(p: RstParser): int =
|
||||
result = p.tok[p.idx].col + len(p.tok[p.idx].symbol) - 1
|
||||
@@ -1408,8 +1406,6 @@ type
|
||||
hasArg, hasOptions, argIsFile, argIsWord
|
||||
DirFlags = set[DirFlag]
|
||||
SectionParser = proc (p: var RstParser): PRstNode {.nimcall.}
|
||||
{.deprecated: [TDirFlag: DirFlag, TDirFlags: DirFlags,
|
||||
TSectionParser: SectionParser].}
|
||||
|
||||
proc parseDirective(p: var RstParser, flags: DirFlags): PRstNode =
|
||||
## Parses arguments and options for a directive block.
|
||||
|
||||
@@ -70,8 +70,6 @@ type
|
||||
## the document or the section
|
||||
level*: int ## valid for some node kinds
|
||||
sons*: RstNodeSeq ## the node's sons
|
||||
{.deprecated: [TRstNodeKind: RstNodeKind, TRstNodeSeq: RstNodeSeq,
|
||||
TRstNode: RstNode].}
|
||||
|
||||
proc len*(n: PRstNode): int =
|
||||
result = len(n.sons)
|
||||
@@ -99,7 +97,6 @@ type
|
||||
RenderContext {.pure.} = object
|
||||
indent: int
|
||||
verbatim: int
|
||||
{.deprecated: [TRenderContext: RenderContext].}
|
||||
|
||||
proc renderRstToRst(d: var RenderContext, n: PRstNode,
|
||||
result: var string) {.gcsafe.}
|
||||
|
||||
@@ -13,9 +13,6 @@ type
|
||||
SortOrder* = enum ## sort order
|
||||
Descending, Ascending
|
||||
|
||||
{.deprecated: [TSortOrder: SortOrder].}
|
||||
|
||||
|
||||
proc `*`*(x: int, order: SortOrder): int {.inline.} =
|
||||
## flips `x` if ``order == Descending``;
|
||||
## if ``order == Ascending`` then `x` is returned.
|
||||
@@ -69,21 +66,25 @@ proc reversed*[T](a: openArray[T]): seq[T] =
|
||||
|
||||
proc binarySearch*[T](a: openArray[T], key: T): int =
|
||||
## binary search for `key` in `a`. Returns -1 if not found.
|
||||
var b = len(a)
|
||||
while result < b:
|
||||
var mid = (result + b) div 2
|
||||
if a[mid] < key: result = mid + 1
|
||||
else: b = mid
|
||||
if result >= len(a) or a[result] != key: result = -1
|
||||
if ((a.len - 1) and a.len) == 0 and a.len > 0:
|
||||
# when `a.len` is a power of 2, a faster div can be used.
|
||||
var step = a.len div 2
|
||||
while step > 0:
|
||||
if a[result or step] <= key:
|
||||
result = result or step
|
||||
step = step shr 1
|
||||
if a[result] != key: result = -1
|
||||
else:
|
||||
var b = len(a)
|
||||
while result < b:
|
||||
var mid = (result + b) div 2
|
||||
if a[mid] < key: result = mid + 1
|
||||
else: b = mid
|
||||
if result >= len(a) or a[result] != key: result = -1
|
||||
|
||||
proc smartBinarySearch*[T](a: openArray[T], key: T): int =
|
||||
## ``a.len`` must be a power of 2 for this to work.
|
||||
var step = a.len div 2
|
||||
while step > 0:
|
||||
if a[result or step] <= key:
|
||||
result = result or step
|
||||
step = step shr 1
|
||||
if a[result] != key: result = -1
|
||||
proc smartBinarySearch*[T](a: openArray[T], key: T): int {.deprecated.} =
|
||||
## **Deprecated since version 0.18.1**; Use ``binarySearch`` instead.
|
||||
binarySearch(a,key)
|
||||
|
||||
const
|
||||
onlySafeCode = true
|
||||
@@ -363,10 +364,11 @@ when isMainModule:
|
||||
var srt1 = [1,2,3,4,4,4,4,5]
|
||||
var srt2 = ["iello","hello"]
|
||||
var srt3 = [1.0,1.0,1.0]
|
||||
var srt4: seq[int] = @[]
|
||||
var srt4: seq[int]
|
||||
assert srt1.isSorted(cmp) == true
|
||||
assert srt2.isSorted(cmp) == false
|
||||
assert srt3.isSorted(cmp) == true
|
||||
assert srt4.isSorted(cmp) == true
|
||||
var srtseq = newSeq[int]()
|
||||
assert srtseq.isSorted(cmp) == true
|
||||
# Tests for reversed
|
||||
@@ -514,4 +516,24 @@ when isMainModule:
|
||||
|
||||
block fillEmptySeq:
|
||||
var s = newSeq[int]()
|
||||
s.fill(0)
|
||||
s.fill(0)
|
||||
|
||||
block testBinarySearch:
|
||||
var noData: seq[int]
|
||||
doAssert binarySearch(noData, 7) == -1
|
||||
let oneData = @[1]
|
||||
doAssert binarySearch(oneData, 1) == 0
|
||||
doAssert binarySearch(onedata, 7) == -1
|
||||
let someData = @[1,3,4,7]
|
||||
doAssert binarySearch(someData, 1) == 0
|
||||
doAssert binarySearch(somedata, 7) == 3
|
||||
doAssert binarySearch(someData, -1) == -1
|
||||
doAssert binarySearch(someData, 5) == -1
|
||||
doAssert binarySearch(someData, 13) == -1
|
||||
let moreData = @[1,3,5,7,4711]
|
||||
doAssert binarySearch(moreData, -1) == -1
|
||||
doAssert binarySearch(moreData, 1) == 0
|
||||
doAssert binarySearch(moreData, 5) == 2
|
||||
doAssert binarySearch(moreData, 6) == -1
|
||||
doAssert binarySearch(moreData, 4711) == 4
|
||||
doAssert binarySearch(moreData, 4712) == -1
|
||||
|
||||
@@ -27,8 +27,6 @@ type
|
||||
FutureError* = object of Exception
|
||||
cause*: FutureBase
|
||||
|
||||
{.deprecated: [PFutureBase: FutureBase, PFuture: Future].}
|
||||
|
||||
when not defined(release):
|
||||
var currentID = 0
|
||||
|
||||
@@ -177,7 +175,7 @@ proc fail*[T](future: Future[T], error: ref Exception) =
|
||||
if getStackTrace(error) == "": getStackTrace() else: getStackTrace(error)
|
||||
future.callbacks.call()
|
||||
|
||||
proc clearCallbacks(future: FutureBase) =
|
||||
proc clearCallbacks*(future: FutureBase) =
|
||||
future.callbacks.function = nil
|
||||
future.callbacks.next = nil
|
||||
|
||||
|
||||
@@ -60,9 +60,6 @@ type
|
||||
reusePort: bool
|
||||
maxBody: int ## The maximum content-length that will be read for the body.
|
||||
|
||||
{.deprecated: [TRequest: Request, PAsyncHttpServer: AsyncHttpServer,
|
||||
THttpCode: HttpCode, THttpVersion: HttpVersion].}
|
||||
|
||||
proc newAsyncHttpServer*(reuseAddr = true, reusePort = false,
|
||||
maxBody = 8388608): AsyncHttpServer =
|
||||
## Creates a new ``AsyncHttpServer`` instance.
|
||||
|
||||
@@ -134,8 +134,6 @@ type
|
||||
protocol: Protocol
|
||||
AsyncSocket* = ref AsyncSocketDesc
|
||||
|
||||
{.deprecated: [PAsyncSocket: AsyncSocket].}
|
||||
|
||||
proc newAsyncSocket*(fd: AsyncFD, domain: Domain = AF_INET,
|
||||
sockType: SockType = SOCK_STREAM,
|
||||
protocol: Protocol = IPPROTO_TCP, buffered = true): AsyncSocket =
|
||||
|
||||
@@ -64,8 +64,6 @@ type
|
||||
methodPost, ## query uses the POST method
|
||||
methodGet ## query uses the GET method
|
||||
|
||||
{.deprecated: [TRequestMethod: RequestMethod, ECgi: CgiError].}
|
||||
|
||||
proc cgiError*(msg: string) {.noreturn.} =
|
||||
## raises an ECgi exception with message `msg`.
|
||||
var e: ref CgiError
|
||||
|
||||
@@ -14,8 +14,6 @@ import strutils
|
||||
type
|
||||
Color* = distinct int ## a color stored as RGB
|
||||
|
||||
{.deprecated: [TColor: Color].}
|
||||
|
||||
proc `==` *(a, b: Color): bool {.borrow.}
|
||||
## compares two colors.
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@ type
|
||||
Complex* = tuple[re, im: float]
|
||||
## a complex number, consisting of a real and an imaginary part
|
||||
|
||||
{.deprecated: [TComplex: Complex].}
|
||||
|
||||
proc toComplex*(x: SomeInteger): Complex =
|
||||
## Convert some integer ``x`` to a complex number.
|
||||
result.re = x
|
||||
|
||||
@@ -83,9 +83,6 @@ type
|
||||
foreignKey*: bool ## is this a foreign key?
|
||||
DbColumns* = seq[DbColumn]
|
||||
|
||||
{.deprecated: [EDb: DbError, TSqlQuery: SqlQuery, FDb: DbEffect,
|
||||
FReadDb: ReadDbEffect, FWriteDb: WriteDbEffect].}
|
||||
|
||||
template sql*(query: string): SqlQuery =
|
||||
## constructs a SqlQuery from the string `query`. This is supposed to be
|
||||
## used as a raw-string-literal modifier:
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
## Loading a simple C function
|
||||
## ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
##
|
||||
## The following example demonstrates loading a function called 'greet'
|
||||
## The following example demonstrates loading a function called 'greet'
|
||||
## from a library that is determined at runtime based upon a language choice.
|
||||
## If the library fails to load or the function 'greet' is not found,
|
||||
## If the library fails to load or the function 'greet' is not found,
|
||||
## it quits with a failure error code.
|
||||
##
|
||||
## .. code-block::nim
|
||||
@@ -59,8 +59,6 @@ import strutils
|
||||
type
|
||||
LibHandle* = pointer ## a handle to a dynamically loaded library
|
||||
|
||||
{.deprecated: [TLibHandle: LibHandle].}
|
||||
|
||||
proc loadLib*(path: string, global_symbols=false): LibHandle {.gcsafe.}
|
||||
## loads a library from `path`. Returns nil if the library could not
|
||||
## be loaded.
|
||||
|
||||
@@ -27,8 +27,6 @@ type
|
||||
EncodingError* = object of ValueError ## exception that is raised
|
||||
## for encoding errors
|
||||
|
||||
{.deprecated: [EInvalidEncoding: EncodingError, PConverter: EncodingConverter].}
|
||||
|
||||
when defined(windows):
|
||||
proc eqEncodingNames(a, b: string): bool =
|
||||
var i = 0
|
||||
|
||||
@@ -43,9 +43,6 @@ type
|
||||
s: seq[EventHandler]
|
||||
EventError* = object of ValueError
|
||||
|
||||
{.deprecated: [TEventArgs: EventArgs, TEventHandler: EventHandler,
|
||||
TEventEmitter: EventEmitter, EInvalidEvent: EventError].}
|
||||
|
||||
proc initEventHandler*(name: string): EventHandler =
|
||||
## Initializes an EventHandler with the specified name and returns it.
|
||||
result.handlers = @[]
|
||||
|
||||
@@ -45,7 +45,6 @@ type
|
||||
Hash* = int ## a hash value; hash tables using these values should
|
||||
## always have a size of a power of two and can use the ``and``
|
||||
## operator instead of ``mod`` for truncation of the hash value.
|
||||
{.deprecated: [THash: Hash].}
|
||||
|
||||
proc `!&`*(h: Hash, val: int): Hash {.inline.} =
|
||||
## mixes a hash value `h` with `val` to produce a new hash value. This is
|
||||
|
||||
@@ -178,7 +178,6 @@ type
|
||||
tagVar, ## the HTML ``var`` element
|
||||
tagVideo, ## the HTML ``video`` element
|
||||
tagWbr ## the HTML ``wbr`` element
|
||||
{.deprecated: [THtmlTag: HtmlTag].}
|
||||
|
||||
const
|
||||
tagToStr* = [
|
||||
|
||||
@@ -219,10 +219,6 @@ type
|
||||
## and ``postContent`` proc,
|
||||
## when the server returns an error
|
||||
|
||||
{.deprecated: [TResponse: Response, PProxy: Proxy,
|
||||
EInvalidProtocol: ProtocolError, EHttpRequestErr: HttpRequestError
|
||||
].}
|
||||
|
||||
const defUserAgent* = "Nim httpclient/" & NimVersion
|
||||
|
||||
proc httpError(msg: string) =
|
||||
@@ -362,8 +358,6 @@ proc parseResponse(s: Socket, getBody: bool, timeout: int): Response =
|
||||
else:
|
||||
result.body = ""
|
||||
|
||||
{.deprecated: [THttpMethod: HttpMethod].}
|
||||
|
||||
when not defined(ssl):
|
||||
type SSLContext = ref object
|
||||
var defaultSSLContext {.threadvar.}: SSLContext
|
||||
@@ -585,7 +579,7 @@ proc request*(url: string, httpMethod: string, extraHeaders = "",
|
||||
|
||||
result = parseResponse(s, httpMethod != "HEAD", timeout)
|
||||
|
||||
proc request*(url: string, httpMethod = httpGET, extraHeaders = "",
|
||||
proc request*(url: string, httpMethod = HttpGET, extraHeaders = "",
|
||||
body = "", sslContext = defaultSSLContext, timeout = -1,
|
||||
userAgent = defUserAgent, proxy: Proxy = nil): Response
|
||||
{.deprecated.} =
|
||||
@@ -627,13 +621,13 @@ proc get*(url: string, extraHeaders = "", maxRedirects = 5,
|
||||
## server takes longer than specified an ETimeout exception will be raised.
|
||||
##
|
||||
## **Deprecated since version 0.15.0**: use ``HttpClient.get`` instead.
|
||||
result = request(url, httpGET, extraHeaders, "", sslContext, timeout,
|
||||
result = request(url, HttpGET, extraHeaders, "", sslContext, timeout,
|
||||
userAgent, proxy)
|
||||
var lastURL = url
|
||||
for i in 1..maxRedirects:
|
||||
if result.status.redirection():
|
||||
let redirectTo = getNewLocation(lastURL, result.headers)
|
||||
result = request(redirectTo, httpGET, extraHeaders, "", sslContext,
|
||||
result = request(redirectTo, HttpGET, extraHeaders, "", sslContext,
|
||||
timeout, userAgent, proxy)
|
||||
lastURL = redirectTo
|
||||
|
||||
@@ -687,13 +681,13 @@ proc post*(url: string, extraHeaders = "", body = "",
|
||||
if not multipart.isNil:
|
||||
xh.add(withNewLine("Content-Type: " & mpContentType))
|
||||
|
||||
result = request(url, httpPOST, xh, xb, sslContext, timeout, userAgent,
|
||||
result = request(url, HttpPOST, xh, xb, sslContext, timeout, userAgent,
|
||||
proxy)
|
||||
var lastURL = url
|
||||
for i in 1..maxRedirects:
|
||||
if result.status.redirection():
|
||||
let redirectTo = getNewLocation(lastURL, result.headers)
|
||||
var meth = if result.status != "307": httpGet else: httpPost
|
||||
var meth = if result.status != "307": HttpGet else: HttpPost
|
||||
result = request(redirectTo, meth, xh, xb, sslContext, timeout,
|
||||
userAgent, proxy)
|
||||
lastURL = redirectTo
|
||||
@@ -749,7 +743,7 @@ proc generateHeaders(requestUrl: Uri, httpMethod: string,
|
||||
|
||||
if proxy.isNil or requestUrl.scheme == "https":
|
||||
# /path?query
|
||||
if requestUrl.path[0] != '/': result.add '/'
|
||||
if not requestUrl.path.startsWith("/"): result.add '/'
|
||||
result.add(requestUrl.path)
|
||||
if requestUrl.query.len > 0:
|
||||
result.add("?" & requestUrl.query)
|
||||
|
||||
@@ -45,10 +45,6 @@ type
|
||||
## TCP/IP tunnel, usually used for proxies.
|
||||
HttpPatch ## Applies partial modifications to a resource.
|
||||
|
||||
{.deprecated: [httpGet: HttpGet, httpHead: HttpHead, httpPost: HttpPost,
|
||||
httpPut: HttpPut, httpDelete: HttpDelete, httpTrace: HttpTrace,
|
||||
httpOptions: HttpOptions, httpConnect: HttpConnect].}
|
||||
|
||||
|
||||
const
|
||||
Http100* = HttpCode(100)
|
||||
|
||||
@@ -110,7 +110,6 @@ when false:
|
||||
# TODO: Fix this, or get rid of it.
|
||||
type
|
||||
RequestMethod = enum reqGet, reqPost
|
||||
{.deprecated: [TRequestMethod: RequestMethod].}
|
||||
|
||||
proc executeCgi(client: Socket, path, query: string, meth: RequestMethod) =
|
||||
var env = newStringTable(modeCaseInsensitive)
|
||||
@@ -225,7 +224,6 @@ type
|
||||
PAsyncHTTPServer* = ref AsyncHTTPServer
|
||||
AsyncHTTPServer = object of Server
|
||||
asyncSocket: AsyncSocket
|
||||
{.deprecated: [TAsyncHTTPServer: AsyncHTTPServer, TServer: Server].}
|
||||
|
||||
proc open*(s: var Server, port = Port(80), reuseAddr = false) =
|
||||
## creates a new server at port `port`. If ``port == 0`` a free port is
|
||||
|
||||
@@ -18,13 +18,13 @@ proc createAsyncNativeSocket*(domain: Domain = Domain.AF_INET,
|
||||
createAsyncNativeSocketImpl(domain, sockType, protocol)
|
||||
|
||||
proc newAsyncNativeSocket*(domain: cint, sockType: cint,
|
||||
protocol: cint): AsyncFD {.deprecated.} =
|
||||
protocol: cint): AsyncFD {.deprecated: "use createAsyncNativeSocket instead".} =
|
||||
createAsyncNativeSocketImpl(domain, sockType, protocol)
|
||||
|
||||
proc newAsyncNativeSocket*(domain: Domain = Domain.AF_INET,
|
||||
sockType: SockType = SOCK_STREAM,
|
||||
protocol: Protocol = IPPROTO_TCP): AsyncFD
|
||||
{.deprecated.} =
|
||||
{.deprecated: "use createAsyncNativeSocket instead".} =
|
||||
createAsyncNativeSocketImpl(domain, sockType, protocol)
|
||||
|
||||
when defined(windows) or defined(nimdoc):
|
||||
|
||||
@@ -12,50 +12,6 @@ when not defined(nimscript):
|
||||
when defined(windows):
|
||||
import winlean
|
||||
|
||||
proc osErrorMsg*(): string {.rtl, extern: "nos$1", deprecated.} =
|
||||
## Retrieves the operating system's error flag, ``errno``.
|
||||
## On Windows ``GetLastError`` is checked before ``errno``.
|
||||
## Returns "" if no error occurred.
|
||||
##
|
||||
## **Deprecated since version 0.9.4**: use the other ``osErrorMsg`` proc.
|
||||
|
||||
result = ""
|
||||
when defined(Windows) and not defined(nimscript):
|
||||
var err = getLastError()
|
||||
if err != 0'i32:
|
||||
when useWinUnicode:
|
||||
var msgbuf: WideCString
|
||||
if formatMessageW(0x00000100 or 0x00001000 or 0x00000200 or 0x000000FF,
|
||||
nil, err, 0, addr(msgbuf), 0, nil) != 0'i32:
|
||||
result = $msgbuf
|
||||
if msgbuf != nil: localFree(cast[pointer](msgbuf))
|
||||
else:
|
||||
var msgbuf: cstring
|
||||
if formatMessageA(0x00000100 or 0x00001000 or 0x00000200 or 0x000000FF,
|
||||
nil, err, 0, addr(msgbuf), 0, nil) != 0'i32:
|
||||
result = $msgbuf
|
||||
if msgbuf != nil: localFree(msgbuf)
|
||||
when not defined(nimscript):
|
||||
if errno != 0'i32:
|
||||
result = $c_strerror(errno)
|
||||
|
||||
{.push warning[deprecated]: off.}
|
||||
proc raiseOSError*(msg: string = "") {.noinline, rtl, extern: "nos$1",
|
||||
deprecated.} =
|
||||
## raises an OSError exception with the given message ``msg``.
|
||||
## If ``msg == ""``, the operating system's error flag
|
||||
## (``errno``) is converted to a readable error message. On Windows
|
||||
## ``GetLastError`` is checked before ``errno``.
|
||||
## If no error flag is set, the message ``unknown OS error`` is used.
|
||||
##
|
||||
## **Deprecated since version 0.9.4**: use the other ``raiseOSError`` proc.
|
||||
if len(msg) == 0:
|
||||
var m = osErrorMsg()
|
||||
raise newException(OSError, if m.len > 0: m else: "unknown OS error")
|
||||
else:
|
||||
raise newException(OSError, msg)
|
||||
{.pop.}
|
||||
|
||||
proc `==`*(err1, err2: OSErrorCode): bool {.borrow.}
|
||||
proc `$`*(err: OSErrorCode): string {.borrow.}
|
||||
|
||||
|
||||
@@ -158,9 +158,6 @@ type
|
||||
JsonKindError* = object of ValueError ## raised by the ``to`` macro if the
|
||||
## JSON kind is incorrect.
|
||||
|
||||
{.deprecated: [TJsonEventKind: JsonEventKind, TJsonError: JsonError,
|
||||
TJsonParser: JsonParser, TTokKind: TokKind].}
|
||||
|
||||
const
|
||||
errorMessages: array[JsonError, string] = [
|
||||
"no error",
|
||||
@@ -622,9 +619,6 @@ type
|
||||
|
||||
JsonParsingError* = object of ValueError ## is raised for a JSON error
|
||||
|
||||
{.deprecated: [EJsonParsingError: JsonParsingError, TJsonNode: JsonNodeObj,
|
||||
PJsonNode: JsonNode, TJsonNodeKind: JsonNodeKind].}
|
||||
|
||||
proc raiseParseErr*(p: JsonParser, msg: string) {.noinline, noreturn.} =
|
||||
## raises an `EJsonParsingError` exception.
|
||||
raise newException(JsonParsingError, errorMsgExpected(p, msg))
|
||||
@@ -695,7 +689,7 @@ proc getBiggestInt*(n: JsonNode, default: BiggestInt = 0): BiggestInt =
|
||||
if n.isNil or n.kind != JInt: return default
|
||||
else: return n.num
|
||||
|
||||
proc getNum*(n: JsonNode, default: BiggestInt = 0): BiggestInt {.deprecated.} =
|
||||
proc getNum*(n: JsonNode, default: BiggestInt = 0): BiggestInt {.deprecated: "use getInt or getBiggestInt instead".} =
|
||||
## **Deprecated since v0.18.2:** use ``getInt`` or ``getBiggestInt`` instead.
|
||||
getBiggestInt(n, default)
|
||||
|
||||
@@ -709,7 +703,7 @@ proc getFloat*(n: JsonNode, default: float = 0.0): float =
|
||||
of JInt: return float(n.num)
|
||||
else: return default
|
||||
|
||||
proc getFNum*(n: JsonNode, default: float = 0.0): float {.deprecated.} =
|
||||
proc getFNum*(n: JsonNode, default: float = 0.0): float {.deprecated: "use getFloat instead".} =
|
||||
## **Deprecated since v0.18.2:** use ``getFloat`` instead.
|
||||
getFloat(n, default)
|
||||
|
||||
@@ -720,7 +714,7 @@ proc getBool*(n: JsonNode, default: bool = false): bool =
|
||||
if n.isNil or n.kind != JBool: return default
|
||||
else: return n.bval
|
||||
|
||||
proc getBVal*(n: JsonNode, default: bool = false): bool {.deprecated.} =
|
||||
proc getBVal*(n: JsonNode, default: bool = false): bool {.deprecated: "use getBool instead".} =
|
||||
## **Deprecated since v0.18.2:** use ``getBool`` instead.
|
||||
getBool(n, default)
|
||||
|
||||
@@ -946,7 +940,7 @@ proc contains*(node: JsonNode, val: JsonNode): bool =
|
||||
assert(node.kind == JArray)
|
||||
find(node.elems, val) >= 0
|
||||
|
||||
proc existsKey*(node: JsonNode, key: string): bool {.deprecated.} = node.hasKey(key)
|
||||
proc existsKey*(node: JsonNode, key: string): bool {.deprecated: "use hasKey instead".} = node.hasKey(key)
|
||||
## **Deprecated:** use `hasKey` instead.
|
||||
|
||||
proc `[]=`*(obj: JsonNode, key: string, val: JsonNode) {.inline.} =
|
||||
@@ -1277,7 +1271,6 @@ else:
|
||||
from math import `mod`
|
||||
type
|
||||
JSObject = object
|
||||
{.deprecated: [TJSObject: JSObject].}
|
||||
|
||||
proc parseNativeJson(x: cstring): JSObject {.importc: "JSON.parse".}
|
||||
|
||||
|
||||
@@ -40,8 +40,6 @@ type
|
||||
offsetBase*: int # use ``offsetBase + bufpos`` to get the offset
|
||||
refillChars: set[char]
|
||||
|
||||
{.deprecated: [TBaseLexer: BaseLexer].}
|
||||
|
||||
const
|
||||
chrSize = sizeof(char)
|
||||
|
||||
|
||||
@@ -96,10 +96,6 @@ when not defined(js):
|
||||
logFiles: int # how many log files already created, e.g. basename.1, basename.2...
|
||||
bufSize: int # size of output buffer (-1: use system defaults, 0: unbuffered, >0: fixed buffer size)
|
||||
|
||||
{.deprecated: [PFileLogger: FileLogger, PRollingFileLogger: RollingFileLogger].}
|
||||
|
||||
{.deprecated: [TLevel: Level, PLogger: Logger, PConsoleLogger: ConsoleLogger].}
|
||||
|
||||
var
|
||||
level {.threadvar.}: Level ## global log filter
|
||||
handlers {.threadvar.}: seq[Logger] ## handlers with their own log levels
|
||||
|
||||
@@ -309,7 +309,6 @@ when not defined(testing) and isMainModule:
|
||||
Node = object
|
||||
next, prev: PNode
|
||||
data: string
|
||||
{.deprecated: [TNode: Node].}
|
||||
|
||||
proc buildList(): PNode =
|
||||
new(result)
|
||||
|
||||
@@ -29,11 +29,21 @@ proc binom*(n, k: int): int {.noSideEffect.} =
|
||||
for i in countup(2, k):
|
||||
result = (result * (n + 1 - i)) div i
|
||||
|
||||
proc fac*(n: int): int {.noSideEffect.} =
|
||||
proc createFactTable[N: static[int]]: array[N, int] =
|
||||
result[0] = 1
|
||||
for i in 1 ..< N:
|
||||
result[i] = result[i - 1] * i
|
||||
|
||||
proc fac*(n: int): int =
|
||||
## Computes the faculty/factorial function.
|
||||
result = 1
|
||||
for i in countup(2, n):
|
||||
result = result * i
|
||||
const factTable =
|
||||
when sizeof(int) == 4:
|
||||
createFactTable[13]()
|
||||
else:
|
||||
createFactTable[21]()
|
||||
assert(n > 0, $n & " must not be negative.")
|
||||
assert(n < factTable.len, $n & " is too large to look up in the table")
|
||||
factTable[n]
|
||||
|
||||
{.push checks:off, line_dir:off, stack_trace:off.}
|
||||
|
||||
|
||||
@@ -38,8 +38,6 @@ type
|
||||
else:
|
||||
handle: cint
|
||||
|
||||
{.deprecated: [TMemFile: MemFile].}
|
||||
|
||||
proc mapMem*(m: var MemFile, mode: FileMode = fmRead,
|
||||
mappedSize = -1, offset = 0): pointer =
|
||||
## returns a pointer to a mapped portion of MemFile `m`
|
||||
|
||||
@@ -12,8 +12,6 @@ type
|
||||
mt: array[0..623, uint32]
|
||||
index: int
|
||||
|
||||
{.deprecated: [TMersenneTwister: MersenneTwister].}
|
||||
|
||||
proc newMersenneTwister*(seed: uint32): MersenneTwister =
|
||||
result.index = 0
|
||||
result.mt[0] = seed
|
||||
|
||||
@@ -13,8 +13,6 @@ type
|
||||
MimeDB* = object
|
||||
mimes: StringTableRef
|
||||
|
||||
{.deprecated: [TMimeDB: MimeDB].}
|
||||
|
||||
const mimes* = {
|
||||
"ez": "application/andrew-inset",
|
||||
"anx": "application/annodex",
|
||||
|
||||
@@ -85,9 +85,6 @@ type
|
||||
length*: int
|
||||
addrList*: seq[string]
|
||||
|
||||
{.deprecated: [TPort: Port, TDomain: Domain, TType: SockType,
|
||||
TProtocol: Protocol, TServent: Servent, THostent: Hostent].}
|
||||
|
||||
when useWinVersion:
|
||||
let
|
||||
osInvalidSocket* = winlean.INVALID_SOCKET
|
||||
@@ -640,7 +637,7 @@ proc pruneSocketSet(s: var seq[SocketHandle], fd: var TFdSet) =
|
||||
inc(i)
|
||||
setLen(s, L)
|
||||
|
||||
proc select*(readfds: var seq[SocketHandle], timeout = 500): int {.deprecated.} =
|
||||
proc select*(readfds: var seq[SocketHandle], timeout = 500): int {.deprecated: "use selectRead instead".} =
|
||||
## When a socket in ``readfds`` is ready to be read from then a non-zero
|
||||
## value will be returned specifying the count of the sockets which can be
|
||||
## read from. The sockets which can be read from will also be removed
|
||||
|
||||
@@ -110,9 +110,6 @@ when defineSsl:
|
||||
serverGetPskFunc: SslServerGetPskFunc
|
||||
clientGetPskFunc: SslClientGetPskFunc
|
||||
|
||||
{.deprecated: [ESSL: SSLError, TSSLCVerifyMode: SSLCVerifyMode,
|
||||
TSSLProtVersion: SSLProtVersion, PSSLContext: SSLContext,
|
||||
TSSLAcceptResult: SSLAcceptResult].}
|
||||
else:
|
||||
type
|
||||
SslContext* = void # TODO: Workaround #4797.
|
||||
@@ -159,10 +156,6 @@ type
|
||||
Peek,
|
||||
SafeDisconn ## Ensures disconnection exceptions (ECONNRESET, EPIPE etc) are not thrown.
|
||||
|
||||
{.deprecated: [TSocketFlags: SocketFlag, ETimeout: TimeoutError,
|
||||
TReadLineResult: ReadLineResult, TSOBool: SOBool, PSocket: Socket,
|
||||
TSocketImpl: SocketImpl].}
|
||||
|
||||
type
|
||||
IpAddressFamily* {.pure.} = enum ## Describes the type of an IP address
|
||||
IPv6, ## IPv6 address
|
||||
@@ -176,8 +169,6 @@ type
|
||||
of IpAddressFamily.IPv4:
|
||||
address_v4*: array[0..3, uint8] ## Contains the IP address in bytes in
|
||||
## case of IPv4
|
||||
{.deprecated: [TIpAddress: IpAddress].}
|
||||
|
||||
|
||||
proc socketError*(socket: Socket, err: int = -1, async = false,
|
||||
lastError = (-1).OSErrorCode): void {.gcsafe.}
|
||||
@@ -1421,8 +1412,7 @@ proc sendTo*(socket: Socket, address: string, port: Port, data: pointer,
|
||||
##
|
||||
## **Note:** This proc is not available for SSL sockets.
|
||||
assert(not socket.isClosed, "Cannot `sendTo` on a closed socket")
|
||||
var aiList = getAddrInfo(address, port, af)
|
||||
|
||||
var aiList = getAddrInfo(address, port, af, socket.sockType, socket.protocol)
|
||||
# try all possibilities:
|
||||
var success = false
|
||||
var it = aiList
|
||||
@@ -1443,7 +1433,7 @@ proc sendTo*(socket: Socket, address: string, port: Port,
|
||||
## this function will try each IP of that hostname.
|
||||
##
|
||||
## This is the high-level version of the above ``sendTo`` function.
|
||||
result = socket.sendTo(address, port, cstring(data), data.len)
|
||||
result = socket.sendTo(address, port, cstring(data), data.len, socket.domain )
|
||||
|
||||
|
||||
proc isSsl*(socket: Socket): bool =
|
||||
|
||||
@@ -30,7 +30,6 @@ when not declared(system.StackTrace):
|
||||
type StackTrace = object
|
||||
lines: array[0..20, cstring]
|
||||
files: array[0..20, cstring]
|
||||
{.deprecated: [TStackTrace: StackTrace].}
|
||||
proc `[]`*(st: StackTrace, i: int): cstring = st.lines[i]
|
||||
|
||||
# We use a simple hash table of bounded size to keep track of the stack traces:
|
||||
@@ -39,7 +38,6 @@ type
|
||||
total: int
|
||||
st: StackTrace
|
||||
ProfileData = array[0..64*1024-1, ptr ProfileEntry]
|
||||
{.deprecated: [TProfileEntry: ProfileEntry, TProfileData: ProfileData].}
|
||||
|
||||
proc `==`(a, b: StackTrace): bool =
|
||||
for i in 0 .. high(a.lines):
|
||||
|
||||
@@ -23,11 +23,9 @@ type
|
||||
fuzz: int32 ##
|
||||
count: int32 ##
|
||||
|
||||
{.deprecated: [Toid: Oid].}
|
||||
|
||||
proc `==`*(oid1: Oid, oid2: Oid): bool =
|
||||
## Compare two Mongo Object IDs for equality
|
||||
return (oid1.time == oid2.time) and (oid1.fuzz == oid2.fuzz) and (oid1.count == oid2.count)
|
||||
## Compare two Mongo Object IDs for equality
|
||||
return (oid1.time == oid2.time) and (oid1.fuzz == oid2.fuzz) and (oid1.count == oid2.count)
|
||||
|
||||
proc hexbyte*(hex: char): int =
|
||||
case hex
|
||||
|
||||
@@ -431,8 +431,6 @@ type
|
||||
fpOthersWrite, ## write access for others
|
||||
fpOthersRead ## read access for others
|
||||
|
||||
{.deprecated: [TFilePermission: FilePermission].}
|
||||
|
||||
proc getFilePermissions*(filename: string): set[FilePermission] {.
|
||||
rtl, extern: "nos$1", tags: [ReadDirEffect].} =
|
||||
## retrieves file permissions for `filename`. `OSError` is raised in case of
|
||||
@@ -730,8 +728,6 @@ type
|
||||
pcDir, ## path refers to a directory
|
||||
pcLinkToDir ## path refers to a symbolic link to a directory
|
||||
|
||||
{.deprecated: [TPathComponent: PathComponent].}
|
||||
|
||||
|
||||
when defined(posix):
|
||||
proc getSymlinkFileKind(path: string): PathComponent =
|
||||
@@ -1441,18 +1437,6 @@ proc getAppFilename*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} =
|
||||
if result.len == 0:
|
||||
result = getApplHeuristic()
|
||||
|
||||
proc getApplicationFilename*(): string {.rtl, extern: "nos$1", deprecated.} =
|
||||
## Returns the filename of the application's executable.
|
||||
## **Deprecated since version 0.8.12**: use ``getAppFilename``
|
||||
## instead.
|
||||
result = getAppFilename()
|
||||
|
||||
proc getApplicationDir*(): string {.rtl, extern: "nos$1", deprecated.} =
|
||||
## Returns the directory of the application's executable.
|
||||
## **Deprecated since version 0.8.12**: use ``getAppDir``
|
||||
## instead.
|
||||
result = splitFile(getAppFilename()).dir
|
||||
|
||||
proc getAppDir*(): string {.rtl, extern: "nos$1", tags: [ReadIOEffect].} =
|
||||
## Returns the directory of the application's executable.
|
||||
result = splitFile(getAppFilename()).dir
|
||||
|
||||
@@ -29,11 +29,6 @@ type
|
||||
|
||||
OSErrorCode* = distinct int32 ## Specifies an OS Error Code.
|
||||
|
||||
{.deprecated: [FReadEnv: ReadEnvEffect, FWriteEnv: WriteEnvEffect,
|
||||
FReadDir: ReadDirEffect,
|
||||
FWriteDir: WriteDirEffect,
|
||||
TOSErrorCode: OSErrorCode
|
||||
].}
|
||||
const
|
||||
doslikeFileSystem* = defined(windows) or defined(OS2) or defined(DOS)
|
||||
|
||||
|
||||
@@ -61,9 +61,6 @@ type
|
||||
Process* = ref ProcessObj ## represents an operating system process
|
||||
|
||||
|
||||
{.deprecated: [TProcess: ProcessObj, PProcess: Process,
|
||||
TProcessOption: ProcessOption].}
|
||||
|
||||
const poUseShell* {.deprecated.} = poUsePath
|
||||
## Deprecated alias for poUsePath.
|
||||
|
||||
@@ -373,17 +370,15 @@ template streamAccess(p) =
|
||||
when defined(Windows) and not defined(useNimRtl):
|
||||
# We need to implement a handle stream for Windows:
|
||||
type
|
||||
PFileHandleStream = ref FileHandleStream
|
||||
FileHandleStream = object of StreamObj
|
||||
FileHandleStream = ref object of StreamObj
|
||||
handle: Handle
|
||||
atTheEnd: bool
|
||||
{.deprecated: [TFileHandleStream: FileHandleStream].}
|
||||
|
||||
proc hsClose(s: Stream) = discard # nothing to do here
|
||||
proc hsAtEnd(s: Stream): bool = return PFileHandleStream(s).atTheEnd
|
||||
proc hsAtEnd(s: Stream): bool = return FileHandleStream(s).atTheEnd
|
||||
|
||||
proc hsReadData(s: Stream, buffer: pointer, bufLen: int): int =
|
||||
var s = PFileHandleStream(s)
|
||||
var s = FileHandleStream(s)
|
||||
if s.atTheEnd: return 0
|
||||
var br: int32
|
||||
var a = winlean.readFile(s.handle, buffer, bufLen.cint, addr br, nil)
|
||||
@@ -395,13 +390,13 @@ when defined(Windows) and not defined(useNimRtl):
|
||||
result = br
|
||||
|
||||
proc hsWriteData(s: Stream, buffer: pointer, bufLen: int) =
|
||||
var s = PFileHandleStream(s)
|
||||
var s = FileHandleStream(s)
|
||||
var bytesWritten: int32
|
||||
var a = winlean.writeFile(s.handle, buffer, bufLen.cint,
|
||||
addr bytesWritten, nil)
|
||||
if a == 0: raiseOSError(osLastError())
|
||||
|
||||
proc newFileHandleStream(handle: Handle): PFileHandleStream =
|
||||
proc newFileHandleStream(handle: Handle): FileHandleStream =
|
||||
new(result)
|
||||
result.handle = handle
|
||||
result.closeImpl = hsClose
|
||||
@@ -527,7 +522,7 @@ when defined(Windows) and not defined(useNimRtl):
|
||||
if setHandleInformation(he, DWORD(1), DWORD(0)) == 0'i32:
|
||||
raiseOsError(osLastError())
|
||||
if setHandleInformation(hi, DWORD(1), DWORD(0)) == 0'i32:
|
||||
raiseOsError(osLastError())
|
||||
raiseOsError(osLastError())
|
||||
if setHandleInformation(ho, DWORD(1), DWORD(0)) == 0'i32:
|
||||
raiseOsError(osLastError())
|
||||
else:
|
||||
@@ -752,14 +747,14 @@ elif not defined(useNimRtl):
|
||||
copyMem(result[i], addr(x[0]), x.len+1)
|
||||
inc(i)
|
||||
|
||||
type StartProcessData = object
|
||||
sysCommand: string
|
||||
sysArgs: cstringArray
|
||||
sysEnv: cstringArray
|
||||
workingDir: cstring
|
||||
pStdin, pStdout, pStderr, pErrorPipe: array[0..1, cint]
|
||||
options: set[ProcessOption]
|
||||
{.deprecated: [TStartProcessData: StartProcessData].}
|
||||
type
|
||||
StartProcessData = object
|
||||
sysCommand: string
|
||||
sysArgs: cstringArray
|
||||
sysEnv: cstringArray
|
||||
workingDir: cstring
|
||||
pStdin, pStdout, pStderr, pErrorPipe: array[0..1, cint]
|
||||
options: set[ProcessOption]
|
||||
|
||||
const useProcessAuxSpawn = declared(posix_spawn) and not defined(useFork) and
|
||||
not defined(useClone) and not defined(linux)
|
||||
|
||||
@@ -125,9 +125,6 @@ type
|
||||
tok: Token
|
||||
filename: string
|
||||
|
||||
{.deprecated: [TCfgEventKind: CfgEventKind, TCfgEvent: CfgEvent,
|
||||
TTokKind: TokKind, TToken: Token, TCfgParser: CfgParser].}
|
||||
|
||||
# implementation
|
||||
|
||||
const
|
||||
|
||||
@@ -66,8 +66,6 @@ type
|
||||
CsvError* = object of IOError ## exception that is raised if
|
||||
## a parsing error occurs
|
||||
|
||||
{.deprecated: [TCsvRow: CsvRow, TCsvParser: CsvParser, EInvalidCsv: CsvError].}
|
||||
|
||||
proc raiseEInvalidCsv(filename: string, line, col: int,
|
||||
msg: string) {.noreturn.} =
|
||||
var e: ref CsvError
|
||||
|
||||
@@ -54,8 +54,6 @@ type
|
||||
## or the argument, ``value`` is not "" if
|
||||
## the option was given a value
|
||||
|
||||
{.deprecated: [TCmdLineKind: CmdLineKind, TOptParser: OptParser].}
|
||||
|
||||
proc parseWord(s: string, i: int, w: var string,
|
||||
delim: set[char] = {'\x09', ' '}): int =
|
||||
result = i
|
||||
|
||||
@@ -41,8 +41,6 @@ type
|
||||
## or the argument, ``value`` is not "" if
|
||||
## the option was given a value
|
||||
|
||||
{.deprecated: [TCmdLineKind: CmdLineKind, TOptParser: OptParser].}
|
||||
|
||||
proc initOptParser*(cmdline: seq[string]): OptParser {.rtl.} =
|
||||
## Initalizes option parses with cmdline. cmdline should not contain
|
||||
## argument 0 - program name.
|
||||
@@ -122,8 +120,6 @@ proc cmdLineRest*(p: OptParser): TaintedString {.rtl, extern: "npo2$1", deprecat
|
||||
type
|
||||
GetoptResult* = tuple[kind: CmdLineKind, key, val: TaintedString]
|
||||
|
||||
{.deprecated: [TGetoptResult: GetoptResult].}
|
||||
|
||||
iterator getopt*(p: var OptParser): GetoptResult =
|
||||
## This is an convenience iterator for iterating over the given OptParser object.
|
||||
## Example:
|
||||
|
||||
@@ -45,8 +45,6 @@ type
|
||||
SqlLexer* = object of BaseLexer ## the parser object.
|
||||
filename: string
|
||||
|
||||
{.deprecated: [TToken: Token, TSqlLexer: SqlLexer].}
|
||||
|
||||
const
|
||||
tokKindToStr: array[TokKind, string] = [
|
||||
"invalid", "[EOF]", "identifier", "quoted identifier", "string constant",
|
||||
|
||||
@@ -365,8 +365,6 @@ type
|
||||
ikVar, ## ``var`` part of the interpolated string
|
||||
ikExpr ## ``expr`` part of the interpolated string
|
||||
|
||||
{.deprecated: [TInterpolatedKind: InterpolatedKind].}
|
||||
|
||||
iterator interpolatedFragments*(s: string): tuple[kind: InterpolatedKind,
|
||||
value: string] =
|
||||
## Tokenizes the string `s` into substrings for interpolation purposes.
|
||||
|
||||
@@ -98,9 +98,6 @@ type
|
||||
filename: string
|
||||
options: set[XmlParseOption]
|
||||
|
||||
{.deprecated: [TXmlParser: XmlParser, TXmlParseOptions: XmlParseOption,
|
||||
TXmlError: XmlErrorKind, TXmlEventKind: XmlEventKind].}
|
||||
|
||||
const
|
||||
errorMessages: array[XmlErrorKind, string] = [
|
||||
"no error",
|
||||
|
||||
@@ -74,8 +74,8 @@ type
|
||||
line: int ## line the symbol has been declared/used in
|
||||
col: int ## column the symbol has been declared/used in
|
||||
flags: set[NonTerminalFlag] ## the nonterminal's flags
|
||||
rule: Node ## the rule that the symbol refers to
|
||||
Node {.shallow.} = object
|
||||
rule: Peg ## the rule that the symbol refers to
|
||||
Peg* {.shallow.} = object ## type that represents a PEG
|
||||
case kind: PegKind
|
||||
of pkEmpty..pkWhitespace: nil
|
||||
of pkTerminal, pkTerminalIgnoreCase, pkTerminalIgnoreStyle: term: string
|
||||
@@ -83,13 +83,9 @@ type
|
||||
of pkCharChoice, pkGreedyRepSet: charChoice: ref set[char]
|
||||
of pkNonTerminal: nt: NonTerminal
|
||||
of pkBackRef..pkBackRefIgnoreStyle: index: range[0..MaxSubpatterns]
|
||||
else: sons: seq[Node]
|
||||
else: sons: seq[Peg]
|
||||
NonTerminal* = ref NonTerminalObj
|
||||
|
||||
Peg* = Node ## type that represents a PEG
|
||||
|
||||
{.deprecated: [TPeg: Peg, TNode: Node].}
|
||||
|
||||
proc term*(t: string): Peg {.nosideEffect, rtl, extern: "npegs$1Str".} =
|
||||
## constructs a PEG from a terminal string
|
||||
if t.len != 1:
|
||||
|
||||
@@ -37,8 +37,6 @@ type
|
||||
length: int
|
||||
data: string # != nil if a leaf
|
||||
|
||||
{.deprecated: [PRope: Rope].}
|
||||
|
||||
proc isConc(r: Rope): bool {.inline.} = return isNil(r.data)
|
||||
|
||||
# Note that the left and right pointers are not needed for leafs.
|
||||
|
||||
@@ -94,9 +94,6 @@ type
|
||||
disp: Dispatcher
|
||||
AsyncScgiState* = ref AsyncScgiStateObj
|
||||
|
||||
{.deprecated: [EScgi: ScgiError, TScgiState: ScgiState,
|
||||
PAsyncScgiState: AsyncScgiState].}
|
||||
|
||||
proc recvBuffer(s: var ScgiState, L: int) =
|
||||
if L > s.bufLen:
|
||||
s.bufLen = L
|
||||
|
||||
@@ -271,7 +271,7 @@ else:
|
||||
msg.add("Internal Error\n")
|
||||
var err = newException(IOSelectorsException, msg)
|
||||
raise err
|
||||
|
||||
|
||||
proc setNonBlocking(fd: cint) {.inline.} =
|
||||
setBlocking(fd.SocketHandle, false)
|
||||
|
||||
@@ -316,18 +316,18 @@ else:
|
||||
include ioselects/ioselectors_poll
|
||||
|
||||
proc register*[T](s: Selector[T], fd: int | SocketHandle,
|
||||
events: set[Event], data: T) {.deprecated.} =
|
||||
events: set[Event], data: T) {.deprecated: "use registerHandle instead".} =
|
||||
## **Deprecated since v0.18.0:** Use ``registerHandle`` instead.
|
||||
s.registerHandle(fd, events, data)
|
||||
|
||||
proc setEvent*(ev: SelectEvent) {.deprecated.} =
|
||||
proc setEvent*(ev: SelectEvent) {.deprecated: "use trigger instead".} =
|
||||
## Trigger event ``ev``.
|
||||
##
|
||||
## **Deprecated since v0.18.0:** Use ``trigger`` instead.
|
||||
ev.trigger()
|
||||
|
||||
proc update*[T](s: Selector[T], fd: int | SocketHandle,
|
||||
events: set[Event]) {.deprecated.} =
|
||||
events: set[Event]) {.deprecated: "use updateHandle instead".} =
|
||||
## Update file/socket descriptor ``fd``, registered in selector
|
||||
## ``s`` with new events set ``event``.
|
||||
##
|
||||
|
||||
@@ -51,8 +51,6 @@ type
|
||||
Smtp* = SmtpBase[Socket]
|
||||
AsyncSmtp* = SmtpBase[AsyncSocket]
|
||||
|
||||
{.deprecated: [EInvalidReply: ReplyError, TMessage: Message, TSMTP: Smtp].}
|
||||
|
||||
proc debugSend(smtp: Smtp | AsyncSmtp, cmd: string) {.multisync.} =
|
||||
if smtp.debug:
|
||||
echo("C:" & cmd)
|
||||
|
||||
@@ -65,8 +65,6 @@ type
|
||||
y_stats*: RunningStat ## stats for second set of data
|
||||
s_xy: float ## accumulated data for combined xy
|
||||
|
||||
{.deprecated: [TFloatClass: FloatClass, TRunningStat: RunningStat].}
|
||||
|
||||
# ----------- RunningStat --------------------------
|
||||
proc clear*(s: var RunningStat) =
|
||||
## reset `s`
|
||||
|
||||
@@ -57,8 +57,6 @@ type
|
||||
tags: [WriteIOEffect], gcsafe.}
|
||||
flushImpl*: proc (s: Stream) {.nimcall, tags: [WriteIOEffect], gcsafe.}
|
||||
|
||||
{.deprecated: [PStream: Stream, TStream: StreamObj].}
|
||||
|
||||
proc flush*(s: Stream) =
|
||||
## flushes the buffers that the stream `s` might use.
|
||||
if not isNil(s.flushImpl): s.flushImpl(s)
|
||||
@@ -76,27 +74,14 @@ proc atEnd*(s: Stream): bool =
|
||||
## been read.
|
||||
result = s.atEndImpl(s)
|
||||
|
||||
proc atEnd*(s, unused: Stream): bool {.deprecated.} =
|
||||
## checks if more data can be read from `f`. Returns true if all data has
|
||||
## been read.
|
||||
result = s.atEndImpl(s)
|
||||
|
||||
proc setPosition*(s: Stream, pos: int) =
|
||||
## sets the position `pos` of the stream `s`.
|
||||
s.setPositionImpl(s, pos)
|
||||
|
||||
proc setPosition*(s, unused: Stream, pos: int) {.deprecated.} =
|
||||
## sets the position `pos` of the stream `s`.
|
||||
s.setPositionImpl(s, pos)
|
||||
|
||||
proc getPosition*(s: Stream): int =
|
||||
## retrieves the current position in the stream `s`.
|
||||
result = s.getPositionImpl(s)
|
||||
|
||||
proc getPosition*(s, unused: Stream): int {.deprecated.} =
|
||||
## retrieves the current position in the stream `s`.
|
||||
result = s.getPositionImpl(s)
|
||||
|
||||
proc readData*(s: Stream, buffer: pointer, bufLen: int): int =
|
||||
## low level proc that reads data into an untyped `buffer` of `bufLen` size.
|
||||
result = s.readDataImpl(s, buffer, bufLen)
|
||||
@@ -114,11 +99,6 @@ proc readAll*(s: Stream): string =
|
||||
inc r, bufferSize
|
||||
setLen(result, r+bufferSize)
|
||||
|
||||
proc readData*(s, unused: Stream, buffer: pointer,
|
||||
bufLen: int): int {.deprecated.} =
|
||||
## low level proc that reads data into an untyped `buffer` of `bufLen` size.
|
||||
result = s.readDataImpl(s, buffer, bufLen)
|
||||
|
||||
proc peekData*(s: Stream, buffer: pointer, bufLen: int): int =
|
||||
## low level proc that reads data into an untyped `buffer` of `bufLen` size
|
||||
## without moving stream position
|
||||
@@ -153,11 +133,6 @@ proc write*(s: Stream, x: string) =
|
||||
else:
|
||||
if x.len > 0: writeData(s, unsafeAddr x[0], x.len)
|
||||
|
||||
proc writeLn*(s: Stream, args: varargs[string, `$`]) {.deprecated.} =
|
||||
## **Deprecated since version 0.11.4:** Use **writeLine** instead.
|
||||
for str in args: write(s, str)
|
||||
write(s, "\n")
|
||||
|
||||
proc writeLine*(s: Stream, args: varargs[string, `$`]) =
|
||||
## writes one or more strings to the the stream `s` followed
|
||||
## by a new line. No length field or terminating zero is written.
|
||||
@@ -348,8 +323,6 @@ when not defined(js):
|
||||
data*: string
|
||||
pos: int
|
||||
|
||||
{.deprecated: [PStringStream: StringStream, TStringStream: StringStreamObj].}
|
||||
|
||||
proc ssAtEnd(s: Stream): bool =
|
||||
var s = StringStream(s)
|
||||
return s.pos >= s.data.len
|
||||
@@ -409,7 +382,6 @@ when not defined(js):
|
||||
FileStream* = ref FileStreamObj ## a stream that encapsulates a `File`
|
||||
FileStreamObj* = object of Stream
|
||||
f: File
|
||||
{.deprecated: [PFileStream: FileStream, TFileStream: FileStreamObj].}
|
||||
|
||||
proc fsClose(s: Stream) =
|
||||
if FileStream(s).f != nil:
|
||||
@@ -472,9 +444,6 @@ else:
|
||||
handle*: FileHandle
|
||||
pos: int
|
||||
|
||||
{.deprecated: [PFileHandleStream: FileHandleStream,
|
||||
TFileHandleStream: FileHandleStreamObj].}
|
||||
|
||||
proc newEOS(msg: string): ref OSError =
|
||||
new(result)
|
||||
result.msg = msg
|
||||
|
||||
@@ -17,9 +17,7 @@ import
|
||||
|
||||
when defined(js):
|
||||
{.pragma: rtlFunc.}
|
||||
{.pragma: deprecatedGetFunc.}
|
||||
else:
|
||||
{.pragma: deprecatedGetFunc, deprecatedGet.}
|
||||
{.pragma: rtlFunc, rtl.}
|
||||
import os
|
||||
include "system/inclrtl"
|
||||
@@ -38,9 +36,6 @@ type
|
||||
|
||||
StringTableRef* = ref StringTableObj ## use this type to declare string tables
|
||||
|
||||
{.deprecated: [TStringTableMode: StringTableMode,
|
||||
TStringTable: StringTableObj, PStringTable: StringTableRef].}
|
||||
|
||||
proc len*(t: StringTableRef): int {.rtlFunc, extern: "nst$1".} =
|
||||
## returns the number of keys in `t`.
|
||||
result = t.counter
|
||||
@@ -73,10 +68,6 @@ type
|
||||
useKey ## do not replace ``$key`` if it is not found
|
||||
## in the table (or in the environment)
|
||||
|
||||
{.deprecated: [TFormatFlag: FormatFlag].}
|
||||
|
||||
# implementation
|
||||
|
||||
const
|
||||
growthFactor = 2
|
||||
startSize = 64
|
||||
@@ -118,17 +109,12 @@ template get(t: StringTableRef, key: string) =
|
||||
raise newException(KeyError, "key not found")
|
||||
|
||||
proc `[]`*(t: StringTableRef, key: string): var string {.
|
||||
rtlFunc, extern: "nstTake", deprecatedGetFunc.} =
|
||||
rtlFunc, extern: "nstTake".} =
|
||||
## retrieves the location at ``t[key]``. If `key` is not in `t`, the
|
||||
## ``KeyError`` exception is raised. One can check with ``hasKey`` whether
|
||||
## the key exists.
|
||||
get(t, key)
|
||||
|
||||
proc mget*(t: StringTableRef, key: string): var string {.deprecated.} =
|
||||
## retrieves the location at ``t[key]``. If `key` is not in `t`, the
|
||||
## ``KeyError`` exception is raised. Use ```[]``` instead.
|
||||
get(t, key)
|
||||
|
||||
proc getOrDefault*(t: StringTableRef; key: string, default: string = ""): string =
|
||||
var index = rawGet(t, key)
|
||||
if index >= 0: result = t.data[index].val
|
||||
@@ -193,7 +179,8 @@ proc newStringTable*(mode: StringTableMode): StringTableRef {.
|
||||
result.counter = 0
|
||||
newSeq(result.data, startSize)
|
||||
|
||||
proc clear*(s: StringTableRef, mode: StringTableMode) =
|
||||
proc clear*(s: StringTableRef, mode: StringTableMode) {.
|
||||
rtlFunc, extern: "nst$1".} =
|
||||
## resets a string table to be empty again.
|
||||
s.mode = mode
|
||||
s.counter = 0
|
||||
|
||||
@@ -31,8 +31,6 @@ type
|
||||
SubexError* = object of ValueError ## exception that is raised for
|
||||
## an invalid subex
|
||||
|
||||
{.deprecated: [EInvalidSubex: SubexError].}
|
||||
|
||||
proc raiseInvalidFormat(msg: string) {.noinline.} =
|
||||
raise newException(SubexError, "invalid format string: " & msg)
|
||||
|
||||
@@ -44,7 +42,6 @@ type
|
||||
else:
|
||||
f: cstring
|
||||
num, i, lineLen: int
|
||||
{.deprecated: [TFormatParser: FormatParser].}
|
||||
|
||||
template call(x: untyped): untyped =
|
||||
p.i = i
|
||||
|
||||
@@ -1173,12 +1173,16 @@ proc formatToken(dt: DateTime, token: string, buf: var string) =
|
||||
of "dddd":
|
||||
buf.add($dt.weekday)
|
||||
of "h":
|
||||
buf.add($(if dt.hour > 12: dt.hour - 12 else: dt.hour))
|
||||
if dt.hour == 0: buf.add("12")
|
||||
else: buf.add($(if dt.hour > 12: dt.hour - 12 else: dt.hour))
|
||||
of "hh":
|
||||
let amerHour = if dt.hour > 12: dt.hour - 12 else: dt.hour
|
||||
if amerHour < 10:
|
||||
buf.add('0')
|
||||
buf.add($amerHour)
|
||||
if dt.hour == 0:
|
||||
buf.add("12")
|
||||
else:
|
||||
let amerHour = if dt.hour > 12: dt.hour - 12 else: dt.hour
|
||||
if amerHour < 10:
|
||||
buf.add('0')
|
||||
buf.add($amerHour)
|
||||
of "H":
|
||||
buf.add($dt.hour)
|
||||
of "HH":
|
||||
@@ -1503,11 +1507,15 @@ proc parseToken(dt: var DateTime; token, value: string; j: var int) =
|
||||
dt.second = value[j..j+1].parseInt()
|
||||
j += 2
|
||||
of "t":
|
||||
if value[j] == 'P' and dt.hour > 0 and dt.hour < 12:
|
||||
if value[j] == 'A' and dt.hour == 12:
|
||||
dt.hour = 0
|
||||
elif value[j] == 'P' and dt.hour > 0 and dt.hour < 12:
|
||||
dt.hour += 12
|
||||
j += 1
|
||||
of "tt":
|
||||
if value[j..j+1] == "PM" and dt.hour > 0 and dt.hour < 12:
|
||||
if value[j..j+1] == "AM" and dt.hour == 12:
|
||||
dt.hour = 0
|
||||
elif value[j..j+1] == "PM" and dt.hour > 0 and dt.hour < 12:
|
||||
dt.hour += 12
|
||||
j += 2
|
||||
of "yy":
|
||||
|
||||
@@ -18,14 +18,12 @@ type
|
||||
hostname*, port*, path*, query*, anchor*: string
|
||||
opaque*: bool
|
||||
|
||||
{.deprecated: [TUrl: Url, TUri: Uri].}
|
||||
|
||||
{.push warning[deprecated]: off.}
|
||||
proc `$`*(url: Url): string {.deprecated.} =
|
||||
proc `$`*(url: Url): string {.deprecated: "use Uri instead".} =
|
||||
## **Deprecated since 0.9.6**: Use ``Uri`` instead.
|
||||
return string(url)
|
||||
|
||||
proc `/`*(a, b: Url): Url {.deprecated.} =
|
||||
proc `/`*(a, b: Url): Url {.deprecated: "use Uri instead".} =
|
||||
## Joins two URLs together, separating them with / if needed.
|
||||
##
|
||||
## **Deprecated since 0.9.6**: Use ``Uri`` instead.
|
||||
@@ -40,32 +38,43 @@ proc `/`*(a, b: Url): Url {.deprecated.} =
|
||||
urlS.add(bs)
|
||||
result = Url(urlS)
|
||||
|
||||
proc add*(url: var Url, a: Url) {.deprecated.} =
|
||||
proc add*(url: var Url, a: Url) {.deprecated: "use Uri instead".} =
|
||||
## Appends url to url.
|
||||
##
|
||||
## **Deprecated since 0.9.6**: Use ``Uri`` instead.
|
||||
url = url / a
|
||||
{.pop.}
|
||||
|
||||
proc encodeUrl*(s: string): string =
|
||||
## Encodes a value to be HTTP safe: This means that characters in the set
|
||||
## ``{'A'..'Z', 'a'..'z', '0'..'9', '_'}`` are carried over to the result,
|
||||
## a space is converted to ``'+'`` and every other character is encoded as
|
||||
## ``'%xx'`` where ``xx`` denotes its hexadecimal value.
|
||||
proc encodeUrl*(s: string, usePlus=true): string =
|
||||
## Encodes a URL according to RFC3986.
|
||||
##
|
||||
## This means that characters in the set
|
||||
## ``{'a'..'z', 'A'..'Z', '0'..'9', '-', '.', '_', '~'}`` are
|
||||
## carried over to the result.
|
||||
## All other characters are encoded as ``''%xx'`` where ``xx``
|
||||
## denotes its hexadecimal value.
|
||||
##
|
||||
## As a special rule, when the value of ``usePlus`` is true,
|
||||
## spaces are encoded as ``'+'`` instead of ``'%20'``.
|
||||
result = newStringOfCap(s.len + s.len shr 2) # assume 12% non-alnum-chars
|
||||
for i in 0..s.len-1:
|
||||
case s[i]
|
||||
of 'a'..'z', 'A'..'Z', '0'..'9', '_': add(result, s[i])
|
||||
of ' ': add(result, '+')
|
||||
let fromSpace = if usePlus: "+" else: "%20"
|
||||
for c in s:
|
||||
case c
|
||||
of 'a'..'z', 'A'..'Z', '0'..'9', '-', '.', '_', '~': add(result, c)
|
||||
of ' ': add(result, fromSpace)
|
||||
else:
|
||||
add(result, '%')
|
||||
add(result, toHex(ord(s[i]), 2))
|
||||
add(result, toHex(ord(c), 2))
|
||||
|
||||
proc decodeUrl*(s: string): string =
|
||||
## Decodes a value from its HTTP representation: This means that a ``'+'``
|
||||
## is converted to a space, ``'%xx'`` (where ``xx`` denotes a hexadecimal
|
||||
## value) is converted to the character with ordinal number ``xx``, and
|
||||
proc decodeUrl*(s: string, decodePlus=true): string =
|
||||
## Decodes a URL according to RFC3986.
|
||||
##
|
||||
## This means that any ``'%xx'`` (where ``xx`` denotes a hexadecimal
|
||||
## value) are converted to the character with ordinal number ``xx``,
|
||||
## and every other character is carried over.
|
||||
##
|
||||
## As a special rule, when the value of ``decodePlus`` is true, ``'+'``
|
||||
## characters are converted to a space.
|
||||
proc handleHexChar(c: char, x: var int) {.inline.} =
|
||||
case c
|
||||
of '0'..'9': x = (x shl 4) or (ord(c) - ord('0'))
|
||||
@@ -84,7 +93,11 @@ proc decodeUrl*(s: string): string =
|
||||
handleHexChar(s[i+2], x)
|
||||
inc(i, 2)
|
||||
result[j] = chr(x)
|
||||
of '+': result[j] = ' '
|
||||
of '+':
|
||||
if decodePlus:
|
||||
result[j] = ' '
|
||||
else:
|
||||
result[j] = s[i]
|
||||
else: result[j] = s[i]
|
||||
inc(i)
|
||||
inc(j)
|
||||
@@ -370,6 +383,9 @@ when isMainModule:
|
||||
const test1 = "abc\L+def xyz"
|
||||
doAssert encodeUrl(test1) == "abc%0A%2Bdef+xyz"
|
||||
doAssert decodeUrl(encodeUrl(test1)) == test1
|
||||
doAssert encodeUrl(test1, false) == "abc%0A%2Bdef%20xyz"
|
||||
doAssert decodeUrl(encodeUrl(test1, false), false) == test1
|
||||
doAssert decodeUrl(encodeUrl(test1)) == test1
|
||||
|
||||
block:
|
||||
let str = "http://localhost"
|
||||
|
||||
@@ -16,8 +16,6 @@ type
|
||||
## for invalid XML.
|
||||
errors*: seq[string] ## All detected parsing errors.
|
||||
|
||||
{.deprecated: [EInvalidXml: XmlError].}
|
||||
|
||||
proc raiseInvalidXml(errors: seq[string]) =
|
||||
var e: ref XmlError
|
||||
new(e)
|
||||
|
||||
@@ -33,9 +33,6 @@ type
|
||||
fAttr: XmlAttributes
|
||||
fClientData: int ## for other clients
|
||||
|
||||
{.deprecated: [PXmlNode: XmlNode, TXmlNodeKind: XmlNodeKind, PXmlAttributes:
|
||||
XmlAttributes, TXmlNode: XmlNodeObj].}
|
||||
|
||||
proc newXmlNode(kind: XmlNodeKind): XmlNode =
|
||||
## creates a new ``XmlNode``.
|
||||
new(result)
|
||||
@@ -155,11 +152,6 @@ proc `[]`* (n: var XmlNode, i: int): var XmlNode {.inline.} =
|
||||
assert n.k == xnElement
|
||||
result = n.s[i]
|
||||
|
||||
proc mget*(n: var XmlNode, i: int): var XmlNode {.inline, deprecated.} =
|
||||
## returns the `i`'th child of `n` so that it can be modified. Use ```[]```
|
||||
## instead.
|
||||
n[i]
|
||||
|
||||
iterator items*(n: XmlNode): XmlNode {.inline.} =
|
||||
## iterates over any child of `n`.
|
||||
assert n.k == xnElement
|
||||
@@ -319,8 +311,8 @@ proc xmlConstructor(a: NimNode): NimNode {.compileTime.} =
|
||||
if a.kind == nnkCall:
|
||||
result = newCall("newXmlTree", toStrLit(a[0]))
|
||||
var attrs = newNimNode(nnkBracket, a)
|
||||
var newStringTabCall = newCall("newStringTable", attrs,
|
||||
newIdentNode("modeCaseSensitive"))
|
||||
var newStringTabCall = newCall(bindSym"newStringTable", attrs,
|
||||
bindSym"modeCaseSensitive")
|
||||
var elements = newNimNode(nnkBracket, a)
|
||||
for i in 1..a.len-1:
|
||||
if a[i].kind == nnkExprEqExpr:
|
||||
|
||||
@@ -4172,8 +4172,9 @@ template doAssertRaises*(exception, code: untyped): typed =
|
||||
if wrong:
|
||||
raiseAssert(astToStr(exception) & " wasn't raised by:\n" & astToStr(code))
|
||||
|
||||
when defined(cpp) and appType != "lib" and not defined(js) and
|
||||
not defined(nimscript) and hostOS != "standalone":
|
||||
when defined(cpp) and appType != "lib" and
|
||||
not defined(js) and not defined(nimscript) and
|
||||
hostOS != "standalone" and not defined(noCppExceptions):
|
||||
proc setTerminate(handler: proc() {.noconv.})
|
||||
{.importc: "std::set_terminate", header: "<exception>".}
|
||||
setTerminate proc() {.noconv.} =
|
||||
|
||||
@@ -76,6 +76,7 @@ proc rawNewStringNoInit(space: int): NimString {.compilerProc.} =
|
||||
if s < 7: s = 7
|
||||
result = allocStrNoInit(sizeof(TGenericSeq) + s + 1)
|
||||
result.reserved = s
|
||||
result.len = 0
|
||||
when defined(gogc):
|
||||
result.elemSize = 1
|
||||
|
||||
@@ -84,6 +85,7 @@ proc rawNewString(space: int): NimString {.compilerProc.} =
|
||||
if s < 7: s = 7
|
||||
result = allocStr(sizeof(TGenericSeq) + s + 1)
|
||||
result.reserved = s
|
||||
result.len = 0
|
||||
when defined(gogc):
|
||||
result.elemSize = 1
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ when useWinVersion:
|
||||
|
||||
from winlean import SocketHandle
|
||||
else:
|
||||
const versions = "(.1.1|.38|.39|.41|.43|.44|.10|.1.0.2|.1.0.1|.1.0.0|.0.9.9|.0.9.8|)"
|
||||
const versions = "(.1.1|.38|.39|.41|.43|.44|.45|.10|.1.0.2|.1.0.1|.1.0.0|.0.9.9|.0.9.8|)"
|
||||
|
||||
when defined(macosx):
|
||||
const
|
||||
|
||||
@@ -12,11 +12,11 @@ const
|
||||
|
||||
var clientCount = 0
|
||||
|
||||
proc sendMessages(client: TAsyncFD) {.async.} =
|
||||
proc sendMessages(client: AsyncFD) {.async.} =
|
||||
for i in 0 .. <messagesToSend:
|
||||
await send(client, "Message " & $i & "\c\L")
|
||||
|
||||
proc launchSwarm(port: TPort) {.async.} =
|
||||
proc launchSwarm(port: Port) {.async.} =
|
||||
for i in 0 .. <swarmSize:
|
||||
var sock = newAsyncNativeSocket()
|
||||
|
||||
@@ -24,7 +24,7 @@ proc launchSwarm(port: TPort) {.async.} =
|
||||
await sendMessages(sock)
|
||||
closeSocket(sock)
|
||||
|
||||
proc readMessages(client: TAsyncFD) {.async.} =
|
||||
proc readMessages(client: AsyncFD) {.async.} =
|
||||
while true:
|
||||
var line = await recvLine(client)
|
||||
if line == "":
|
||||
@@ -37,7 +37,7 @@ proc readMessages(client: TAsyncFD) {.async.} =
|
||||
else:
|
||||
doAssert false
|
||||
|
||||
proc createServer(port: TPort) {.async.} =
|
||||
proc createServer(port: Port) {.async.} =
|
||||
var server = newAsyncNativeSocket()
|
||||
block:
|
||||
var name: Sockaddr_in
|
||||
@@ -55,8 +55,8 @@ proc createServer(port: TPort) {.async.} =
|
||||
while true:
|
||||
asyncCheck readMessages(await accept(server))
|
||||
|
||||
asyncCheck createServer(TPort(10335))
|
||||
asyncCheck launchSwarm(TPort(10335))
|
||||
asyncCheck createServer(Port(10335))
|
||||
asyncCheck launchSwarm(Port(10335))
|
||||
while true:
|
||||
poll()
|
||||
if clientCount == swarmSize: break
|
||||
|
||||
@@ -3,7 +3,7 @@ discard """
|
||||
"""
|
||||
|
||||
import tables
|
||||
from hashes import THash
|
||||
from hashes import Hash
|
||||
|
||||
# Test with int
|
||||
block:
|
||||
@@ -66,7 +66,7 @@ block:
|
||||
# The same test with a custom hash(s: string) does
|
||||
# work though.
|
||||
block:
|
||||
proc hash(x: int): THash {.inline.} =
|
||||
proc hash(x: int): Hash {.inline.} =
|
||||
echo "overloaded hash"
|
||||
result = x
|
||||
var t = initTable[int, int]()
|
||||
|
||||
@@ -81,7 +81,7 @@ semiProblem()
|
||||
# bug #844
|
||||
|
||||
import json
|
||||
proc parseResponse(): PJsonNode =
|
||||
proc parseResponse(): JsonNode =
|
||||
result = % { "key1": % { "key2": % "value" } }
|
||||
for key, val in result["key1"]:
|
||||
var excMsg = key & "("
|
||||
|
||||
@@ -40,11 +40,11 @@ proc mustRehash(length, counter: int): bool {.inline.} =
|
||||
assert(length > counter)
|
||||
result = (length * 2 < counter * 3) or (length - counter < 4)
|
||||
|
||||
proc nextTry(h, maxHash: THash): THash {.inline.} =
|
||||
proc nextTry(h, maxHash: Hash): Hash {.inline.} =
|
||||
result = ((5 * h) + 1) and maxHash
|
||||
|
||||
template rawGetImpl() =
|
||||
var h: THash = hash(key) and high(t.data) # start with real hash value
|
||||
var h: Hash = hash(key) and high(t.data) # start with real hash value
|
||||
while t.data[h].slot != seEmpty:
|
||||
if t.data[h].key == key and t.data[h].slot == seFilled:
|
||||
return h
|
||||
@@ -52,7 +52,7 @@ template rawGetImpl() =
|
||||
result = -1
|
||||
|
||||
template rawInsertImpl() =
|
||||
var h: THash = hash(key) and high(data)
|
||||
var h: Hash = hash(key) and high(data)
|
||||
while data[h].slot == seFilled:
|
||||
h = nextTry(h, high(data))
|
||||
data[h].key = key
|
||||
@@ -162,7 +162,7 @@ iterator values*[A](t: TCountTable[A]): int =
|
||||
if t.data[h].val != 0: yield t.data[h].val
|
||||
|
||||
proc RawGet[A](t: TCountTable[A], key: A): int =
|
||||
var h: THash = hash(key) and high(t.data) # start with real hash value
|
||||
var h: Hash = hash(key) and high(t.data) # start with real hash value
|
||||
while t.data[h].val != 0:
|
||||
if t.data[h].key == key: return h
|
||||
h = nextTry(h, high(t.data))
|
||||
@@ -181,7 +181,7 @@ proc hasKey*[A](t: TCountTable[A], key: A): bool =
|
||||
|
||||
proc rawInsert[A](t: TCountTable[A], data: var seq[tuple[key: A, val: int]],
|
||||
key: A, val: int) =
|
||||
var h: THash = hash(key) and high(data)
|
||||
var h: Hash = hash(key) and high(data)
|
||||
while data[h].val != 0: h = nextTry(h, high(data))
|
||||
data[h].key = key
|
||||
data[h].val = val
|
||||
|
||||
@@ -28,6 +28,12 @@ t.checkFormat("d dd ddd dddd h hh H HH m mm M MM MMM MMMM s" &
|
||||
|
||||
t.checkFormat("yyyyMMddhhmmss", "20380119031407")
|
||||
|
||||
# issue 7620
|
||||
let t7620_am = parse("4/15/2017 12:01:02 AM +0", "M/d/yyyy' 'h:mm:ss' 'tt' 'z", utc())
|
||||
t7620_am.checkFormat("M/d/yyyy' 'h:mm:ss' 'tt' 'z", "4/15/2017 12:01:02 AM +0")
|
||||
let t7620_pm = parse("4/15/2017 12:01:02 PM +0", "M/d/yyyy' 'h:mm:ss' 'tt' 'z", utc())
|
||||
t7620_pm.checkFormat("M/d/yyyy' 'h:mm:ss' 'tt' 'z", "4/15/2017 12:01:02 PM +0")
|
||||
|
||||
let t2 = fromUnix(160070789).utc # Mon 27 Jan 16:06:29 GMT 1975
|
||||
t2.checkFormat("d dd ddd dddd h hh H HH m mm M MM MMM MMMM s" &
|
||||
" ss t tt y yy yyy yyyy yyyyy z zz zzz",
|
||||
|
||||
@@ -5,7 +5,7 @@ true'''
|
||||
|
||||
import pegs
|
||||
|
||||
template optPeg{peg(pattern)}(pattern: string{lit}): TPeg =
|
||||
template optPeg{peg(pattern)}(pattern: string{lit}): Peg =
|
||||
var gl {.global, gensym.} = peg(pattern)
|
||||
gl
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ proc works() =
|
||||
sort(f, system.cmp[int])
|
||||
outp(f)
|
||||
|
||||
proc weird(json_params: TTable) =
|
||||
proc weird(json_params: Table) =
|
||||
var f = @[3, 2, 1]
|
||||
# The following line doesn't compile: type mismatch. Why?
|
||||
sort(f, system.cmp[int])
|
||||
@@ -29,4 +29,4 @@ when isMainModule:
|
||||
sort(t, system.cmp[int])
|
||||
outp(t)
|
||||
works()
|
||||
weird(initTable[string, TJsonNode]())
|
||||
weird(initTable[string, JsonNode]())
|
||||
|
||||
@@ -52,14 +52,17 @@ when defined(windows):
|
||||
proc askBool(m: string): bool =
|
||||
stdout.write m
|
||||
while true:
|
||||
let answer = stdin.readLine().normalize
|
||||
case answer
|
||||
of "y", "yes":
|
||||
return true
|
||||
of "n", "no":
|
||||
return false
|
||||
else:
|
||||
echo "Please type 'y' or 'n'"
|
||||
try:
|
||||
let answer = stdin.readLine().normalize
|
||||
case answer
|
||||
of "y", "yes":
|
||||
return true
|
||||
of "n", "no":
|
||||
return false
|
||||
else:
|
||||
echo "Please type 'y' or 'n'"
|
||||
except EOFError:
|
||||
quit(1)
|
||||
|
||||
proc askNumber(m: string; a, b: int): int =
|
||||
stdout.write m
|
||||
@@ -99,10 +102,6 @@ when defined(windows):
|
||||
|
||||
proc addToPathEnv*(e: string) =
|
||||
var p = tryGetUnicodeValue(r"Environment", "Path", HKEY_CURRENT_USER)
|
||||
if p.len == 0:
|
||||
p = tryGetUnicodeValue(
|
||||
r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment",
|
||||
"Path", HKEY_LOCAL_MACHINE)
|
||||
let x = if e.contains(Whitespace): "\"" & e & "\"" else: e
|
||||
if p.len > 0:
|
||||
p.add ";"
|
||||
@@ -189,8 +188,10 @@ when defined(windows):
|
||||
proc main() =
|
||||
when defined(windows):
|
||||
let desiredPath = expandFilename(getCurrentDir() / "bin")
|
||||
let p = getUnicodeValue(r"Environment", "Path",
|
||||
HKEY_CURRENT_USER)
|
||||
let p = tryGetUnicodeValue(r"Environment", "Path",
|
||||
HKEY_CURRENT_USER) & ";" & tryGetUnicodeValue(
|
||||
r"System\CurrentControlSet\Control\Session Manager\Environment", "Path",
|
||||
HKEY_LOCAL_MACHINE)
|
||||
var alreadyInPath = false
|
||||
var mingWchoices: seq[string] = @[]
|
||||
var incompat: seq[string] = @[]
|
||||
@@ -199,7 +200,7 @@ proc main() =
|
||||
let y = try: expandFilename(if x[0] == '"' and x[^1] == '"':
|
||||
substr(x, 1, x.len-2) else: x)
|
||||
except: ""
|
||||
if y == desiredPath: alreadyInPath = true
|
||||
if y.cmpIgnoreCase(desiredPath) == 0: alreadyInPath = true
|
||||
if y.toLowerAscii.contains("mingw"):
|
||||
if dirExists(y):
|
||||
if checkGccArch(y): mingWchoices.add y
|
||||
|
||||
Reference in New Issue
Block a user