stdlib: documenation updates, the exception names have been changed

This commit is contained in:
Andreas Rumpf 2018-10-25 07:42:45 +02:00
commit 223e92b83a
15 changed files with 80 additions and 80 deletions

View file

@ -599,7 +599,7 @@ proc listen*(socket: AsyncSocket, backlog = SOMAXCONN) {.tags: [ReadIOEffect].}
## ``Backlog`` specifies the maximum length of the
## queue of pending connections.
##
## Raises an EOS error upon failure.
## Raises an OSError error upon failure.
if listen(socket.fd, backlog) < 0'i32: raiseOSError(osLastError())
proc bindAddr*(socket: AsyncSocket, port = Port(0), address = "") {.

View file

@ -377,7 +377,7 @@ proc colorNameCmp(x: tuple[name: string, col: Color], y: string): int =
proc parseColor*(name: string): Color =
## parses `name` to a color value. If no valid color could be
## parsed ``EInvalidValue`` is raised. Case insensitive.
## parsed ``ValueError`` is raised. Case insensitive.
if name[0] == '#':
result = Color(parseHexInt(name))
else:

View file

@ -302,7 +302,7 @@ proc getCurrentEncoding*(): string =
proc open*(destEncoding = "UTF-8", srcEncoding = "CP1252"): EncodingConverter =
## opens a converter that can convert from `srcEncoding` to `destEncoding`.
## Raises `EIO` if it cannot fulfill the request.
## Raises `IOError` if it cannot fulfill the request.
when not defined(windows):
result = iconvOpen(destEncoding, srcEncoding)
if result == nil:

View file

@ -254,12 +254,12 @@ proc loadAny(s: Stream, a: Any, t: var Table[BiggestInt, pointer]) =
close(p)
proc load*[T](s: Stream, data: var T) =
## loads `data` from the stream `s`. Raises `EIO` in case of an error.
## loads `data` from the stream `s`. Raises `IOError` in case of an error.
var tab = initTable[BiggestInt, pointer]()
loadAny(s, toAny(data), tab)
proc store*[T](s: Stream, data: T) =
## stores `data` into the stream `s`. Raises `EIO` in case of an error.
## stores `data` into the stream `s`. Raises `IOError` in case of an error.
var stored = initIntSet()
var d: T
shallowCopy(d, data)

View file

@ -90,7 +90,7 @@ proc unmapMem*(f: var MemFile, p: pointer, size: int) =
proc open*(filename: string, mode: FileMode = fmRead,
mappedSize = -1, offset = 0, newFileSize = -1,
allowRemap = false): MemFile =
## opens a memory mapped file. If this fails, ``EOS`` is raised.
## opens a memory mapped file. If this fails, ``OSError`` is raised.
##
## ``newFileSize`` can only be set if the file does not exist and is opened
## with write access (e.g., with fmReadWrite).
@ -141,7 +141,7 @@ proc open*(filename: string, mode: FileMode = fmRead,
if result.mapHandle != 0: discard closeHandle(result.mapHandle)
raiseOSError(errCode)
# return false
#raise newException(EIO, msg)
#raise newException(IOError, msg)
template callCreateFile(winApiProc, filename): untyped =
winApiProc(
@ -465,7 +465,7 @@ proc mmsWriteData(s: Stream, buffer: pointer, bufLen: int) =
proc newMemMapFileStream*(filename: string, mode: FileMode = fmRead, fileSize: int = -1):
MemMapFileStream =
## creates a new stream from the file named `filename` with the mode `mode`.
## Raises ## `EOS` if the file cannot be opened. See the `system
## Raises ## `OSError` if the file cannot be opened. See the `system
## <system.html>`_ module for a list of available FileMode enums.
## ``fileSize`` can only be set if the file does not exist and is opened
## with write access (e.g., with fmReadWrite).

View file

@ -221,7 +221,7 @@ proc close*(socket: SocketHandle) =
discard winlean.closesocket(socket)
else:
discard posix.close(socket)
# TODO: These values should not be discarded. An EOS should be raised.
# TODO: These values should not be discarded. An OSError should be raised.
# http://stackoverflow.com/questions/12463473/what-happens-if-you-call-close-on-a-bsd-socket-multiple-times
proc bindAddr*(socket: SocketHandle, name: ptr SockAddr, namelen: SockLen): cint =
@ -594,7 +594,7 @@ proc setSockOptInt*(socket: SocketHandle, level, optname, optval: int) {.
proc setBlocking*(s: SocketHandle, blocking: bool) =
## Sets blocking mode on socket.
##
## Raises EOS on error.
## Raises OSError on error.
when useWinVersion:
var mode = clong(ord(not blocking)) # 1 for non-blocking, 0 for blocking
if ioctlsocket(s, FIONBIO, addr(mode)) == -1:

View file

@ -210,7 +210,7 @@ proc newSocket*(fd: SocketHandle, domain: Domain = AF_INET,
proc newSocket*(domain, sockType, protocol: cint, buffered = true): Socket =
## Creates a new socket.
##
## If an error occurs EOS will be raised.
## If an error occurs OSError will be raised.
let fd = createNativeSocket(domain, sockType, protocol)
if fd == osInvalidSocket:
raiseOSError(osLastError())
@ -221,7 +221,7 @@ proc newSocket*(domain: Domain = AF_INET, sockType: SockType = SOCK_STREAM,
protocol: Protocol = IPPROTO_TCP, buffered = true): Socket =
## Creates a new socket.
##
## If an error occurs EOS will be raised.
## If an error occurs OSError will be raised.
let fd = createNativeSocket(domain, sockType, protocol)
if fd == osInvalidSocket:
raiseOSError(osLastError())
@ -229,7 +229,7 @@ proc newSocket*(domain: Domain = AF_INET, sockType: SockType = SOCK_STREAM,
proc parseIPv4Address(addressStr: string): IpAddress =
## Parses IPv4 adresses
## Raises EInvalidValue on errors
## Raises ValueError on errors
var
byteCount = 0
currentByte:uint16 = 0
@ -263,7 +263,7 @@ proc parseIPv4Address(addressStr: string): IpAddress =
proc parseIPv6Address(addressStr: string): IpAddress =
## Parses IPv6 adresses
## Raises EInvalidValue on errors
## Raises ValueError on errors
result.family = IpAddressFamily.IPv6
if addressStr.len < 2:
raise newException(ValueError, "Invalid IP Address")
@ -384,7 +384,7 @@ proc parseIPv6Address(addressStr: string): IpAddress =
proc parseIpAddress*(addressStr: string): IpAddress =
## Parses an IP address
## Raises EInvalidValue on error
## Raises ValueError on error
if addressStr.len == 0:
raise newException(ValueError, "IP Address string is empty")
if addressStr.contains(':'):
@ -746,7 +746,7 @@ proc listen*(socket: Socket, backlog = SOMAXCONN) {.tags: [ReadIOEffect].} =
## ``Backlog`` specifies the maximum length of the
## queue of pending connections.
##
## Raises an EOS error upon failure.
## Raises an OSError error upon failure.
if nativesockets.listen(socket.fd, backlog) < 0'i32:
raiseOSError(osLastError())
@ -777,7 +777,7 @@ proc acceptAddr*(server: Socket, client: var Socket, address: var string,
## Blocks until a connection is being made from a client. When a connection
## is made sets ``client`` to the client socket and ``address`` to the address
## of the connecting client.
## This function will raise EOS if an error occurs.
## This function will raise OSError if an error occurs.
##
## The resulting client will inherit any properties of the server socket. For
## example: whether the socket is buffered or not.
@ -983,7 +983,7 @@ when defined(ssl):
## Returns ``False`` whenever the socket is not yet ready for a handshake,
## ``True`` whenever handshake completed successfully.
##
## A ESSL error is raised on any other errors.
## A SslError error is raised on any other errors.
##
## **Note:** This procedure is deprecated since version 0.14.0.
result = true
@ -1011,7 +1011,7 @@ when defined(ssl):
## Determines whether a handshake has occurred between a client (``socket``)
## and the server that ``socket`` is connected to.
##
## Throws ESSL if ``socket`` is not an SSL socket.
## Throws SslError if ``socket`` is not an SSL socket.
if socket.isSSL:
return not socket.sslNoHandshake
else:
@ -1203,7 +1203,7 @@ proc recv*(socket: Socket, size: int, timeout = -1,
##
## When ``""`` is returned the socket's connection has been closed.
##
## This function will throw an EOS exception when an error occurs.
## This function will throw an OSError exception when an error occurs.
##
## A timeout may be specified in milliseconds, if enough data is not received
## within the time specified an ETimeout exception will be raised.
@ -1244,7 +1244,7 @@ proc readLine*(socket: Socket, line: var TaintedString, timeout = -1,
##
## If the socket is disconnected, ``line`` will be set to ``""``.
##
## An EOS exception will be raised in the case of a socket error.
## An OSError exception will be raised in the case of a socket error.
##
## A timeout can be specified in milliseconds, if data is not received within
## the specified time an ETimeout exception will be raised.
@ -1299,7 +1299,7 @@ proc recvLine*(socket: Socket, timeout = -1,
##
## If the socket is disconnected, the result will be set to ``""``.
##
## An EOS exception will be raised in the case of a socket error.
## An OSError exception will be raised in the case of a socket error.
##
## A timeout can be specified in milliseconds, if data is not received within
## the specified time an ETimeout exception will be raised.
@ -1317,7 +1317,7 @@ proc recvFrom*(socket: Socket, data: var string, length: int,
## Receives data from ``socket``. This function should normally be used with
## connection-less sockets (UDP sockets).
##
## If an error occurs an EOS exception will be raised. Otherwise the return
## If an error occurs an OSError exception will be raised. Otherwise the return
## value will be the length of data received.
##
## **Warning:** This function does not yet have a buffered implementation,
@ -1390,7 +1390,7 @@ template `&=`*(socket: Socket; data: typed) =
send(socket, data)
proc trySend*(socket: Socket, data: string): bool {.tags: [WriteIOEffect].} =
## Safe alternative to ``send``. Does not raise an EOS when an error occurs,
## Safe alternative to ``send``. Does not raise an OSError when an error occurs,
## and instead returns ``false`` on failure.
result = send(socket, cstring(data), data.len) == data.len

View file

@ -121,7 +121,7 @@ proc startProcess*(command: string,
## invocation if possible as it leads to non portable software.
##
## Return value: The newly created process object. Nil is never returned,
## but ``EOS`` is raised in case of an error.
## but ``OSError`` is raised in case of an error.
proc startCmd*(command: string, options: set[ProcessOption] = {
poStdErrToStdOut, poUsePath}): Process {.

View file

@ -267,7 +267,7 @@ proc parseBiggestInt*(s: string, number: var BiggestInt, start = 0): int {.
rtl, extern: "npuParseBiggestInt", noSideEffect.} =
## parses an integer starting at `start` and stores the value into `number`.
## Result is the number of processed chars or 0 if there is no integer.
## `EOverflow` is raised if an overflow occurs.
## `OverflowError` is raised if an overflow occurs.
var res: BiggestInt
# use 'res' for exception safety (don't write to 'number' in case of an
# overflow exception):

View file

@ -1342,7 +1342,7 @@ when not defined(js):
subs: varargs[tuple[pattern: Peg, repl: string]]) {.
rtl, extern: "npegs$1".} =
## reads in the file `infile`, performs a parallel replacement (calls
## `parallelReplace`) and writes back to `outfile`. Raises ``EIO`` if an
## `parallelReplace`) and writes back to `outfile`. Raises ``IOError`` if an
## error occurs. This is supposed to be used for quick scripting.
##
## **Note**: this proc does not exist while using the JS backend.

View file

@ -157,112 +157,112 @@ proc peek[T](s: Stream, result: var T) =
raise newEIO("cannot read from stream")
proc readChar*(s: Stream): char =
## reads a char from the stream `s`. Raises `EIO` if an error occurred.
## reads a char from the stream `s`. Raises `IOError` if an error occurred.
## Returns '\\0' as an EOF marker.
if readData(s, addr(result), sizeof(result)) != 1: result = '\0'
proc peekChar*(s: Stream): char =
## peeks a char from the stream `s`. Raises `EIO` if an error occurred.
## peeks a char from the stream `s`. Raises `IOError` if an error occurred.
## Returns '\\0' as an EOF marker.
if peekData(s, addr(result), sizeof(result)) != 1: result = '\0'
proc readBool*(s: Stream): bool =
## reads a bool from the stream `s`. Raises `EIO` if an error occurred.
## reads a bool from the stream `s`. Raises `IOError` if an error occurred.
read(s, result)
proc peekBool*(s: Stream): bool =
## peeks a bool from the stream `s`. Raises `EIO` if an error occurred.
## peeks a bool from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result)
proc readInt8*(s: Stream): int8 =
## reads an int8 from the stream `s`. Raises `EIO` if an error occurred.
## reads an int8 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result)
proc peekInt8*(s: Stream): int8 =
## peeks an int8 from the stream `s`. Raises `EIO` if an error occurred.
## peeks an int8 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result)
proc readInt16*(s: Stream): int16 =
## reads an int16 from the stream `s`. Raises `EIO` if an error occurred.
## reads an int16 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result)
proc peekInt16*(s: Stream): int16 =
## peeks an int16 from the stream `s`. Raises `EIO` if an error occurred.
## peeks an int16 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result)
proc readInt32*(s: Stream): int32 =
## reads an int32 from the stream `s`. Raises `EIO` if an error occurred.
## reads an int32 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result)
proc peekInt32*(s: Stream): int32 =
## peeks an int32 from the stream `s`. Raises `EIO` if an error occurred.
## peeks an int32 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result)
proc readInt64*(s: Stream): int64 =
## reads an int64 from the stream `s`. Raises `EIO` if an error occurred.
## reads an int64 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result)
proc peekInt64*(s: Stream): int64 =
## peeks an int64 from the stream `s`. Raises `EIO` if an error occurred.
## peeks an int64 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result)
proc readUint8*(s: Stream): uint8 =
## reads an uint8 from the stream `s`. Raises `EIO` if an error occurred.
## reads an uint8 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result)
proc peekUint8*(s: Stream): uint8 =
## peeks an uint8 from the stream `s`. Raises `EIO` if an error occurred.
## peeks an uint8 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result)
proc readUint16*(s: Stream): uint16 =
## reads an uint16 from the stream `s`. Raises `EIO` if an error occurred.
## reads an uint16 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result)
proc peekUint16*(s: Stream): uint16 =
## peeks an uint16 from the stream `s`. Raises `EIO` if an error occurred.
## peeks an uint16 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result)
proc readUint32*(s: Stream): uint32 =
## reads an uint32 from the stream `s`. Raises `EIO` if an error occurred.
## reads an uint32 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result)
proc peekUint32*(s: Stream): uint32 =
## peeks an uint32 from the stream `s`. Raises `EIO` if an error occurred.
## peeks an uint32 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result)
proc readUint64*(s: Stream): uint64 =
## reads an uint64 from the stream `s`. Raises `EIO` if an error occurred.
## reads an uint64 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result)
proc peekUint64*(s: Stream): uint64 =
## peeks an uint64 from the stream `s`. Raises `EIO` if an error occurred.
## peeks an uint64 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result)
proc readFloat32*(s: Stream): float32 =
## reads a float32 from the stream `s`. Raises `EIO` if an error occurred.
## reads a float32 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result)
proc peekFloat32*(s: Stream): float32 =
## peeks a float32 from the stream `s`. Raises `EIO` if an error occurred.
## peeks a float32 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result)
proc readFloat64*(s: Stream): float64 =
## reads a float64 from the stream `s`. Raises `EIO` if an error occurred.
## reads a float64 from the stream `s`. Raises `IOError` if an error occurred.
read(s, result)
proc peekFloat64*(s: Stream): float64 =
## peeks a float64 from the stream `s`. Raises `EIO` if an error occurred.
## peeks a float64 from the stream `s`. Raises `IOError` if an error occurred.
peek(s, result)
proc readStr*(s: Stream, length: int): TaintedString =
## reads a string of length `length` from the stream `s`. Raises `EIO` if
## reads a string of length `length` from the stream `s`. Raises `IOError` if
## an error occurred.
result = newString(length).TaintedString
var L = readData(s, cstring(result), length)
if L != length: setLen(result.string, L)
proc peekStr*(s: Stream, length: int): TaintedString =
## peeks a string of length `length` from the stream `s`. Raises `EIO` if
## peeks a string of length `length` from the stream `s`. Raises `IOError` if
## an error occurred.
result = newString(length).TaintedString
var L = peekData(s, cstring(result), length)
@ -301,7 +301,7 @@ proc peekLine*(s: Stream, line: var TaintedString): bool =
proc readLine*(s: Stream): TaintedString =
## Reads a line from a stream `s`. Note: This is not very efficient. Raises
## `EIO` if an error occurred.
## `IOError` if an error occurred.
result = TaintedString""
if s.atEnd:
raise newEIO("cannot read from stream")
@ -317,7 +317,7 @@ proc readLine*(s: Stream): TaintedString =
proc peekLine*(s: Stream): TaintedString =
## Peeks a line from a stream `s`. Note: This is not very efficient. Raises
## `EIO` if an error occurred.
## `IOError` if an error occurred.
let pos = getPosition(s)
defer: setPosition(s, pos)
result = readLine(s)