PKSvH֕Iprompt/__info__.py__author__ = "Stefan Fischer" __email__ = "sfischer13@ymail.com" __contact__ = "Stefan Fischer <{}>".format(__email__) __copyright__ = "Copyright (c) 2015-2016 {}".format(__author__) __credits__ = [] __date__ = "2016-03-22" __license__ = "MIT" __status__ = "production" __summary__ = "Prompt and verify user input on the command line." __url__ = "https://github.com/sfischer13/python-prompt/" __version__ = "0.3.2" PK{PG_%``prompt/exceptions.pyclass PromptException: """Root of prompt exceptions which will never be raised.""" pass PKzvHqprompt/__init__.py# The MIT License (MIT) # # Copyright (c) 2015-2016 Stefan Fischer # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. """Prompt and verify user input on the command line. The project was initiated by Stefan Fischer. Note ---- This project is still a work in progress. """ import getpass import re __author__ = "Stefan Fischer" __contact__ = "Stefan Fischer " __copyright__ = "Copyright (c) 2015-2016 Stefan Fischer" __credits__ = [] __date__ = "2016-03-22" __license__ = "MIT" __status__ = "production" __version__ = "0.3.2" PROMPT = "? " """Prompt that will be shown by default.""" RE_EMAIL_SIMPLE = re.compile(r"^[^@]+@[^@]+\.[^@]+$") """Regular expression for email addresses.""" def character(prompt=None, empty=False): """Prompt a single character. Parameters ---------- prompt : str, optional Use an alternative prompt. empty : bool, optional Allow an empty response. Returns ------- str or None A str if the user entered a single-character, non-empty string. None if the user pressed only Enter and ``empty`` was True. """ s = _prompt_input(prompt) if empty and not s: return None elif len(s) == 1: return s else: return character(prompt=prompt, empty=empty) def email(prompt=None, empty=False, mode="simple"): """Prompt an email address. This check is based on a simple regular expression and does not verify whether an email actually exists. Parameters ---------- prompt : str, optional Use an alternative prompt. empty : bool, optional Allow an empty response. mode : {'simple'}, optional 'simple' will use a simple regular expression. No other mode is implemented yet. Returns ------- str or None A str if the user entered a likely email address. None if the user pressed only Enter and ``empty`` was True. """ if mode == "simple": s = _prompt_input(prompt) if empty and not s: return None else: if RE_EMAIL_SIMPLE.match(s): return s else: return email(prompt=prompt, empty=empty, mode=mode) else: raise ValueError def integer(prompt=None, empty=False): """Prompt an integer. Parameters ---------- prompt : str, optional Use an alternative prompt. empty : bool, optional Allow an empty response. Returns ------- int or None An int if the user entered a valid integer. None if the user pressed only Enter and ``empty`` was True. """ s = _prompt_input(prompt) if empty and not s: return None else: try: return int(s) except ValueError: return integer(prompt=prompt, empty=empty) def real(prompt=None, empty=False): """Prompt a real number. Parameters ---------- prompt : str, optional Use an alternative prompt. empty : bool, optional Allow an empty response. Returns ------- float or None A float if the user entered a valid real number. None if the user pressed only Enter and ``empty`` was True. """ s = _prompt_input(prompt) if empty and not s: return None else: try: return float(s) except ValueError: return real(prompt=prompt, empty=empty) def regex(pattern, prompt=None, empty=False, flags=0): """Prompt a string that matches a regular expression. Parameters ---------- pattern : str A regular expression that must be matched. prompt : str, optional Use an alternative prompt. empty : bool, optional Allow an empty response. flags : int, optional Flags that will be passed to ``re.match``. Returns ------- Match or None A match object if the user entered a matching string. None if the user pressed only Enter and ``empty`` was True. See Also -------- re.match """ s = _prompt_input(prompt) if empty and not s: return None else: m = re.match(pattern, s, flags=flags) if m: return m else: return regex(pattern, prompt=prompt, empty=empty, flags=flags) def secret(prompt=None, empty=False): """Prompt a string without echoing. Parameters ---------- prompt : str, optional Use an alternative prompt. empty : bool, optional Allow an empty response. Returns ------- str or None A str if the user entered a non-empty string. None if the user pressed only Enter and ``empty`` was True. Raises ------ getpass.GetPassWarning If echo free input is unavailable. See Also -------- getpass.getpass """ if prompt is None: prompt = PROMPT s = getpass.getpass(prompt=prompt) if empty and not s: return None else: if s: return s else: return secret(prompt=prompt, empty=empty) def string(prompt=None, empty=False): """Prompt a string. Parameters ---------- prompt : str, optional Use an alternative prompt. empty : bool, optional Allow an empty response. Returns ------- str or None A str if the user entered a non-empty string. None if the user pressed only Enter and ``empty`` was True. """ s = _prompt_input(prompt) if empty and not s: return None else: if s: return s else: return string(prompt=prompt, empty=empty) def _prompt_input(prompt): if prompt is None: return input(PROMPT) else: return input(prompt) PKvHth-y y &prompt-0.3.2.dist-info/DESCRIPTION.rstPython Prompt Package ===================== |PyPI Version| |PyPI Downloads| |Travis| |Coverage Status| |Documentation Status| | Prompt and verify user input on the command line. | Python 3.2+ and Wheels are supported. The project was initiated by Stefan Fischer. - `Documentation `__ is available on PythonHosted. - `Questions `__ can be asked via e-mail. - `Changes `__ between releases are documented. - `Source code `__ is tracked on GitHub. - `Bugs `__ can be reported on the issue tracker. Install ------- |PyPI Python Versions| |PyPI Wheel| The package is available on `PyPI `__: :: $ pip install prompt Use --- An extensive `documentation `__ is available. Some simple use cases: :: import prompt email = prompt.email() # modify default prompt integer = prompt.integer(prompt="Please enter a number: ") # allow empty response real = prompt.real(empty=True) # require a two digit number using a regular expression regex = prompt.regex("^\d\d$") Contribute ---------- | Write a bug report or send a pull request. | Other `contributors `__ have done so before. - `Roadmap `__ of planned improvements - `Issues `__ that have been reported License ------- | Copyright (c) 2015-2016 Stefan Fischer | The source code is available under the **MIT License**. | See `LICENSE `__ for further details. .. |PyPI Version| image:: https://img.shields.io/pypi/v/prompt.svg :target: https://pypi.python.org/pypi/prompt .. |PyPI Downloads| image:: https://img.shields.io/pypi/dm/prompt.svg :target: https://pypi.python.org/pypi/prompt .. |Travis| image:: https://img.shields.io/travis/sfischer13/python-prompt.svg :target: https://travis-ci.org/sfischer13/python-prompt .. |Coverage Status| image:: https://coveralls.io/repos/sfischer13/python-prompt/badge.svg?branch=master&service=github :target: https://coveralls.io/github/sfischer13/python-prompt?branch=master .. |Documentation Status| image:: https://readthedocs.org/projects/prompt/badge/?version=latest :target: http://prompt.readthedocs.org/en/latest/?badge=latest .. |PyPI Python Versions| image:: https://img.shields.io/pypi/pyversions/prompt.svg :target: https://pypi.python.org/pypi/prompt .. |PyPI Wheel| image:: https://img.shields.io/pypi/wheel/prompt.svg :target: https://pypi.python.org/pypi/prompt PKvHs6``$prompt-0.3.2.dist-info/metadata.json{"classifiers": ["Development Status :: 5 - Production/Stable", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: Implementation", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Terminals", "Topic :: Utilities"], "extensions": {"python.details": {"contacts": [{"email": "sfischer13@ymail.com", "name": "Stefan Fischer", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/sfischer13/python-prompt/"}}}, "generator": "bdist_wheel (0.26.0)", "keywords": ["prompt", "input", "console", "terminal", "tty"], "license": "MIT", "metadata_version": "2.0", "name": "prompt", "summary": "This is a library for prompting input on the command line.", "test_requires": [{"requires": ["pytest"]}], "version": "0.3.2"}PKvHaQ$prompt-0.3.2.dist-info/top_level.txtprompt PKFQG2prompt-0.3.2.dist-info/zip-safe PKvH}\\prompt-0.3.2.dist-info/WHEELWheel-Version: 1.0 Generator: bdist_wheel (0.26.0) Root-Is-Purelib: true Tag: py3-none-any PKvH򁜽yyprompt-0.3.2.dist-info/METADATAMetadata-Version: 2.0 Name: prompt Version: 0.3.2 Summary: This is a library for prompting input on the command line. Home-page: https://github.com/sfischer13/python-prompt/ Author: Stefan Fischer Author-email: sfischer13@ymail.com License: MIT Keywords: prompt input console terminal tty Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Environment :: Console Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: Implementation Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development :: Libraries Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Topic :: Terminals Classifier: Topic :: Utilities Python Prompt Package ===================== |PyPI Version| |PyPI Downloads| |Travis| |Coverage Status| |Documentation Status| | Prompt and verify user input on the command line. | Python 3.2+ and Wheels are supported. The project was initiated by Stefan Fischer. - `Documentation `__ is available on PythonHosted. - `Questions `__ can be asked via e-mail. - `Changes `__ between releases are documented. - `Source code `__ is tracked on GitHub. - `Bugs `__ can be reported on the issue tracker. Install ------- |PyPI Python Versions| |PyPI Wheel| The package is available on `PyPI `__: :: $ pip install prompt Use --- An extensive `documentation `__ is available. Some simple use cases: :: import prompt email = prompt.email() # modify default prompt integer = prompt.integer(prompt="Please enter a number: ") # allow empty response real = prompt.real(empty=True) # require a two digit number using a regular expression regex = prompt.regex("^\d\d$") Contribute ---------- | Write a bug report or send a pull request. | Other `contributors `__ have done so before. - `Roadmap `__ of planned improvements - `Issues `__ that have been reported License ------- | Copyright (c) 2015-2016 Stefan Fischer | The source code is available under the **MIT License**. | See `LICENSE `__ for further details. .. |PyPI Version| image:: https://img.shields.io/pypi/v/prompt.svg :target: https://pypi.python.org/pypi/prompt .. |PyPI Downloads| image:: https://img.shields.io/pypi/dm/prompt.svg :target: https://pypi.python.org/pypi/prompt .. |Travis| image:: https://img.shields.io/travis/sfischer13/python-prompt.svg :target: https://travis-ci.org/sfischer13/python-prompt .. |Coverage Status| image:: https://coveralls.io/repos/sfischer13/python-prompt/badge.svg?branch=master&service=github :target: https://coveralls.io/github/sfischer13/python-prompt?branch=master .. |Documentation Status| image:: https://readthedocs.org/projects/prompt/badge/?version=latest :target: http://prompt.readthedocs.org/en/latest/?badge=latest .. |PyPI Python Versions| image:: https://img.shields.io/pypi/pyversions/prompt.svg :target: https://pypi.python.org/pypi/prompt .. |PyPI Wheel| image:: https://img.shields.io/pypi/wheel/prompt.svg :target: https://pypi.python.org/pypi/prompt PKvHh  prompt-0.3.2.dist-info/RECORDprompt/__info__.py,sha256=ZlnISGP46-Z1TLBLfLlLr2GoPZeXqr_v2yisI7Xc7e0,415 prompt/__init__.py,sha256=cmeDzCkHgCUSDDsmOVLzzh1PReFm-KA8mgbT7FLZCfM,6857 prompt/exceptions.py,sha256=CnWKNG-0KdT8xzZthOqWWBAU-wYGqQPklbiTBs7U7bw,96 prompt-0.3.2.dist-info/DESCRIPTION.rst,sha256=-zBe7U_z3exj4QZnZNFucTfSroCMAAkcDkm2OFrXkJo,2937 prompt-0.3.2.dist-info/METADATA,sha256=tee6Fr1d4Yn3NAhNOdKyk0NtOdPlVXPzCSGLkWyNtyg,4217 prompt-0.3.2.dist-info/RECORD,, prompt-0.3.2.dist-info/WHEEL,sha256=zX7PHtH_7K-lEzyK75et0UBa3Bj8egCBMXe1M4gc6SU,92 prompt-0.3.2.dist-info/metadata.json,sha256=0mzCTfiO5LMkfILvK_75FZunxQBO3w37_krJ3onY1lk,1376 prompt-0.3.2.dist-info/top_level.txt,sha256=KTTUaldAfrDXHw_9ncN3OQWhFQqi_S7PiUfLKbQhgCg,7 prompt-0.3.2.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1 PKSvH֕Iprompt/__info__.pyPK{PG_%``prompt/exceptions.pyPKzvHqaprompt/__init__.pyPKvHth-y y &Zprompt-0.3.2.dist-info/DESCRIPTION.rstPKvHs6``$)prompt-0.3.2.dist-info/metadata.jsonPKvHaQ$.prompt-0.3.2.dist-info/top_level.txtPKFQG2/prompt-0.3.2.dist-info/zip-safePKvH}\\@/prompt-0.3.2.dist-info/WHEELPKvH򁜽yy/prompt-0.3.2.dist-info/METADATAPKvHh  @prompt-0.3.2.dist-info/RECORDPK C