{ "info": { "author": "Grant Jenks", "author_email": "contact@grantjenks.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Natural Language :: English", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "Tribool: Three-Valued Logic\n===========================\n\n`Tribool `_ is an Apache2 licensed\nPython module that implements three-valued logic.\n\nSuppose for a moment that you're attempting to store a value across a network\nconnection. You begin with a simple protocol in which the server stores the\nreceived value and then sends an acknowledgement to the client. In this\ndesign, the client experiences a delay between when the request is sent and the\nacknowledgement is received. In that delay, it is impossible for the client to\nknow whether the value has been committed on the server. In such cases, it's\nuseful to describe the commit state of the server from the client's perspective\nas True, False, or Indeterminate.\n\nAnother example occurs in database systems. Consider a record that contains\na boolean field. Such a field may only be either True or False. But we want\nto support the notion of committing a partial record in the case that the\nrecord is large or the client does not have all relevant information. In this\nscenario, we wish to commit neither True nor False as the value is currently\nUnknown.\n\nThe Python Tribool module was designed for these cases by describing a logical\ndata type that supports three values: True, False, and Indeterminate. The third\nvalue is best thought of as a state being either True or False. Given these\nthree values it's possible to define truth tables over the logical operators\n`and`, `or` and `not` and to define equality and inequality relationships.\n\nFeatures\n--------\n\n- Pure-Python (easy to hack with)\n- Fully Documented\n- 100% Test Coverage\n- Pragmatic Design (mostly a few truth tables and thread-safe singleton pattern)\n- Developed on Python 2.7\n- Tested on CPython 2.6, 2.7, 3.2, 3.3, 3.4 and PyPy 2.5+, PyPy3 2.4+\n\nQuickstart\n----------\n\nInstalling Tribool is simple with\n`pip `_::\n\n $ pip install tribool\n\nYou can access documentation in the interpreter with Python's built-in help\nfunction::\n\n >>> from tribool import Tribool\n >>> help(Tribool)\n\nTutorial\n--------\n\nA Python Tribool may have any of three values::\n\n >>> from tribool import Tribool\n >>> Tribool(True) # True\n >>> Tribool('False') # False\n >>> Tribool(Tribool(None)) # Indeterminate\n\nThose three values correspond to True, False and Indeterminate. To view that\nvalue, convert the Tribool to a string::\n\n >>> print Tribool(True), Tribool(False), Tribool(None)\n True False Indeterminate\n\nThe logical operators are also defined over these values. For example, the\nresult of negation::\n\n >>> for value in (True, False, None):\n ... print '~', Tribool(value), '=', ~Tribool(value)\n ~ True = False\n ~ False = True\n ~ Indeterminate = Indeterminate\n\nLikewise for `and`, `or`, and `xor` the operators involving only True and\nFalse are unchanged. And mostly those involving Indeterminate result in\nIndeterminate. For example::\n\n >>> True & Tribool(None) # True and Indeterminate = Indeterminate\n Tribool(None)\n >>> False | Tribool(None) # False or Indeterminate = Indeterminate\n Tribool(None)\n >>> None ^ Tribool(None) # Indeterminate xor Indeterminate = Indeterminate\n Tribool(None)\n\nBut there are a couple cases where this is not so::\n\n >>> True | Tribool(None) # True or Indeterminate = True\n Tribool(True)\n >>> False & Tribool(None) # False and Indeterminate = False\n Tribool(False)\n\nNotice that the bitwise-operators, `&|^~`, have been used rather than the\nshort-circuiting `and`, `or`, `not`. Python supports short-circuiting operators\nonly for boolean values and you cannot implicitly convert a Tribool to a\nboolean. An attempt to do so will raise a `ValueError`::\n\n >>> not Tribool(True)\n Traceback (most recent call last):\n ...\n ValueError: Cannot implicitly convert Tribool to bool (use the bitwise\n (&, |, ^, ~) operators or insert a cast and use Tribool(...).value)\n\nFor this reason, you cannot directly use a Tribool in an `if` statement::\n\n >>> if Tribool(True): pass\n Traceback (most recent call last):\n ...\n ValueError: Cannot implicitly convert Tribool to bool ...\n\nTo test the value of a Tribool, use the `value` property::\n\n >>> print Tribool(True).value, Tribool(False).value, Tribool(None).value\n True False None\n >>> (Tribool(None) | True).value is True\n True\n >>> ready, committed = Tribool(True), Tribool(None)\n >>> if (ready & committed).value is not True:\n ... print 'Still waiting.'\n Still waiting.\n\nWhen the Tribool value is Indeterminate, the `value` property will be `None`.\nFor example::\n\n >>> status = Tribool(None)\n >>> # Do something that will update status.\n >>> while status.value is None:\n ... time.sleep(1) # Busy-wait.\n >>> if status.value is True:\n ... print 'Success'\n ... else:\n ... print 'Error'\n\nTribools also work with equality/inequality relationships. Comparing Tribools\nreturns a Tribool because the result may be ambiguous. For the less-than and\ngreater-than relationships, True corresponds to 1 and False to 0 just as with\nboolean data types. The Indeterminate value is either 0 or 1 which has some\nunusual implications. Some example inequalities::\n\n >>> Tribool(False) < Tribool(True)\n Tribool(True)\n >>> Tribool(False) == Tribool(False)\n Tribool(True)\n >>> Tribool(False) > Tribool(True)\n Tribool(False)\n\nThe unusual implication of the Indeterminate value is that it is not equal\nto itself::\n\n >>> print Tribool(True) >= Tribool(None)\n True\n >>> print Tribool(False) < Tribool(None)\n Indeterminate\n >>> print Tribool(None) == Tribool(None)\n Indeterminate\n\nWhen an object is not equal to itself, strange things can happen. Fortunately\nPython defines two notions of equality. The first is defined by the `is`\nrelationship and may not be overriden. The second is defined by the `__eq__`\nmethod. To behave as value types, Tribool objects are singletons. Threrefore\ntwo Tribools with the same value will have matching `id` values. For example::\n\n >>> (id(Tribool(True)), id(Tribool(True)), id(Tribool(True)))\n (4426760848, 4426760848, 4426760848)\n >>> (id(Tribool(None)), id(Tribool(None)), id(Tribool(None)))\n (4426719568, 4426719568, 4426719568)\n\nThis is accomplished by overriding the `__new__` constructor and implementing\na thread-safe singleton pattern. As singletons, Tribool objects are immutable\nand comparable using the `is` operator. Judicious use often results in code\nthat is more readable::\n\n >>> Succeeded, TryAgain = Tribool(True), Tribool(None)\n >>> status = Tribool(None)\n >>> while status is TryAgain:\n ... status = try_something()\n >>> if status is Succeeded:\n ... print 'Success!'\n\nTribool objects are also hashable and work inside `dict` and map-like types::\n\n >>> display = {\n ... Tribool(True): 'Success',\n ... Tribool(False): 'Error',\n ... Tribool(None): 'Try Again',\n ... }\n >>> print display[Tribool(None)]\n Try Again\n\nA surprising result occurs however with containers. When using the `in`\noperator, objects are tested for membership using equality. But this occurs\nin several steps, the first of which is using the `is` operator followed by\nthe `__eq__` method. In case the `__eq__` method fails to return a boolean-\ntyped value, an implicit conversion occurs which Tribool does not permit.\nFor example::\n\n >>> Success, Error, Unknown = map(Tribool, (True, False, None))\n >>> Success in [Success, Error, Unknown] # Works!\n True\n >>> Error in [Success, Error, Unknown] # Fails\n Traceback (most recent call last):\n ...\n ValueError: Cannot implicitly convert Tribool to bool ...\n\nThe latter attempt fails because `Error is Success` returns False and so\n`Error == Success` is tried. That returns `Tribool(False)` which does not\nhave type `bool` and so an implicit conversion occurs. To achieve the\naffect of the `in` operator use the `any` built-in and a generator expression\nlike so::\n\n >>> statuses = [Success, Success, Unknown, Error]\n >>> any(status is Error for status in statuses)\n True\n\nTo obey the singleton pattern, Tribool also implements the `__copy__` and\n`__deepcopy__` methods as part of the `copy` module protocol. Pickling is\nanother method of copying objects and so `__reduce__` is implemented as part of\nthe `pickle` protocol. Note also that Tribool inherits directly from `tuple` to\nprevent mutation of its internal state.\n\nThe Python Tribool module has many uses but it was originally designed to\nsupport the notion of `three-valued logic as found in SQL\n`_. SQL defines similar rules for\nits Null value type in logical expressions. `Django's NullBooleanField\n`_\nis an example where these ideas intersect.\n\nSome readers will be familiar with `Boost.Tribool\n`_, an\nimplementation of the Tribool datatype in C++. While the semantics of both\npackages are the same, the design of the Boost implementation differs a great\ndeal. In particular, Boost defines a new `indeterminate` keyword rather than\nusing the `null` value in C++. An `Indeterminate` object was considered in the\ndesign of this module but discarded in favor of Python's built-in `None`.\n\nReference and Indices\n---------------------\n\n* `Tribool Documentation`_\n* `Tribool at PyPI`_\n* `Tribool at GitHub`_\n* `Tribool Issue Tracker`_\n\n.. _`Tribool Documentation`: http://www.grantjenks.com/docs/tribool/\n.. _`Tribool at PyPI`: https://pypi.python.org/pypi/tribool/\n.. _`Tribool at GitHub`: https://github.com/grantjenks/python_tribool/\n.. _`Tribool Issue Tracker`: https://github.com/grantjenks/python_tribool/issues/\n\nLicense\n-------\n\nCopyright 2015 Grant Jenks\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://www.grantjenks.com/docs/tribool/", "keywords": "", "license": "Apache 2.0", "maintainer": "", "maintainer_email": "", "name": "tribool", "package_url": "https://pypi.org/project/tribool/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/tribool/", "project_urls": { "Homepage": "http://www.grantjenks.com/docs/tribool/" }, "release_url": "https://pypi.org/project/tribool/0.7.3/", "requires_dist": null, "requires_python": "", "summary": "Three-valued logic data type.", "version": "0.7.3" }, "last_serial": 2043829, "releases": { "0.0.4": [ { "comment_text": "", "digests": { "md5": "4ddd9b8df8783a3fd5f84d5c26660956", "sha256": "7d5d8f2b7023ed75effcb0c2da03d42b7a347e385b288587dfc46d1b921a0087" }, "downloads": -1, "filename": "tribool-0.0.4.zip", "has_sig": false, "md5_digest": "4ddd9b8df8783a3fd5f84d5c26660956", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5663, "upload_time": "2013-03-18T05:56:57", "url": "https://files.pythonhosted.org/packages/b0/5d/21fcf824443171715086e4ffe72bb81ca946a4838e9d9fc9af4ca2b35a34/tribool-0.0.4.zip" } ], "0.0.5": [ { "comment_text": "", "digests": { "md5": "8cc8844804bcc691cef8faabd22dacb0", "sha256": "1819746c06b8dcc34c525eadd7bf2a0ac87cf62bc448ed6c8b612703f0067017" }, "downloads": -1, "filename": "tribool-0.0.5.zip", "has_sig": false, "md5_digest": "8cc8844804bcc691cef8faabd22dacb0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5834, "upload_time": "2013-03-22T17:41:51", "url": "https://files.pythonhosted.org/packages/70/11/6da8682560f155f6fae1eacd09d9101cff4175a42fba42dee85368f26dfa/tribool-0.0.5.zip" } ], "0.5.1": [], "0.5.2": [ { "comment_text": "", "digests": { "md5": "e29547fb655d3b0e7cda360059ab036e", "sha256": "911b22ef5ada0a57989b823822696136aea153eabd6fa0db5c78165550cde894" }, "downloads": -1, "filename": "tribool-0.5.2.tar.gz", "has_sig": false, "md5_digest": "e29547fb655d3b0e7cda360059ab036e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7736, "upload_time": "2015-06-05T17:13:37", "url": "https://files.pythonhosted.org/packages/68/97/4cd69d46cfbcf48d2655c82a966d631ac07dc1d4b6916d6dddd366355974/tribool-0.5.2.tar.gz" } ], "0.5.3": [ { "comment_text": "", "digests": { "md5": "23a9fd5967308db466d5d89b6106b8a5", "sha256": "391c909a1880cd6a371a3d8cb5170bbdac9934dec7b8ac12b7c550131ae55fd0" }, "downloads": -1, "filename": "tribool-0.5.3.tar.gz", "has_sig": false, "md5_digest": "23a9fd5967308db466d5d89b6106b8a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4788, "upload_time": "2015-06-05T17:16:54", "url": "https://files.pythonhosted.org/packages/cd/ce/829b4b52711c2a86650ac48035843dc8cb2e3c192d1ee62b6d58d4b3fef7/tribool-0.5.3.tar.gz" } ], "0.5.4": [ { "comment_text": "", "digests": { "md5": "3e93ecf4e7e1b10b80561cb2926ee4de", "sha256": "1b9aa62fb19319f56807b60350cd2fdfcf0d9b853451fb7a6325ba84814834a2" }, "downloads": -1, "filename": "tribool-0.5.4.tar.gz", "has_sig": false, "md5_digest": "3e93ecf4e7e1b10b80561cb2926ee4de", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7747, "upload_time": "2015-06-05T17:19:58", "url": "https://files.pythonhosted.org/packages/c8/ec/102b188eeb34009863f5da2a22cb76da3aaa8418defe093cf25a590ac674/tribool-0.5.4.tar.gz" } ], "0.6.1": [ { "comment_text": "", "digests": { "md5": "7f36bccbb22f0319cf5ad536172ac250", "sha256": "f9d7b8e9947fb7e0ee84092de8cfb7353f580456440920897401f93b440deebb" }, "downloads": -1, "filename": "tribool-0.6.1.tar.gz", "has_sig": false, "md5_digest": "7f36bccbb22f0319cf5ad536172ac250", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7944, "upload_time": "2015-09-14T18:59:51", "url": "https://files.pythonhosted.org/packages/17/2e/d2def5b6c953835a1006590d733cf446448625178e5a494bdd585b9f4ac0/tribool-0.6.1.tar.gz" } ], "0.6.2": [ { "comment_text": "", "digests": { "md5": "10389e8bc9b0ef4cb11a2f7a206b25a5", "sha256": "15554863eaf4886d65051943a30040e0b04905010802d0cb43240d632ab4cc60" }, "downloads": -1, "filename": "tribool-0.6.2.tar.gz", "has_sig": false, "md5_digest": "10389e8bc9b0ef4cb11a2f7a206b25a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7945, "upload_time": "2015-09-14T19:04:06", "url": "https://files.pythonhosted.org/packages/84/8a/404f6a89baa29f7fbc49d4992d0dcfa1b23c35940762b8355bfb40c9849c/tribool-0.6.2.tar.gz" } ], "0.7.1": [ { "comment_text": "", "digests": { "md5": "d939581544661d606991591e82a3fde6", "sha256": "cb30ddc2c929bc9db16568f184cfad65f4e61cc867d6a368d477225a4477ae5e" }, "downloads": -1, "filename": "tribool-0.7.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "d939581544661d606991591e82a3fde6", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11512, "upload_time": "2016-04-03T21:54:42", "url": "https://files.pythonhosted.org/packages/0e/6f/450cc3de6d38e33e3727a7c9b4c3521b488b3efdee0280821394eceb047b/tribool-0.7.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f4778dfe39ee0bc9c3004c82af0dd91d", "sha256": "02336e59bf3ddd7c5a4ff29fb0c694e99f4518671548b0b12c179c7a02ad788a" }, "downloads": -1, "filename": "tribool-0.7.1.tar.gz", "has_sig": false, "md5_digest": "f4778dfe39ee0bc9c3004c82af0dd91d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7693, "upload_time": "2016-04-03T21:54:48", "url": "https://files.pythonhosted.org/packages/d3/15/5a61f6d06b6acfd5ac8dda986a4af10304669c6780f7081f62f23ca02413/tribool-0.7.1.tar.gz" } ], "0.7.2": [ { "comment_text": "", "digests": { "md5": "15cf724ace2b7e5b3416c4f6cb66afca", "sha256": "73a1c05bf9683af65ae4ccd15656c294f6208ef1ec6ebc48260fad67f226eb66" }, "downloads": -1, "filename": "tribool-0.7.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "15cf724ace2b7e5b3416c4f6cb66afca", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11508, "upload_time": "2016-04-03T21:59:33", "url": "https://files.pythonhosted.org/packages/4c/a4/6a7a85660c39c797ffcc34b0a8d0ccdb6dc43a3272aacb095995cda087d4/tribool-0.7.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "70f723df39f4cc48b00c3ab034676933", "sha256": "498027abf5f645f6f59da70a145b1fadae655e8b77cf6326bd486d0fcbd27529" }, "downloads": -1, "filename": "tribool-0.7.2.tar.gz", "has_sig": false, "md5_digest": "70f723df39f4cc48b00c3ab034676933", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7693, "upload_time": "2016-04-03T21:59:43", "url": "https://files.pythonhosted.org/packages/45/39/0eb63db06aebc78c194bfce8ad0e4e98fe6df3d55893a247ff12c8ee502c/tribool-0.7.2.tar.gz" } ], "0.7.3": [ { "comment_text": "", "digests": { "md5": "16b870eb0e1d751dbdf02eb9edd17ab8", "sha256": "fde13951bf571ee9e1f9136461e11c686f0247d44ce005e49fb32c126ca9a617" }, "downloads": -1, "filename": "tribool-0.7.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "16b870eb0e1d751dbdf02eb9edd17ab8", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11528, "upload_time": "2016-04-03T22:07:52", "url": "https://files.pythonhosted.org/packages/aa/32/cd997ace62eafa0d8a1f69d9163447a68ef09b807700948bbb5e2c87770d/tribool-0.7.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "dd35de631a51ca786dcd8304a4f0d7ac", "sha256": "201ebea42e996c921b10b34f07f76bde0c62d2605b610587a2bc24b134bcdb13" }, "downloads": -1, "filename": "tribool-0.7.3.tar.gz", "has_sig": false, "md5_digest": "dd35de631a51ca786dcd8304a4f0d7ac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7714, "upload_time": "2016-04-03T22:07:59", "url": "https://files.pythonhosted.org/packages/c4/10/9442d674824e0f8b6b895cd5836870afcdda53f09e9120a8a7e5c2bce27e/tribool-0.7.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "16b870eb0e1d751dbdf02eb9edd17ab8", "sha256": "fde13951bf571ee9e1f9136461e11c686f0247d44ce005e49fb32c126ca9a617" }, "downloads": -1, "filename": "tribool-0.7.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "16b870eb0e1d751dbdf02eb9edd17ab8", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11528, "upload_time": "2016-04-03T22:07:52", "url": "https://files.pythonhosted.org/packages/aa/32/cd997ace62eafa0d8a1f69d9163447a68ef09b807700948bbb5e2c87770d/tribool-0.7.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "dd35de631a51ca786dcd8304a4f0d7ac", "sha256": "201ebea42e996c921b10b34f07f76bde0c62d2605b610587a2bc24b134bcdb13" }, "downloads": -1, "filename": "tribool-0.7.3.tar.gz", "has_sig": false, "md5_digest": "dd35de631a51ca786dcd8304a4f0d7ac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7714, "upload_time": "2016-04-03T22:07:59", "url": "https://files.pythonhosted.org/packages/c4/10/9442d674824e0f8b6b895cd5836870afcdda53f09e9120a8a7e5c2bce27e/tribool-0.7.3.tar.gz" } ] }