diff options
author | dom96 <dominikpicheta@googlemail.com> | 2011-03-28 22:08:16 +0100 |
---|---|---|
committer | dom96 <dominikpicheta@googlemail.com> | 2011-03-28 22:08:16 +0100 |
commit | d9232d126eae4169d2c2200a77f3521ceb47b50b (patch) | |
tree | 40595f798f34d370eb6fc76a0b45f724e62a22df /lib/pure | |
parent | dc669155e39007f1b584eef247dff90523f836bf (diff) | |
download | Nim-d9232d126eae4169d2c2200a77f3521ceb47b50b.tar.gz |
Bug fixes for standard library: httpclient, json, os, parsexml, xmltree, xmlparser, gtk2.
Diffstat (limited to 'lib/pure')
-rwxr-xr-x | lib/pure/httpclient.nim | 5 | ||||
-rwxr-xr-x | lib/pure/json.nim | 14 | ||||
-rwxr-xr-x | lib/pure/os.nim | 6 | ||||
-rwxr-xr-x | lib/pure/parsexml.nim | 2 | ||||
-rwxr-xr-x | lib/pure/xmlparser.nim | 4 | ||||
-rwxr-xr-x | lib/pure/xmltree.nim | 19 |
6 files changed, 39 insertions, 11 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index 092d8e5c6..39ceb5f68 100755 --- a/lib/pure/httpclient.nim +++ b/lib/pure/httpclient.nim @@ -237,10 +237,7 @@ proc request*(url: string, httpMethod = httpGET, extraHeaders = "", var r = parseUrl(url) var headers = copy($httpMethod, len("http")) - if r.path != "": - headers.add(" /" & r.path & r.query) - else: - headers.add(" /") + headers.add(" /" & r.path & r.query) headers.add(" HTTP/1.1\c\L") add(headers, "Host: " & r.hostname & "\c\L") diff --git a/lib/pure/json.nim b/lib/pure/json.nim index 7fbc8bfcf..c90c071b6 100755 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -700,6 +700,18 @@ proc `$`*(node: PJsonNode): String = result = "" toPretty(result, node, 1, False) +iterator items*(node: PJsonNode): PJSonNode = + ## Iterator for the items of `node`. `node` has to be a JArray. + assert node.kind == JArray + for i in items(node.elems): + yield i + +iterator pairs*(node: PJsonNode): tuple[key: string, val: PJsonNode] = + ## Iterator for the child elements of `node`. `node` has to be a JObject. + assert node.kind == JObject + for key, val in items(node.fields): + yield (key, val) + proc eat(p: var TJsonParser, tok: TTokKind) = if p.tok == tok: discard getTok(p) else: raiseParseErr(p, tokToStr[tok]) @@ -711,7 +723,7 @@ proc parseJson(p: var TJsonParser): PJsonNode = result = newJString(p.a) discard getTok(p) of tkInt: - result = newJInt(parseInt(p.a)) + result = newJInt(parseBiggestInt(p.a)) discard getTok(p) of tkFloat: result = newJFloat(parseFloat(p.a)) diff --git a/lib/pure/os.nim b/lib/pure/os.nim index f7d22ca06..d9b81365f 100755 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -1130,6 +1130,12 @@ proc getConfigDir*(): string {.rtl, extern: "nos$1".} = when defined(windows): return getEnv("APPDATA") & "\\" else: return getEnv("HOME") & "/.config/" +proc getTempDir*(): string {.rtl, extern: "nos$1".} = + ## Returns the temporary directory of the current user for applications to + ## save temporary files in. + when defined(windows): return getEnv("TEMP") & "\\" + else: return "/tmp/" + when defined(windows): # Since we support GUI applications with Nimrod, we sometimes generate # a WinMain entry proc. But a WinMain proc has no access to the parsed diff --git a/lib/pure/parsexml.nim b/lib/pure/parsexml.nim index 8551dda90..c49986087 100755 --- a/lib/pure/parsexml.nim +++ b/lib/pure/parsexml.nim @@ -586,11 +586,11 @@ proc next*(my: var TXmlParser) = of stateNormal: getTok(my) of stateStart: + my.state = stateNormal getTok(my) if my.kind == xmlPI and my.a == "xml": # just skip the first ``<?xml >`` processing instruction getTok(my) - my.state = stateNormal of stateAttr: # parse an attribute key-value pair: if my.buf[my.bufpos] == '>': diff --git a/lib/pure/xmlparser.nim b/lib/pure/xmlparser.nim index ad28bf618..8c5c5f5ab 100755 --- a/lib/pure/xmlparser.nim +++ b/lib/pure/xmlparser.nim @@ -68,11 +68,11 @@ proc parse(x: var TXmlParser, errors: var seq[string]): PXmlNode = of xmlElementOpen: result = newElement(x.elementName) next(x) - result.attr = newStringTable() + result.attrs = newStringTable() while true: case x.kind of xmlAttribute: - result.attr[x.attrKey] = x.attrValue + result.attrs[x.attrKey] = x.attrValue next(x) of xmlElementClose: next(x) diff --git a/lib/pure/xmltree.nim b/lib/pure/xmltree.nim index 57988698b..41765b87a 100755 --- a/lib/pure/xmltree.nim +++ b/lib/pure/xmltree.nim @@ -98,17 +98,17 @@ iterator items*(n: PXmlNode): PXmlNode {.inline.} = assert n.k == xnElement for i in 0 .. n.len-1: yield n[i] -proc attr*(n: PXmlNode): PXmlAttributes {.inline.} = +proc attrs*(n: PXmlNode): PXmlAttributes {.inline.} = ## gets the attributes belonging to `n`. assert n.k == xnElement result = n.fAttr -proc `attr=`*(n: PXmlNode, attr: PXmlAttributes) {.inline.} = +proc `attrs=`*(n: PXmlNode, attr: PXmlAttributes) {.inline.} = ## sets the attributes belonging to `n`. assert n.k == xnElement n.fAttr = attr -proc attrLen*(n: PXmlNode): int {.inline.} = +proc attrsLen*(n: PXmlNode): int {.inline.} = ## returns the number of `n`'s attributes. assert n.k == xnElement if not isNil(n.fAttr): result = len(n.fAttr) @@ -262,3 +262,16 @@ macro `<>`*(x: expr): expr = ## result = xmlConstructor(x) +proc child*(n: PXmlNode, name: string): PXmlNode = + ## Finds the first child element of `n` with a name of `name`. + ## Returns `nil` on failure. + assert n.kind == xnElement + for i in items(n): + if i.kind == xnElement: + if i.tag == name: + return i + +proc attr*(n: PXmlNode, name: string): string = + ## Finds the first attribute of `n` with a name of `name`. + assert n.kind == xnElement + return n.attrs[name] |