about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorYuce Tekol <yucetekol@gmail.com>2019-05-05 08:32:07 +0300
committerYuce Tekol <yucetekol@gmail.com>2019-05-05 08:32:07 +0300
commit255eb665172640f2315ca7e18d64c95927c6620a (patch)
tree834779f258c560ad030ac4d04fad2b989ef49b0b
parent76404999955ee8e98e851fcbc0ce22866291dbc4 (diff)
parent9d214c788740b8c5042a186a390fc72c78c012d0 (diff)
downloadpyopenbsd-255eb665172640f2315ca7e18d64c95927c6620a.tar.gz
Merge branch 'master' of gitea.cs:yuce/pyopenbsd
-rw-r--r--README.md8
1 files changed, 7 insertions, 1 deletions
diff --git a/README.md b/README.md
index b8b12a2..d178c33 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,7 @@
 # openbsd
 
 Python bindings for some OpenBSD-specific APIs. Currently the following are supported:
+
 * `pledge`
 * `unveil`
 
@@ -35,7 +36,7 @@ openbsd.pledge("stdio rpath")
 print(open("/etc/resolv.conf"))
 ```
 
-Try removing `rpath` permission.
+Try removing the`rpath permission.
 
 ### unveil
 
@@ -48,6 +49,11 @@ Try opening `/bin/ksh`.
 
 Use `openbsd.unveil()` to lock down restrictions.
 
+
+## Similar Projects
+
+* [PyPledge](https://gitlab.com/i80and/pypledge): Python binding for the OpenBSD pledge(2) system call. Uses ctypes.
+
 ## License
 
 (c) 2019 Yuce Tekol
} /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#
#
#              Nim's Runtime Library
#        (c) Copyright 2020 Nim Contributors
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## This module adds functionality for the built-in `set` type.
##
## See also
## ========
## * `std/packedsets <packedsets.html>`_
## * `std/sets <sets.html>`_

import typetraits, macros

#[
  type SetElement* = char|byte|bool|int16|uint16|enum|uint8|int8
    ## The allowed types of a built-in set.
]#

template toSet*(iter: untyped): untyped =
  ## Returns a built-in set from the elements of the iterable `iter`.
  runnableExamples:
    assert "helloWorld".toSet == {'W', 'd', 'e', 'h', 'l', 'o', 'r'}
    assert toSet([10u16, 20, 30]) == {10u16, 20, 30}
    assert [30u8, 100, 10].toSet == {10u8, 30, 100}
    assert toSet(@[1321i16, 321, 90]) == {90i16, 321, 1321}
    assert toSet([false]) == {false}
    assert toSet(0u8..10) == {0u8..10}

  var result: set[elementType(iter)]
  for x in iter:
    incl(result, x)
  result

macro enumElementsAsSet(enm: typed): untyped = result = newNimNode(nnkCurly).add(enm.getType[1][1..^1])

# func fullSet*(T: typedesc): set[T] {.inline.} = # xxx would give: Error: ordinal type expected
func fullSet*[T](U: typedesc[T]): set[T] {.inline.} =
  ## Returns a set containing all elements in `U`.
  runnableExamples:
    assert bool.fullSet == {true, false}
    type A = range[1..3]
    assert A.fullSet == {1.A, 2, 3}
    assert int8.fullSet.len == 256
  when T is Ordinal:
    {T.low..T.high}
  else: # Hole filled enum
    enumElementsAsSet(T)

func complement*[T](s: set[T]): set[T] {.inline.} =
  ## Returns the set complement of `a`.
  runnableExamples:
    type Colors = enum
      red, green = 3, blue
    assert complement({red, blue}) == {green}
    assert complement({red, green, blue}).card == 0
    assert complement({range[0..10](0), 1, 2, 3}) == {range[0..10](4), 5, 6, 7, 8, 9, 10}
    assert complement({'0'..'9'}) == {0.char..255.char} - {'0'..'9'}
  fullSet(T) - s

func `[]=`*[T](t: var set[T], key: T, val: bool) {.inline.} =
  ## Syntax sugar for `if val: t.incl key else: t.excl key`
  runnableExamples:
    type A = enum
      a0, a1, a2, a3
    var s = {a0, a3}
    s[a0] = false
    s[a1] = false
    assert s == {a3}
    s[a2] = true
    s[a3] = true
    assert s == {a2, a3}
  if val: t.incl key else: t.excl key