summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/packages/docutils/rstgen.nim13
-rw-r--r--lib/pure/asyncio.nim7
-rw-r--r--lib/pure/httpclient.nim3
-rw-r--r--lib/pure/os.nim8
-rw-r--r--lib/pure/unicode.nim4
-rw-r--r--lib/system.nim19
6 files changed, 47 insertions, 7 deletions
diff --git a/lib/packages/docutils/rstgen.nim b/lib/packages/docutils/rstgen.nim
index 5afd70319..a56f62448 100644
--- a/lib/packages/docutils/rstgen.nim
+++ b/lib/packages/docutils/rstgen.nim
@@ -699,7 +699,18 @@ proc formatNamedVars*(frmt: string, varnames: openArray[string],
 
 
 proc defaultConfig*(): PStringTable =
-  ## creates a default configuration for HTML generation.
+  ## Returns a default configuration for embedded HTML generation.
+  ##
+  ## The returned ``PStringTable`` contains the paramters used by the HTML
+  ## engine to build the final output. For information on what these parameters
+  ## are and their purpose, please look up the file ``config/nimdoc.cfg``
+  ## bundled with the compiler.
+  ##
+  ## The only difference between the contents of that file and the values
+  ## provided by this proc is the ``doc.file`` variable. The ``doc.file``
+  ## variable of the configuration file contains HTML to build standalone
+  ## pages, while this proc returns just the content for procs like
+  ## ``rstToHtml`` to generate the bare minimum HTML.
   result = newStringTable(modeStyleInsensitive)
   
   template setConfigVar(key, val: expr) =
diff --git a/lib/pure/asyncio.nim b/lib/pure/asyncio.nim
index c4a07d751..3c2a5c17a 100644
--- a/lib/pure/asyncio.nim
+++ b/lib/pure/asyncio.nim
@@ -233,8 +233,11 @@ proc asyncSockHandleWrite(h: PObject) =
       let sock = PAsyncSocket(h)
       try:
         let bytesSent = sock.socket.sendAsync(sock.sendBuffer)
-        assert bytesSent > 0
-        if bytesSent != sock.sendBuffer.len:
+        if bytesSent == 0:
+          # Apparently the socket cannot be written to. Even though select
+          # just told us that it can be... This used to be an assert. Just
+          # do nothing instead.
+        elif bytesSent != sock.sendBuffer.len:
           sock.sendBuffer = sock.sendBuffer[bytesSent .. -1]
         elif bytesSent == sock.sendBuffer.len:
           sock.sendBuffer = ""
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim
index 2c0e7b835..bb9835fe7 100644
--- a/lib/pure/httpclient.nim
+++ b/lib/pure/httpclient.nim
@@ -220,9 +220,8 @@ proc parseResponse(s: TSocket, getBody: bool, timeout: int): TResponse =
       inc(linei, le)
       if line[linei] != ':': httpError("invalid headers")
       inc(linei) # Skip :
-      linei += skipWhitespace(line, linei)
       
-      result.headers[name] = line[linei.. -1]
+      result.headers[name] = line[linei.. -1].strip()
   if not fullyRead:
     httpError("Connection was closed before full request has been made")
   if getBody:
diff --git a/lib/pure/os.nim b/lib/pure/os.nim
index 504343d67..448ecc1e3 100644
--- a/lib/pure/os.nim
+++ b/lib/pure/os.nim
@@ -387,6 +387,14 @@ proc existsDir*(dir: string): bool {.rtl, extern: "nos$1", tags: [FReadDir].} =
     var res: TStat
     return stat(dir, res) >= 0'i32 and S_ISDIR(res.st_mode)
 
+proc fileExists*(filename: string): bool {.inline.} =
+  ## Synonym for existsFile
+  existsFile(filename)
+
+proc dirExists*(dir: string): bool {.inline.} =
+  ## Synonym for existsDir
+  existsDir(dir)
+
 proc getLastModificationTime*(file: string): TTime {.rtl, extern: "nos$1".} =
   ## Returns the `file`'s last modification time.
   when defined(posix):
diff --git a/lib/pure/unicode.nim b/lib/pure/unicode.nim
index 37a64a8f3..6e73eea3f 100644
--- a/lib/pure/unicode.nim
+++ b/lib/pure/unicode.nim
@@ -132,6 +132,10 @@ proc toUTF8*(c: TRune): string {.rtl, extern: "nuc$1".} =
     result = newString(1)
     result[0] = chr(i)
 
+proc `$`*(rune: TRune): string =
+  ## converts a rune to a string
+  rune.toUTF8
+
 proc `$`*(runes: seq[TRune]): string =
   ## converts a sequence of runes to a string
   result = ""
diff --git a/lib/system.nim b/lib/system.nim
index 70c8a529a..75bebf702 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -2708,7 +2708,23 @@ proc locals*(): TObject {.magic: "Locals", noSideEffect.} =
   ## in the current scope. This is quite fast as it does not rely
   ## on any debug or runtime information. Note that in constrast to what
   ## the official signature says, the return type is not ``TObject`` but a
-  ## tuple of a structure that depends on the current scope.
+  ## tuple of a structure that depends on the current scope. Example:
+  ##
+  ## .. code-block:: nimrod
+  ##   proc testLocals() =
+  ##     var
+  ##       a = "something"
+  ##       b = 4
+  ##       c = locals()
+  ##       d = "super!"
+  ##
+  ##     b = 1
+  ##     for name, value in fieldPairs(c):
+  ##       echo "name ", name, " with value ", value
+  ##     echo "B is ", b
+  ##   # -> name a with value something
+  ##   # -> name b with value 4
+  ##   # -> B is 1
   discard
 
 when not defined(booting):
@@ -2719,4 +2735,3 @@ when not defined(booting):
 
   template isStatic*(x): expr = compiles(static(x))
     # checks whether `x` is a value known at compile-time
-