We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Choices in Context
Add support for choices in a context as suggested in #441.

I noticed that we are using custom methods for retrieving the user input and decided to let `click.prompt` handle the Python2/Python3 compatibility matters. This PR requires thorough reviews and testing before merging it as I touched some core functions and I want to be certain I didn't break anything :exclamation: 

The CI might not detect these errors as most of the `read_response` calls are still `monkeypatched`. I'm afraid we need to do some manual testing to be 100% positive that everyting is working as expected :sweat: 

I implemented several tests for the new functionality. :smiley: 

Please let me know your thoughts and I'll be happy to update this PR.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `cookiecutter/compat.py`
Content:
```
1 import os
2 import sys
3 
4 PY3 = sys.version_info[0] == 3
5 OLD_PY2 = sys.version_info[:2] < (2, 7)
6 
7 if PY3:  # pragma: no cover
8     input_str = 'builtins.input'
9     iteritems = lambda d: iter(d.items())
10     from unittest.mock import patch
11     from io import StringIO
12 
13     def read_response(prompt=''):
14         """
15         Prompt the user for a response.
16 
17         Prints the given prompt (which should be a Unicode string),
18         and returns the text entered by the user as a Unicode string.
19 
20         :param prompt: A Unicode string that is presented to the user.
21         """
22         # The Python 3 input function does exactly what we want
23         return input(prompt)
24 
25 else:  # pragma: no cover
26     from __builtin__ import raw_input
27     input = raw_input
28     input_str = '__builtin__.raw_input'
29     iteritems = lambda d: d.iteritems()
30     from mock import patch
31     from cStringIO import StringIO
32 
33     def read_response(prompt=''):
34         """
35         Prompt the user for a response.
36 
37         Prints the given prompt (which should be a Unicode string),
38         and returns the text entered by the user as a Unicode string.
39 
40         :param prompt: A Unicode string that is presented to the user.
41         """
42         # For Python 2, raw_input takes a byte string argument for the prompt.
43         # This must be encoded using the encoding used by sys.stdout.
44         # The result is a byte string encoding using sys.stdin.encoding.
45         # However, if the program is not being run interactively, sys.stdout
46         # and sys.stdin may not have encoding attributes.
47         # In that case we don't print a prompt (stdin/out isn't interactive,
48         # so prompting is pointless), and we assume the returned data is
49         # encoded using sys.getdefaultencoding(). This may not be right,
50         # but it's likely the best we can do.
51         # Isn't Python 2 encoding support wonderful? :-)
52         if sys.stdout.encoding:
53             prompt = prompt.encode(sys.stdout.encoding)
54         else:
55             prompt = ''
56         enc = sys.stdin.encoding or sys.getdefaultencoding()
57         return raw_input(prompt).decode(enc)
58 
59 
60 if PY3:  # Forced testing
61 
62     from shutil import which
63 
64 else:  # Forced testing
65 
66     def is_exe(program):
67         """
68         Returns whether or not a file is an executable.
69         """
70         return os.path.isfile(program) and os.access(program, os.X_OK)
71 
72     def which(cmd, mode=os.F_OK | os.X_OK, path=None):
73         """Given a command, mode, and a PATH string, return the path which
74         conforms to the given mode on the PATH, or None if there is no such
75         file.
76         `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
77         of os.environ.get("PATH"), or can be overridden with a custom search
78         path.
79 
80         Note: This function was backported from the Python 3 source code.
81         """
82         # Check that a given file can be accessed with the correct mode.
83         # Additionally check that `file` is not a directory, as on Windows
84         # directories pass the os.access check.
85         def _access_check(fn, mode):
86             return (os.path.exists(fn) and os.access(fn, mode) and
87                     not os.path.isdir(fn))
88 
89         # If we're given a path with a directory part, look it up directly
90         # rather than referring to PATH directories. This includes checking
91         # relative to the current directory, e.g. ./script
92         if os.path.dirname(cmd):
93             if _access_check(cmd, mode):
94                 return cmd
95             return None
96 
97         if path is None:
98             path = os.environ.get("PATH", os.defpath)
99         if not path:
100             return None
101         path = path.split(os.pathsep)
102 
103         if sys.platform == "win32":
104             # The current directory takes precedence on Windows.
105             if os.curdir not in path:
106                 path.insert(0, os.curdir)
107 
108             # PATHEXT is necessary to check on Windows.
109             pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
110             # See if the given file matches any of the expected path
111             # extensions. This will allow us to short circuit when given
112             # "python.exe". If it does match, only test that one, otherwise we
113             # have to try others.
114             if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
115                 files = [cmd]
116             else:
117                 files = [cmd + ext for ext in pathext]
118         else:
119             # On other platforms you don't have things like PATHEXT to tell you
120             # what file suffixes are executable, so just pass on cmd as-is.
121             files = [cmd]
122 
123         seen = set()
124         for dir in path:
125             normdir = os.path.normcase(dir)
126             if normdir not in seen:
127                 seen.add(normdir)
128                 for thefile in files:
129                     name = os.path.join(dir, thefile)
130                     if _access_check(name, mode):
131                         return name
132         return None
133 
134 
135 def is_string(obj):
136     """Determine if an object is a string."""
137     return isinstance(obj, str if PY3 else basestring)
138 
139 
140 _hush_pyflakes = (patch, StringIO, which)
141
```

Path: `cookiecutter/prompt.py`
Content:
```
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 """
5 cookiecutter.prompt
6 ---------------------
7 
8 Functions for prompting the user for project info.
9 """
10 
11 from __future__ import unicode_literals
12 import sys
13 
14 from .compat import iteritems, read_response, is_string
15 from jinja2.environment import Environment
16 
17 
18 def prompt_for_config(context, no_input=False):
19     """
20     Prompts the user to enter new config, using context as a source for the
21     field names and sample values.
22 
23     :param no_input: Prompt the user at command line for manual configuration?
24     """
25     cookiecutter_dict = {}
26     env = Environment()
27 
28     for key, raw in iteritems(context['cookiecutter']):
29         if key.startswith('_'):
30             cookiecutter_dict[key] = raw
31             continue
32 
33         raw = raw if is_string(raw) else str(raw)
34         val = env.from_string(raw).render(cookiecutter=cookiecutter_dict)
35 
36         if not no_input:
37             prompt = '{0} (default is "{1}")? '.format(key, val)
38 
39             new_val = read_response(prompt).strip()
40 
41             if new_val != '':
42                 val = new_val
43 
44         cookiecutter_dict[key] = val
45     return cookiecutter_dict
46 
47 
48 def query_yes_no(question, default='yes'):
49     """
50     Ask a yes/no question via `read_response()` and return their answer.
51 
52     :param question: A string that is presented to the user.
53     :param default: The presumed answer if the user just hits <Enter>.
54         It must be "yes" (the default), "no" or None (meaning
55         an answer is required of the user).
56 
57     The "answer" return value is one of "yes" or "no".
58 
59     Adapted from
60     http://stackoverflow.com/questions/3041986/python-command-line-yes-no-input
61     http://code.activestate.com/recipes/577058/
62 
63     """
64     valid = {'yes': True, 'y': True, 'ye': True, 'no': False, 'n': False}
65     if default is None:
66         prompt = ' [y/n] '
67     elif default == 'yes':
68         prompt = ' [Y/n] '
69     elif default == 'no':
70         prompt = ' [y/N] '
71     else:
72         raise ValueError('Invalid default answer: "{0}"'.format(default))
73 
74     while True:
75         sys.stdout.write(question + prompt)
76         choice = read_response().lower()
77 
78         if default is not None and choice == '':
79             return valid[default]
80         elif choice in valid:
81             return valid[choice]
82         else:
83             sys.stdout.write('Please respond with "yes" or "no" '
84                              '(or "y" or "n").\n')
85
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/cookiecutter/compat.py b/cookiecutter/compat.py
--- a/cookiecutter/compat.py
+++ b/cookiecutter/compat.py
@@ -4,23 +4,13 @@
 PY3 = sys.version_info[0] == 3
 OLD_PY2 = sys.version_info[:2] < (2, 7)
 
+
 if PY3:  # pragma: no cover
     input_str = 'builtins.input'
     iteritems = lambda d: iter(d.items())
     from unittest.mock import patch
     from io import StringIO
 
-    def read_response(prompt=''):
-        """
-        Prompt the user for a response.
-
-        Prints the given prompt (which should be a Unicode string),
-        and returns the text entered by the user as a Unicode string.
-
-        :param prompt: A Unicode string that is presented to the user.
-        """
-        # The Python 3 input function does exactly what we want
-        return input(prompt)
 
 else:  # pragma: no cover
     from __builtin__ import raw_input
@@ -30,32 +20,6 @@
     from mock import patch
     from cStringIO import StringIO
 
-    def read_response(prompt=''):
-        """
-        Prompt the user for a response.
-
-        Prints the given prompt (which should be a Unicode string),
-        and returns the text entered by the user as a Unicode string.
-
-        :param prompt: A Unicode string that is presented to the user.
-        """
-        # For Python 2, raw_input takes a byte string argument for the prompt.
-        # This must be encoded using the encoding used by sys.stdout.
-        # The result is a byte string encoding using sys.stdin.encoding.
-        # However, if the program is not being run interactively, sys.stdout
-        # and sys.stdin may not have encoding attributes.
-        # In that case we don't print a prompt (stdin/out isn't interactive,
-        # so prompting is pointless), and we assume the returned data is
-        # encoded using sys.getdefaultencoding(). This may not be right,
-        # but it's likely the best we can do.
-        # Isn't Python 2 encoding support wonderful? :-)
-        if sys.stdout.encoding:
-            prompt = prompt.encode(sys.stdout.encoding)
-        else:
-            prompt = ''
-        enc = sys.stdin.encoding or sys.getdefaultencoding()
-        return raw_input(prompt).decode(enc)
-
 
 if PY3:  # Forced testing
 
diff --git a/cookiecutter/prompt.py b/cookiecutter/prompt.py
--- a/cookiecutter/prompt.py
+++ b/cookiecutter/prompt.py
@@ -11,10 +11,29 @@
 from __future__ import unicode_literals
 import sys
 
-from .compat import iteritems, read_response, is_string
+import click
+
+from .compat import iteritems, is_string
 from jinja2.environment import Environment
 
 
+def read_response(prompt=''):
+    """Prompt the user and return the entered value or an empty string.
+
+    :param str prompt: Text to display to the user
+    """
+    # Please see http://click.pocoo.org/4/api/#click.prompt
+    # default: use an empty string if no input happens
+    # prompt_suffix: do not add a suffix to the prompt
+    # show_default: the prompt is expected to mention the default itself
+    return click.prompt(
+        prompt,
+        default='',
+        prompt_suffix='',
+        show_default=False,
+    )
+
+
 def prompt_for_config(context, no_input=False):
     """
     Prompts the user to enter new config, using context as a source for the

