We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Accepting default dict parameter value with no user input causes string "default" to be put into dict parameter
* Cookiecutter version: 1.5
* Template project url: private repo, minimal example is attached
* Python version: 2.7.10
* Operating System: Mac OS X 10.10.5

### Description:

I'm using dict parameter and trying to let it use default value. When prompted, `[default]` is shown as dict parameter default value. Then, if I respond to prompt with:

1. Just enter (i.e. no user input) - project cutting fails due to an error, as cookiecutter puts `default` into dict parameter (i.e. it becomes string instead of dict).
2. String "default" and enter - project is cooked successfully with default value.

In two words, just accepting default value for dict parameter by providing no user input causes string "default" to be put into a dict parameter instead of default value provided in cookiecutter.json.

If you allow some speculation, this happens because `click.prompt` [does not call `value_proc` if no user input is given](https://github.com/pallets/click/blob/master/click/termui.py#L103-L104)

See console session logs below.

### What I've run:

Failure:
```
cookiecutter minimal-example/
app_name [dict_default_bug]: 
dict [default]: 
Unable to create file 'placeholder.md'
Error message: 'str object' has no attribute 'foo'
Context: {
    "cookiecutter": {
        "app_name": "dict_default_bug", 
        "dict": "default"
    }
}
```

Success:
```
cookiecutter minimal-example/
app_name [dict_default_bug]: 
dict [default]: default
```
[minimal-example.zip](https://github.com/audreyr/cookiecutter/files/686416/minimal-example.zip)


--- 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/prompt.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 """
4 cookiecutter.prompt
5 ---------------------
6 
7 Functions for prompting the user for project info.
8 """
9 
10 from collections import OrderedDict
11 import json
12 
13 import click
14 from past.builtins import basestring
15 
16 from future.utils import iteritems
17 
18 from jinja2.exceptions import UndefinedError
19 
20 from .exceptions import UndefinedVariableInTemplate
21 from .environment import StrictEnvironment
22 
23 
24 def read_user_variable(var_name, default_value):
25     """Prompt the user for the given variable and return the entered value
26     or the given default.
27 
28     :param str var_name: Variable of the context to query the user
29     :param default_value: Value that will be returned if no input happens
30     """
31     # Please see http://click.pocoo.org/4/api/#click.prompt
32     return click.prompt(var_name, default=default_value)
33 
34 
35 def read_user_yes_no(question, default_value):
36     """Prompt the user to reply with 'yes' or 'no' (or equivalent values).
37 
38     Note:
39       Possible choices are 'true', '1', 'yes', 'y' or 'false', '0', 'no', 'n'
40 
41     :param str question: Question to the user
42     :param default_value: Value that will be returned if no input happens
43     """
44     # Please see http://click.pocoo.org/4/api/#click.prompt
45     return click.prompt(
46         question,
47         default=default_value,
48         type=click.BOOL
49     )
50 
51 
52 def read_user_choice(var_name, options):
53     """Prompt the user to choose from several options for the given variable.
54 
55     The first item will be returned if no input happens.
56 
57     :param str var_name: Variable as specified in the context
58     :param list options: Sequence of options that are available to select from
59     :return: Exactly one item of ``options`` that has been chosen by the user
60     """
61     # Please see http://click.pocoo.org/4/api/#click.prompt
62     if not isinstance(options, list):
63         raise TypeError
64 
65     if not options:
66         raise ValueError
67 
68     choice_map = OrderedDict(
69         (u'{}'.format(i), value) for i, value in enumerate(options, 1)
70     )
71     choices = choice_map.keys()
72     default = u'1'
73 
74     choice_lines = [u'{} - {}'.format(*c) for c in choice_map.items()]
75     prompt = u'\n'.join((
76         u'Select {}:'.format(var_name),
77         u'\n'.join(choice_lines),
78         u'Choose from {}'.format(u', '.join(choices))
79     ))
80 
81     user_choice = click.prompt(
82         prompt, type=click.Choice(choices), default=default
83     )
84     return choice_map[user_choice]
85 
86 
87 def create_value_proc(default_display, default_value):
88     def process_json(user_value):
89         if user_value == default_display:
90             # Return the given default w/o any processing
91             return default_value
92 
93         try:
94             user_dict = json.loads(
95                 user_value,
96                 object_pairs_hook=OrderedDict,
97             )
98         except Exception:
99             # Leave it up to click to ask the user again
100             raise click.UsageError('Unable to decode to JSON.')
101 
102         if not isinstance(user_dict, dict):
103             # Leave it up to click to ask the user again
104             raise click.UsageError('Requires JSON dict.')
105 
106         return user_dict
107 
108     return process_json
109 
110 
111 def read_user_dict(var_name, default_value):
112     """Prompt the user to provide a dictionary of data.
113 
114     :param str var_name: Variable as specified in the context
115     :param default_value: Value that will be returned if no input is provided
116     :return: A Python dictionary to use in the context.
117     """
118     # Please see http://click.pocoo.org/4/api/#click.prompt
119     if not isinstance(default_value, dict):
120         raise TypeError
121 
122     default_display = 'default'
123 
124     return click.prompt(
125         var_name,
126         default=default_display,
127         type=click.STRING,
128         value_proc=create_value_proc(
129             default_display,
130             default_value,
131         ),
132     )
133 
134 
135 def render_variable(env, raw, cookiecutter_dict):
136     """Inside the prompting taken from the cookiecutter.json file, this renders
137     the next variable. For example, if a project_name is "Peanut Butter
138     Cookie", the repo_name could be be rendered with:
139 
140         `{{ cookiecutter.project_name.replace(" ", "_") }}`.
141 
142     This is then presented to the user as the default.
143 
144     :param Environment env: A Jinja2 Environment object.
145     :param str raw: The next value to be prompted for by the user.
146     :param dict cookiecutter_dict: The current context as it's gradually
147         being populated with variables.
148     :return: The rendered value for the default variable.
149     """
150     if raw is None:
151         return None
152     elif isinstance(raw, dict):
153         return {
154             render_variable(env, k, cookiecutter_dict):
155                 render_variable(env, v, cookiecutter_dict)
156             for k, v in raw.items()
157         }
158     elif isinstance(raw, list):
159         return [
160             render_variable(env, v, cookiecutter_dict)
161             for v in raw
162         ]
163     elif not isinstance(raw, basestring):
164         raw = str(raw)
165 
166     template = env.from_string(raw)
167 
168     rendered_template = template.render(cookiecutter=cookiecutter_dict)
169     return rendered_template
170 
171 
172 def prompt_choice_for_config(cookiecutter_dict, env, key, options, no_input):
173     """Prompt the user which option to choose from the given. Each of the
174     possible choices is rendered beforehand.
175     """
176     rendered_options = [
177         render_variable(env, raw, cookiecutter_dict) for raw in options
178     ]
179 
180     if no_input:
181         return rendered_options[0]
182     return read_user_choice(key, rendered_options)
183 
184 
185 def prompt_for_config(context, no_input=False):
186     """
187     Prompts the user to enter new config, using context as a source for the
188     field names and sample values.
189 
190     :param no_input: Prompt the user at command line for manual configuration?
191     """
192     cookiecutter_dict = {}
193     env = StrictEnvironment(context=context)
194 
195     # First pass: Handle simple and raw variables, plus choices.
196     # These must be done first because the dictionaries keys and
197     # values might refer to them.
198     for key, raw in iteritems(context[u'cookiecutter']):
199         if key.startswith(u'_'):
200             cookiecutter_dict[key] = raw
201             continue
202 
203         try:
204             if isinstance(raw, list):
205                 # We are dealing with a choice variable
206                 val = prompt_choice_for_config(
207                     cookiecutter_dict, env, key, raw, no_input
208                 )
209                 cookiecutter_dict[key] = val
210             elif not isinstance(raw, dict):
211                 # We are dealing with a regular variable
212                 val = render_variable(env, raw, cookiecutter_dict)
213 
214                 if not no_input:
215                     val = read_user_variable(key, val)
216 
217                 cookiecutter_dict[key] = val
218         except UndefinedError as err:
219             msg = "Unable to render variable '{}'".format(key)
220             raise UndefinedVariableInTemplate(msg, err, context)
221 
222     # Second pass; handle the dictionaries.
223     for key, raw in iteritems(context[u'cookiecutter']):
224 
225         try:
226             if isinstance(raw, dict):
227                 # We are dealing with a dict variable
228                 val = render_variable(env, raw, cookiecutter_dict)
229 
230                 if not no_input:
231                     val = read_user_dict(key, val)
232 
233                 cookiecutter_dict[key] = val
234         except UndefinedError as err:
235             msg = "Unable to render variable '{}'".format(key)
236             raise UndefinedVariableInTemplate(msg, err, context)
237 
238     return cookiecutter_dict
239
```
--- 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/prompt.py b/cookiecutter/prompt.py
--- a/cookiecutter/prompt.py
+++ b/cookiecutter/prompt.py
@@ -84,28 +84,21 @@
     return choice_map[user_choice]
 
 
-def create_value_proc(default_display, default_value):
-    def process_json(user_value):
-        if user_value == default_display:
-            # Return the given default w/o any processing
-            return default_value
+def process_json(user_value):
+    try:
+        user_dict = json.loads(
+            user_value,
+            object_pairs_hook=OrderedDict,
+        )
+    except Exception:
+        # Leave it up to click to ask the user again
+        raise click.UsageError('Unable to decode to JSON.')
 
-        try:
-            user_dict = json.loads(
-                user_value,
-                object_pairs_hook=OrderedDict,
-            )
-        except Exception:
-            # Leave it up to click to ask the user again
-            raise click.UsageError('Unable to decode to JSON.')
-
-        if not isinstance(user_dict, dict):
-            # Leave it up to click to ask the user again
-            raise click.UsageError('Requires JSON dict.')
-
-        return user_dict
+    if not isinstance(user_dict, dict):
+        # Leave it up to click to ask the user again
+        raise click.UsageError('Requires JSON dict.')
 
-    return process_json
+    return user_dict
 
 
 def read_user_dict(var_name, default_value):
@@ -121,16 +114,18 @@
 
     default_display = 'default'
 
-    return click.prompt(
+    user_value = click.prompt(
         var_name,
         default=default_display,
         type=click.STRING,
-        value_proc=create_value_proc(
-            default_display,
-            default_value,
-        ),
+        value_proc=process_json,
     )
 
+    if user_value == default_display:
+        # Return the given default w/o any processing
+        return default_value
+    return user_value
+
 
 def render_variable(env, raw, cookiecutter_dict):
     """Inside the prompting taken from the cookiecutter.json file, this renders

{"golden_diff": "diff --git a/cookiecutter/prompt.py b/cookiecutter/prompt.py\n--- a/cookiecutter/prompt.py\n+++ b/cookiecutter/prompt.py\n@@ -84,28 +84,21 @@\n     return choice_map[user_choice]\n \n \n-def create_value_proc(default_display, default_value):\n-    def process_json(user_value):\n-        if user_value == default_display:\n-            # Return the given default w/o any processing\n-            return default_value\n+def process_json(user_value):\n+    try:\n+        user_dict = json.loads(\n+            user_value,\n+            object_pairs_hook=OrderedDict,\n+        )\n+    except Exception:\n+        # Leave it up to click to ask the user again\n+        raise click.UsageError('Unable to decode to JSON.')\n \n-        try:\n-            user_dict = json.loads(\n-                user_value,\n-                object_pairs_hook=OrderedDict,\n-            )\n-        except Exception:\n-            # Leave it up to click to ask the user again\n-            raise click.UsageError('Unable to decode to JSON.')\n-\n-        if not isinstance(user_dict, dict):\n-            # Leave it up to click to ask the user again\n-            raise click.UsageError('Requires JSON dict.')\n-\n-        return user_dict\n+    if not isinstance(user_dict, dict):\n+        # Leave it up to click to ask the user again\n+        raise click.UsageError('Requires JSON dict.')\n \n-    return process_json\n+    return user_dict\n \n \n def read_user_dict(var_name, default_value):\n@@ -121,16 +114,18 @@\n \n     default_display = 'default'\n \n-    return click.prompt(\n+    user_value = click.prompt(\n         var_name,\n         default=default_display,\n         type=click.STRING,\n-        value_proc=create_value_proc(\n-            default_display,\n-            default_value,\n-        ),\n+        value_proc=process_json,\n     )\n \n+    if user_value == default_display:\n+        # Return the given default w/o any processing\n+        return default_value\n+    return user_value\n+\n \n def render_variable(env, raw, cookiecutter_dict):\n     \"\"\"Inside the prompting taken from the cookiecutter.json file, this renders\n", "issue": "Accepting default dict parameter value with no user input causes string \"default\" to be put into dict parameter\n* Cookiecutter version: 1.5\r\n* Template project url: private repo, minimal example is attached\r\n* Python version: 2.7.10\r\n* Operating System: Mac OS X 10.10.5\r\n\r\n### Description:\r\n\r\nI'm using dict parameter and trying to let it use default value. When prompted, `[default]` is shown as dict parameter default value. Then, if I respond to prompt with:\r\n\r\n1. Just enter (i.e. no user input) - project cutting fails due to an error, as cookiecutter puts `default` into dict parameter (i.e. it becomes string instead of dict).\r\n2. String \"default\" and enter - project is cooked successfully with default value.\r\n\r\nIn two words, just accepting default value for dict parameter by providing no user input causes string \"default\" to be put into a dict parameter instead of default value provided in cookiecutter.json.\r\n\r\nIf you allow some speculation, this happens because `click.prompt` [does not call `value_proc` if no user input is given](https://github.com/pallets/click/blob/master/click/termui.py#L103-L104)\r\n\r\nSee console session logs below.\r\n\r\n### What I've run:\r\n\r\nFailure:\r\n```\r\ncookiecutter minimal-example/\r\napp_name [dict_default_bug]: \r\ndict [default]: \r\nUnable to create file 'placeholder.md'\r\nError message: 'str object' has no attribute 'foo'\r\nContext: {\r\n    \"cookiecutter\": {\r\n        \"app_name\": \"dict_default_bug\", \r\n        \"dict\": \"default\"\r\n    }\r\n}\r\n```\r\n\r\nSuccess:\r\n```\r\ncookiecutter minimal-example/\r\napp_name [dict_default_bug]: \r\ndict [default]: default\r\n```\r\n[minimal-example.zip](https://github.com/audreyr/cookiecutter/files/686416/minimal-example.zip)\r\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n\"\"\"\ncookiecutter.prompt\n---------------------\n\nFunctions for prompting the user for project info.\n\"\"\"\n\nfrom collections import OrderedDict\nimport json\n\nimport click\nfrom past.builtins import basestring\n\nfrom future.utils import iteritems\n\nfrom jinja2.exceptions import UndefinedError\n\nfrom .exceptions import UndefinedVariableInTemplate\nfrom .environment import StrictEnvironment\n\n\ndef read_user_variable(var_name, default_value):\n    \"\"\"Prompt the user for the given variable and return the entered value\n    or the given default.\n\n    :param str var_name: Variable of the context to query the user\n    :param default_value: Value that will be returned if no input happens\n    \"\"\"\n    # Please see http://click.pocoo.org/4/api/#click.prompt\n    return click.prompt(var_name, default=default_value)\n\n\ndef read_user_yes_no(question, default_value):\n    \"\"\"Prompt the user to reply with 'yes' or 'no' (or equivalent values).\n\n    Note:\n      Possible choices are 'true', '1', 'yes', 'y' or 'false', '0', 'no', 'n'\n\n    :param str question: Question to the user\n    :param default_value: Value that will be returned if no input happens\n    \"\"\"\n    # Please see http://click.pocoo.org/4/api/#click.prompt\n    return click.prompt(\n        question,\n        default=default_value,\n        type=click.BOOL\n    )\n\n\ndef read_user_choice(var_name, options):\n    \"\"\"Prompt the user to choose from several options for the given variable.\n\n    The first item will be returned if no input happens.\n\n    :param str var_name: Variable as specified in the context\n    :param list options: Sequence of options that are available to select from\n    :return: Exactly one item of ``options`` that has been chosen by the user\n    \"\"\"\n    # Please see http://click.pocoo.org/4/api/#click.prompt\n    if not isinstance(options, list):\n        raise TypeError\n\n    if not options:\n        raise ValueError\n\n    choice_map = OrderedDict(\n        (u'{}'.format(i), value) for i, value in enumerate(options, 1)\n    )\n    choices = choice_map.keys()\n    default = u'1'\n\n    choice_lines = [u'{} - {}'.format(*c) for c in choice_map.items()]\n    prompt = u'\\n'.join((\n        u'Select {}:'.format(var_name),\n        u'\\n'.join(choice_lines),\n        u'Choose from {}'.format(u', '.join(choices))\n    ))\n\n    user_choice = click.prompt(\n        prompt, type=click.Choice(choices), default=default\n    )\n    return choice_map[user_choice]\n\n\ndef create_value_proc(default_display, default_value):\n    def process_json(user_value):\n        if user_value == default_display:\n            # Return the given default w/o any processing\n            return default_value\n\n        try:\n            user_dict = json.loads(\n                user_value,\n                object_pairs_hook=OrderedDict,\n            )\n        except Exception:\n            # Leave it up to click to ask the user again\n            raise click.UsageError('Unable to decode to JSON.')\n\n        if not isinstance(user_dict, dict):\n            # Leave it up to click to ask the user again\n            raise click.UsageError('Requires JSON dict.')\n\n        return user_dict\n\n    return process_json\n\n\ndef read_user_dict(var_name, default_value):\n    \"\"\"Prompt the user to provide a dictionary of data.\n\n    :param str var_name: Variable as specified in the context\n    :param default_value: Value that will be returned if no input is provided\n    :return: A Python dictionary to use in the context.\n    \"\"\"\n    # Please see http://click.pocoo.org/4/api/#click.prompt\n    if not isinstance(default_value, dict):\n        raise TypeError\n\n    default_display = 'default'\n\n    return click.prompt(\n        var_name,\n        default=default_display,\n        type=click.STRING,\n        value_proc=create_value_proc(\n            default_display,\n            default_value,\n        ),\n    )\n\n\ndef render_variable(env, raw, cookiecutter_dict):\n    \"\"\"Inside the prompting taken from the cookiecutter.json file, this renders\n    the next variable. For example, if a project_name is \"Peanut Butter\n    Cookie\", the repo_name could be be rendered with:\n\n        `{{ cookiecutter.project_name.replace(\" \", \"_\") }}`.\n\n    This is then presented to the user as the default.\n\n    :param Environment env: A Jinja2 Environment object.\n    :param str raw: The next value to be prompted for by the user.\n    :param dict cookiecutter_dict: The current context as it's gradually\n        being populated with variables.\n    :return: The rendered value for the default variable.\n    \"\"\"\n    if raw is None:\n        return None\n    elif isinstance(raw, dict):\n        return {\n            render_variable(env, k, cookiecutter_dict):\n                render_variable(env, v, cookiecutter_dict)\n            for k, v in raw.items()\n        }\n    elif isinstance(raw, list):\n        return [\n            render_variable(env, v, cookiecutter_dict)\n            for v in raw\n        ]\n    elif not isinstance(raw, basestring):\n        raw = str(raw)\n\n    template = env.from_string(raw)\n\n    rendered_template = template.render(cookiecutter=cookiecutter_dict)\n    return rendered_template\n\n\ndef prompt_choice_for_config(cookiecutter_dict, env, key, options, no_input):\n    \"\"\"Prompt the user which option to choose from the given. Each of the\n    possible choices is rendered beforehand.\n    \"\"\"\n    rendered_options = [\n        render_variable(env, raw, cookiecutter_dict) for raw in options\n    ]\n\n    if no_input:\n        return rendered_options[0]\n    return read_user_choice(key, rendered_options)\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 = StrictEnvironment(context=context)\n\n    # First pass: Handle simple and raw variables, plus choices.\n    # These must be done first because the dictionaries keys and\n    # values might refer to them.\n    for key, raw in iteritems(context[u'cookiecutter']):\n        if key.startswith(u'_'):\n            cookiecutter_dict[key] = raw\n            continue\n\n        try:\n            if isinstance(raw, list):\n                # We are dealing with a choice variable\n                val = prompt_choice_for_config(\n                    cookiecutter_dict, env, key, raw, no_input\n                )\n                cookiecutter_dict[key] = val\n            elif not isinstance(raw, dict):\n                # We are dealing with a regular variable\n                val = render_variable(env, raw, cookiecutter_dict)\n\n                if not no_input:\n                    val = read_user_variable(key, val)\n\n                cookiecutter_dict[key] = val\n        except UndefinedError as err:\n            msg = \"Unable to render variable '{}'\".format(key)\n            raise UndefinedVariableInTemplate(msg, err, context)\n\n    # Second pass; handle the dictionaries.\n    for key, raw in iteritems(context[u'cookiecutter']):\n\n        try:\n            if isinstance(raw, dict):\n                # We are dealing with a dict variable\n                val = render_variable(env, raw, cookiecutter_dict)\n\n                if not no_input:\n                    val = read_user_dict(key, val)\n\n                cookiecutter_dict[key] = val\n        except UndefinedError as err:\n            msg = \"Unable to render variable '{}'\".format(key)\n            raise UndefinedVariableInTemplate(msg, err, context)\n\n    return cookiecutter_dict\n", "path": "cookiecutter/prompt.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\n\"\"\"\ncookiecutter.prompt\n---------------------\n\nFunctions for prompting the user for project info.\n\"\"\"\n\nfrom collections import OrderedDict\nimport json\n\nimport click\nfrom past.builtins import basestring\n\nfrom future.utils import iteritems\n\nfrom jinja2.exceptions import UndefinedError\n\nfrom .exceptions import UndefinedVariableInTemplate\nfrom .environment import StrictEnvironment\n\n\ndef read_user_variable(var_name, default_value):\n    \"\"\"Prompt the user for the given variable and return the entered value\n    or the given default.\n\n    :param str var_name: Variable of the context to query the user\n    :param default_value: Value that will be returned if no input happens\n    \"\"\"\n    # Please see http://click.pocoo.org/4/api/#click.prompt\n    return click.prompt(var_name, default=default_value)\n\n\ndef read_user_yes_no(question, default_value):\n    \"\"\"Prompt the user to reply with 'yes' or 'no' (or equivalent values).\n\n    Note:\n      Possible choices are 'true', '1', 'yes', 'y' or 'false', '0', 'no', 'n'\n\n    :param str question: Question to the user\n    :param default_value: Value that will be returned if no input happens\n    \"\"\"\n    # Please see http://click.pocoo.org/4/api/#click.prompt\n    return click.prompt(\n        question,\n        default=default_value,\n        type=click.BOOL\n    )\n\n\ndef read_user_choice(var_name, options):\n    \"\"\"Prompt the user to choose from several options for the given variable.\n\n    The first item will be returned if no input happens.\n\n    :param str var_name: Variable as specified in the context\n    :param list options: Sequence of options that are available to select from\n    :return: Exactly one item of ``options`` that has been chosen by the user\n    \"\"\"\n    # Please see http://click.pocoo.org/4/api/#click.prompt\n    if not isinstance(options, list):\n        raise TypeError\n\n    if not options:\n        raise ValueError\n\n    choice_map = OrderedDict(\n        (u'{}'.format(i), value) for i, value in enumerate(options, 1)\n    )\n    choices = choice_map.keys()\n    default = u'1'\n\n    choice_lines = [u'{} - {}'.format(*c) for c in choice_map.items()]\n    prompt = u'\\n'.join((\n        u'Select {}:'.format(var_name),\n        u'\\n'.join(choice_lines),\n        u'Choose from {}'.format(u', '.join(choices))\n    ))\n\n    user_choice = click.prompt(\n        prompt, type=click.Choice(choices), default=default\n    )\n    return choice_map[user_choice]\n\n\ndef process_json(user_value):\n    try:\n        user_dict = json.loads(\n            user_value,\n            object_pairs_hook=OrderedDict,\n        )\n    except Exception:\n        # Leave it up to click to ask the user again\n        raise click.UsageError('Unable to decode to JSON.')\n\n    if not isinstance(user_dict, dict):\n        # Leave it up to click to ask the user again\n        raise click.UsageError('Requires JSON dict.')\n\n    return user_dict\n\n\ndef read_user_dict(var_name, default_value):\n    \"\"\"Prompt the user to provide a dictionary of data.\n\n    :param str var_name: Variable as specified in the context\n    :param default_value: Value that will be returned if no input is provided\n    :return: A Python dictionary to use in the context.\n    \"\"\"\n    # Please see http://click.pocoo.org/4/api/#click.prompt\n    if not isinstance(default_value, dict):\n        raise TypeError\n\n    default_display = 'default'\n\n    user_value = click.prompt(\n        var_name,\n        default=default_display,\n        type=click.STRING,\n        value_proc=process_json,\n    )\n\n    if user_value == default_display:\n        # Return the given default w/o any processing\n        return default_value\n    return user_value\n\n\ndef render_variable(env, raw, cookiecutter_dict):\n    \"\"\"Inside the prompting taken from the cookiecutter.json file, this renders\n    the next variable. For example, if a project_name is \"Peanut Butter\n    Cookie\", the repo_name could be be rendered with:\n\n        `{{ cookiecutter.project_name.replace(\" \", \"_\") }}`.\n\n    This is then presented to the user as the default.\n\n    :param Environment env: A Jinja2 Environment object.\n    :param str raw: The next value to be prompted for by the user.\n    :param dict cookiecutter_dict: The current context as it's gradually\n        being populated with variables.\n    :return: The rendered value for the default variable.\n    \"\"\"\n    if raw is None:\n        return None\n    elif isinstance(raw, dict):\n        return {\n            render_variable(env, k, cookiecutter_dict):\n                render_variable(env, v, cookiecutter_dict)\n            for k, v in raw.items()\n        }\n    elif isinstance(raw, list):\n        return [\n            render_variable(env, v, cookiecutter_dict)\n            for v in raw\n        ]\n    elif not isinstance(raw, basestring):\n        raw = str(raw)\n\n    template = env.from_string(raw)\n\n    rendered_template = template.render(cookiecutter=cookiecutter_dict)\n    return rendered_template\n\n\ndef prompt_choice_for_config(cookiecutter_dict, env, key, options, no_input):\n    \"\"\"Prompt the user which option to choose from the given. Each of the\n    possible choices is rendered beforehand.\n    \"\"\"\n    rendered_options = [\n        render_variable(env, raw, cookiecutter_dict) for raw in options\n    ]\n\n    if no_input:\n        return rendered_options[0]\n    return read_user_choice(key, rendered_options)\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 = StrictEnvironment(context=context)\n\n    # First pass: Handle simple and raw variables, plus choices.\n    # These must be done first because the dictionaries keys and\n    # values might refer to them.\n    for key, raw in iteritems(context[u'cookiecutter']):\n        if key.startswith(u'_'):\n            cookiecutter_dict[key] = raw\n            continue\n\n        try:\n            if isinstance(raw, list):\n                # We are dealing with a choice variable\n                val = prompt_choice_for_config(\n                    cookiecutter_dict, env, key, raw, no_input\n                )\n                cookiecutter_dict[key] = val\n            elif not isinstance(raw, dict):\n                # We are dealing with a regular variable\n                val = render_variable(env, raw, cookiecutter_dict)\n\n                if not no_input:\n                    val = read_user_variable(key, val)\n\n                cookiecutter_dict[key] = val\n        except UndefinedError as err:\n            msg = \"Unable to render variable '{}'\".format(key)\n            raise UndefinedVariableInTemplate(msg, err, context)\n\n    # Second pass; handle the dictionaries.\n    for key, raw in iteritems(context[u'cookiecutter']):\n\n        try:\n            if isinstance(raw, dict):\n                # We are dealing with a dict variable\n                val = render_variable(env, raw, cookiecutter_dict)\n\n                if not no_input:\n                    val = read_user_dict(key, val)\n\n                cookiecutter_dict[key] = val\n        except UndefinedError as err:\n            msg = \"Unable to render variable '{}'\".format(key)\n            raise UndefinedVariableInTemplate(msg, err, context)\n\n    return cookiecutter_dict\n", "path": "cookiecutter/prompt.py"}]}