{"golden_diff": "diff --git a/cookiecutter/compat.py b/cookiecutter/compat.py\n--- a/cookiecutter/compat.py\n+++ b/cookiecutter/compat.py\n@@ -4,23 +4,13 @@\n PY3 = sys.version_info[0] == 3\n OLD_PY2 = sys.version_info[:2] < (2, 7)\n \n+\n if PY3:  # pragma: no cover\n     input_str = 'builtins.input'\n     iteritems = lambda d: iter(d.items())\n     from unittest.mock import patch\n     from io import StringIO\n \n-    def read_response(prompt=''):\n-        \"\"\"\n-        Prompt the user for a response.\n-\n-        Prints the given prompt (which should be a Unicode string),\n-        and returns the text entered by the user as a Unicode string.\n-\n-        :param prompt: A Unicode string that is presented to the user.\n-        \"\"\"\n-        # The Python 3 input function does exactly what we want\n-        return input(prompt)\n \n else:  # pragma: no cover\n     from __builtin__ import raw_input\n@@ -30,32 +20,6 @@\n     from mock import patch\n     from cStringIO import StringIO\n \n-    def read_response(prompt=''):\n-        \"\"\"\n-        Prompt the user for a response.\n-\n-        Prints the given prompt (which should be a Unicode string),\n-        and returns the text entered by the user as a Unicode string.\n-\n-        :param prompt: A Unicode string that is presented to the user.\n-        \"\"\"\n-        # For Python 2, raw_input takes a byte string argument for the prompt.\n-        # This must be encoded using the encoding used by sys.stdout.\n-        # The result is a byte string encoding using sys.stdin.encoding.\n-        # However, if the program is not being run interactively, sys.stdout\n-        # and sys.stdin may not have encoding attributes.\n-        # In that case we don't print a prompt (stdin/out isn't interactive,\n-        # so prompting is pointless), and we assume the returned data is\n-        # encoded using sys.getdefaultencoding(). This may not be right,\n-        # but it's likely the best we can do.\n-        # Isn't Python 2 encoding support wonderful? :-)\n-        if sys.stdout.encoding:\n-            prompt = prompt.encode(sys.stdout.encoding)\n-        else:\n-            prompt = ''\n-        enc = sys.stdin.encoding or sys.getdefaultencoding()\n-        return raw_input(prompt).decode(enc)\n-\n \n if PY3:  # Forced testing\n \ndiff --git a/cookiecutter/prompt.py b/cookiecutter/prompt.py\n--- a/cookiecutter/prompt.py\n+++ b/cookiecutter/prompt.py\n@@ -11,10 +11,29 @@\n from __future__ import unicode_literals\n import sys\n \n-from .compat import iteritems, read_response, is_string\n+import click\n+\n+from .compat import iteritems, is_string\n from jinja2.environment import Environment\n \n \n+def read_response(prompt=''):\n+    \"\"\"Prompt the user and return the entered value or an empty string.\n+\n+    :param str prompt: Text to display to the user\n+    \"\"\"\n+    # Please see http://click.pocoo.org/4/api/#click.prompt\n+    # default: use an empty string if no input happens\n+    # prompt_suffix: do not add a suffix to the prompt\n+    # show_default: the prompt is expected to mention the default itself\n+    return click.prompt(\n+        prompt,\n+        default='',\n+        prompt_suffix='',\n+        show_default=False,\n+    )\n+\n+\n def prompt_for_config(context, no_input=False):\n     \"\"\"\n     Prompts the user to enter new config, using context as a source for the\n", "issue": "Choices in Context\nAdd support for choices in a context as suggested in #441.\n\nI noticed that we are using custom methods for retrieving the user input and decided to let `click.prompt` handle the Python2/Python3 compatibility matters. This PR requires thorough reviews and testing before merging it as I touched some core functions and I want to be certain I didn't break anything :exclamation: \n\nThe CI might not detect these errors as most of the `read_response` calls are still `monkeypatched`. I'm afraid we need to do some manual testing to be 100% positive that everyting is working as expected :sweat: \n\nI implemented several tests for the new functionality. :smiley: \n\nPlease let me know your thoughts and I'll be happy to update this PR.\n\n", "before_files": [{"content": "import os\nimport sys\n\nPY3 = sys.version_info[0] == 3\nOLD_PY2 = sys.version_info[:2] < (2, 7)\n\nif PY3:  # pragma: no cover\n    input_str = 'builtins.input'\n    iteritems = lambda d: iter(d.items())\n    from unittest.mock import patch\n    from io import StringIO\n\n    def read_response(prompt=''):\n        \"\"\"\n        Prompt the user for a response.\n\n        Prints the given prompt (which should be a Unicode string),\n        and returns the text entered by the user as a Unicode string.\n\n        :param prompt: A Unicode string that is presented to the user.\n        \"\"\"\n        # The Python 3 input function does exactly what we want\n        return input(prompt)\n\nelse:  # pragma: no cover\n    from __builtin__ import raw_input\n    input = raw_input\n    input_str = '__builtin__.raw_input'\n    iteritems = lambda d: d.iteritems()\n    from mock import patch\n    from cStringIO import StringIO\n\n    def read_response(prompt=''):\n        \"\"\"\n        Prompt the user for a response.\n\n        Prints the given prompt (which should be a Unicode string),\n        and returns the text entered by the user as a Unicode string.\n\n        :param prompt: A Unicode string that is presented to the user.\n        \"\"\"\n        # For Python 2, raw_input takes a byte string argument for the prompt.\n        # This must be encoded using the encoding used by sys.stdout.\n        # The result is a byte string encoding using sys.stdin.encoding.\n        # However, if the program is not being run interactively, sys.stdout\n        # and sys.stdin may not have encoding attributes.\n        # In that case we don't print a prompt (stdin/out isn't interactive,\n        # so prompting is pointless), and we assume the returned data is\n        # encoded using sys.getdefaultencoding(). This may not be right,\n        # but it's likely the best we can do.\n        # Isn't Python 2 encoding support wonderful? :-)\n        if sys.stdout.encoding:\n            prompt = prompt.encode(sys.stdout.encoding)\n        else:\n            prompt = ''\n        enc = sys.stdin.encoding or sys.getdefaultencoding()\n        return raw_input(prompt).decode(enc)\n\n\nif PY3:  # Forced testing\n\n    from shutil import which\n\nelse:  # Forced testing\n\n    def is_exe(program):\n        \"\"\"\n        Returns whether or not a file is an executable.\n        \"\"\"\n        return os.path.isfile(program) and os.access(program, os.X_OK)\n\n    def which(cmd, mode=os.F_OK | os.X_OK, path=None):\n        \"\"\"Given a command, mode, and a PATH string, return the path which\n        conforms to the given mode on the PATH, or None if there is no such\n        file.\n        `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result\n        of os.environ.get(\"PATH\"), or can be overridden with a custom search\n        path.\n\n        Note: This function was backported from the Python 3 source code.\n        \"\"\"\n        # Check that a given file can be accessed with the correct mode.\n        # Additionally check that `file` is not a directory, as on Windows\n        # directories pass the os.access check.\n        def _access_check(fn, mode):\n            return (os.path.exists(fn) and os.access(fn, mode) and\n                    not os.path.isdir(fn))\n\n        # If we're given a path with a directory part, look it up directly\n        # rather than referring to PATH directories. This includes checking\n        # relative to the current directory, e.g. ./script\n        if os.path.dirname(cmd):\n            if _access_check(cmd, mode):\n                return cmd\n            return None\n\n        if path is None:\n            path = os.environ.get(\"PATH\", os.defpath)\n        if not path:\n            return None\n        path = path.split(os.pathsep)\n\n        if sys.platform == \"win32\":\n            # The current directory takes precedence on Windows.\n            if os.curdir not in path:\n                path.insert(0, os.curdir)\n\n            # PATHEXT is necessary to check on Windows.\n            pathext = os.environ.get(\"PATHEXT\", \"\").split(os.pathsep)\n            # See if the given file matches any of the expected path\n            # extensions. This will allow us to short circuit when given\n            # \"python.exe\". If it does match, only test that one, otherwise we\n            # have to try others.\n            if any(cmd.lower().endswith(ext.lower()) for ext in pathext):\n                files = [cmd]\n            else:\n                files = [cmd + ext for ext in pathext]\n        else:\n            # On other platforms you don't have things like PATHEXT to tell you\n            # what file suffixes are executable, so just pass on cmd as-is.\n            files = [cmd]\n\n        seen = set()\n        for dir in path:\n            normdir = os.path.normcase(dir)\n            if normdir not in seen:\n                seen.add(normdir)\n                for thefile in files:\n                    name = os.path.join(dir, thefile)\n                    if _access_check(name, mode):\n                        return name\n        return None\n\n\ndef is_string(obj):\n    \"\"\"Determine if an object is a string.\"\"\"\n    return isinstance(obj, str if PY3 else basestring)\n\n\n_hush_pyflakes = (patch, StringIO, which)\n", "path": "cookiecutter/compat.py"}, {"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\n\"\"\"\ncookiecutter.prompt\n---------------------\n\nFunctions for prompting the user for project info.\n\"\"\"\n\nfrom __future__ import unicode_literals\nimport sys\n\nfrom .compat import iteritems, read_response, is_string\nfrom jinja2.environment import Environment\n\n\ndef prompt_for_config(context, no_input=False):\n    \"\"\"\n    Prompts the user to enter new config, using context as a source for the\n    field names and sample values.\n\n    :param no_input: Prompt the user at command line for manual configuration?\n    \"\"\"\n    cookiecutter_dict = {}\n    env = Environment()\n\n    for key, raw in iteritems(context['cookiecutter']):\n        if key.startswith('_'):\n            cookiecutter_dict[key] = raw\n            continue\n\n        raw = raw if is_string(raw) else str(raw)\n        val = env.from_string(raw).render(cookiecutter=cookiecutter_dict)\n\n        if not no_input:\n            prompt = '{0} (default is \"{1}\")? '.format(key, val)\n\n            new_val = read_response(prompt).strip()\n\n            if new_val != '':\n                val = new_val\n\n        cookiecutter_dict[key] = val\n    return cookiecutter_dict\n\n\ndef query_yes_no(question, default='yes'):\n    \"\"\"\n    Ask a yes/no question via `read_response()` and return their answer.\n\n    :param question: A string that is presented to the user.\n    :param default: The presumed answer if the user just hits <Enter>.\n        It must be \"yes\" (the default), \"no\" or None (meaning\n        an answer is required of the user).\n\n    The \"answer\" return value is one of \"yes\" or \"no\".\n\n    Adapted from\n    http://stackoverflow.com/questions/3041986/python-command-line-yes-no-input\n    http://code.activestate.com/recipes/577058/\n\n    \"\"\"\n    valid = {'yes': True, 'y': True, 'ye': True, 'no': False, 'n': False}\n    if default is None:\n        prompt = ' [y/n] '\n    elif default == 'yes':\n        prompt = ' [Y/n] '\n    elif default == 'no':\n        prompt = ' [y/N] '\n    else:\n        raise ValueError('Invalid default answer: \"{0}\"'.format(default))\n\n    while True:\n        sys.stdout.write(question + prompt)\n        choice = read_response().lower()\n\n        if default is not None and choice == '':\n            return valid[default]\n        elif choice in valid:\n            return valid[choice]\n        else:\n            sys.stdout.write('Please respond with \"yes\" or \"no\" '\n                             '(or \"y\" or \"n\").\\n')\n", "path": "cookiecutter/prompt.py"}], "after_files": [{"content": "import os\nimport sys\n\nPY3 = sys.version_info[0] == 3\nOLD_PY2 = sys.version_info[:2] < (2, 7)\n\n\nif PY3:  # pragma: no cover\n    input_str = 'builtins.input'\n    iteritems = lambda d: iter(d.items())\n    from unittest.mock import patch\n    from io import StringIO\n\n\nelse:  # pragma: no cover\n    from __builtin__ import raw_input\n    input = raw_input\n    input_str = '__builtin__.raw_input'\n    iteritems = lambda d: d.iteritems()\n    from mock import patch\n    from cStringIO import StringIO\n\n\nif PY3:  # Forced testing\n\n    from shutil import which\n\nelse:  # Forced testing\n\n    def is_exe(program):\n        \"\"\"\n        Returns whether or not a file is an executable.\n        \"\"\"\n        return os.path.isfile(program) and os.access(program, os.X_OK)\n\n    def which(cmd, mode=os.F_OK | os.X_OK, path=None):\n        \"\"\"Given a command, mode, and a PATH string, return the path which\n        conforms to the given mode on the PATH, or None if there is no such\n        file.\n        `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result\n        of os.environ.get(\"PATH\"), or can be overridden with a custom search\n        path.\n\n        Note: This function was backported from the Python 3 source code.\n        \"\"\"\n        # Check that a given file can be accessed with the correct mode.\n        # Additionally check that `file` is not a directory, as on Windows\n        # directories pass the os.access check.\n        def _access_check(fn, mode):\n            return (os.path.exists(fn) and os.access(fn, mode) and\n                    not os.path.isdir(fn))\n\n        # If we're given a path with a directory part, look it up directly\n        # rather than referring to PATH directories. This includes checking\n        # relative to the current directory, e.g. ./script\n        if os.path.dirname(cmd):\n            if _access_check(cmd, mode):\n                return cmd\n            return None\n\n        if path is None:\n            path = os.environ.get(\"PATH\", os.defpath)\n        if not path:\n            return None\n        path = path.split(os.pathsep)\n\n        if sys.platform == \"win32\":\n            # The current directory takes precedence on Windows.\n            if os.curdir not in path:\n                path.insert(0, os.curdir)\n\n            # PATHEXT is necessary to check on Windows.\n            pathext = os.environ.get(\"PATHEXT\", \"\").split(os.pathsep)\n            # See if the given file matches any of the expected path\n            # extensions. This will allow us to short circuit when given\n            # \"python.exe\". If it does match, only test that one, otherwise we\n            # have to try others.\n            if any(cmd.lower().endswith(ext.lower()) for ext in pathext):\n                files = [cmd]\n            else:\n                files = [cmd + ext for ext in pathext]\n        else:\n            # On other platforms you don't have things like PATHEXT to tell you\n            # what file suffixes are executable, so just pass on cmd as-is.\n            files = [cmd]\n\n        seen = set()\n        for dir in path:\n            normdir = os.path.normcase(dir)\n            if normdir not in seen:\n                seen.add(normdir)\n                for thefile in files:\n                    name = os.path.join(dir, thefile)\n                    if _access_check(name, mode):\n                        return name\n        return None\n\n\ndef is_string(obj):\n    \"\"\"Determine if an object is a string.\"\"\"\n    return isinstance(obj, str if PY3 else basestring)\n\n\n_hush_pyflakes = (patch, StringIO, which)\n", "path": "cookiecutter/compat.py"}, {"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\n\"\"\"\ncookiecutter.prompt\n---------------------\n\nFunctions for prompting the user for project info.\n\"\"\"\n\nfrom __future__ import unicode_literals\nimport sys\n\nimport click\n\nfrom .compat import iteritems, is_string\nfrom jinja2.environment import Environment\n\n\ndef read_response(prompt=''):\n    \"\"\"Prompt the user and return the entered value or an empty string.\n\n    :param str prompt: Text to display to the user\n    \"\"\"\n    # Please see http://click.pocoo.org/4/api/#click.prompt\n    # default: use an empty string if no input happens\n    # prompt_suffix: do not add a suffix to the prompt\n    # show_default: the prompt is expected to mention the default itself\n    return click.prompt(\n        prompt,\n        default='',\n        prompt_suffix='',\n        show_default=False,\n    )\n\n\ndef prompt_for_config(context, no_input=False):\n    \"\"\"\n    Prompts the user to enter new config, using context as a source for the\n    field names and sample values.\n\n    :param no_input: Prompt the user at command line for manual configuration?\n    \"\"\"\n    cookiecutter_dict = {}\n    env = Environment()\n\n    for key, raw in iteritems(context['cookiecutter']):\n        if key.startswith('_'):\n            cookiecutter_dict[key] = raw\n            continue\n\n        raw = raw if is_string(raw) else str(raw)\n        val = env.from_string(raw).render(cookiecutter=cookiecutter_dict)\n\n        if not no_input:\n            prompt = '{0} (default is \"{1}\")? '.format(key, val)\n\n            new_val = read_response(prompt).strip()\n\n            if new_val != '':\n                val = new_val\n\n        cookiecutter_dict[key] = val\n    return cookiecutter_dict\n\n\ndef query_yes_no(question, default='yes'):\n    \"\"\"\n    Ask a yes/no question via `read_response()` and return their answer.\n\n    :param question: A string that is presented to the user.\n    :param default: The presumed answer if the user just hits <Enter>.\n        It must be \"yes\" (the default), \"no\" or None (meaning\n        an answer is required of the user).\n\n    The \"answer\" return value is one of \"yes\" or \"no\".\n\n    Adapted from\n    http://stackoverflow.com/questions/3041986/python-command-line-yes-no-input\n    http://code.activestate.com/recipes/577058/\n\n    \"\"\"\n    valid = {'yes': True, 'y': True, 'ye': True, 'no': False, 'n': False}\n    if default is None:\n        prompt = ' [y/n] '\n    elif default == 'yes':\n        prompt = ' [Y/n] '\n    elif default == 'no':\n        prompt = ' [y/N] '\n    else:\n        raise ValueError('Invalid default answer: \"{0}\"'.format(default))\n\n    while True:\n        sys.stdout.write(question + prompt)\n        choice = read_response().lower()\n\n        if default is not None and choice == '':\n            return valid[default]\n        elif choice in valid:\n            return valid[choice]\n        else:\n            sys.stdout.write('Please respond with \"yes\" or \"no\" '\n                             '(or \"y\" or \"n\").\\n')\n", "path": "cookiecutter/prompt.py"}]}