We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
pelican-quickstart: error with accented characters
Hello,

I've got a problem with pelican-quickstart, when I put accented characters in answers.

Here is the output I got : 

> Who will be the author of this web site? Guillaume LAMÉ
> Traceback (most recent call last):
>   File "/home/lomig/StaticGen/Pelican/bin/pelican-quickstart", line 9, in <module>
>     load_entry_point('pelican==3.2.1', 'console_scripts', 'pelican-quickstart')()
>   File "/home/lomig/StaticGen/Pelican/local/lib/python2.7/site-packages/pelican/tools/pelican_quickstart.py", line 184, in main
>     CONF['author'] = ask('Who will be the author of this web site?', answer=str_compat, default=args.author)
>   File "/home/lomig/StaticGen/Pelican/local/lib/python2.7/site-packages/pelican/tools/pelican_quickstart.py", line 57, in wrapper
>     return out.decode(sys.stdin.encoding)
>   File "/home/lomig/StaticGen/Pelican/lib/python2.7/encodings/utf_8.py", line 16, in decode
>     return codecs.utf_8_decode(input, errors, True)
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xc9' in position 13: ordinal not in range(128)

Thanks.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pelican/tools/pelican_quickstart.py`
Content:
```
1 #!/usr/bin/env python
2 
3 # -*- coding: utf-8 -*-
4 from __future__ import unicode_literals, print_function
5 import six
6 
7 import os
8 import string
9 import argparse
10 import sys
11 import codecs
12 
13 from pelican import __version__
14 
15 _TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)),
16                               "templates")
17 
18 CONF = {
19     'pelican': 'pelican',
20     'pelicanopts': '',
21     'basedir': os.curdir,
22     'ftp_host': 'localhost',
23     'ftp_user': 'anonymous',
24     'ftp_target_dir': '/',
25     'ssh_host': 'localhost',
26     'ssh_port': 22,
27     'ssh_user': 'root',
28     'ssh_target_dir': '/var/www',
29     's3_bucket': 'my_s3_bucket',
30     'dropbox_dir': '~/Dropbox/Public/',
31     'default_pagination': 10,
32     'siteurl': '',
33     'lang': 'en'
34 }
35 
36 def _input_compat(prompt):
37     if six.PY3:
38         r = input(prompt)
39     else:
40         # FIXME: why use this with @decoding_strings?
41         r = raw_input(prompt).decode('utf-8')
42     return r
43 
44 if six.PY3:
45     str_compat = str
46 else:
47     str_compat = unicode
48 
49 def decoding_strings(f):
50     def wrapper(*args, **kwargs):
51         out = f(*args, **kwargs)
52         if isinstance(out, six.string_types) and not six.PY3:
53             # todo: make encoding configurable?
54             if six.PY3:
55                 return out
56             else:
57                 return out.decode(sys.stdin.encoding)
58         return out
59     return wrapper
60 
61 
62 def get_template(name, as_encoding='utf-8'):
63     template = os.path.join(_TEMPLATES_DIR, "{0}.in".format(name))
64 
65     if not os.path.isfile(template):
66         raise RuntimeError("Cannot open {0}".format(template))
67 
68     with codecs.open(template, 'r', as_encoding) as fd:
69         line = fd.readline()
70         while line:
71             yield line
72             line = fd.readline()
73         fd.close()
74 
75 
76 @decoding_strings
77 def ask(question, answer=str_compat, default=None, l=None):
78     if answer == str_compat:
79         r = ''
80         while True:
81             if default:
82                 r = _input_compat('> {0} [{1}] '.format(question, default))
83             else:
84                 r = _input_compat('> {0} '.format(question, default))
85 
86             r = r.strip()
87 
88             if len(r) <= 0:
89                 if default:
90                     r = default
91                     break
92                 else:
93                     print('You must enter something')
94             else:
95                 if l and len(r) != l:
96                     print('You must enter a {0} letters long string'.format(l))
97                 else:
98                     break
99 
100         return r
101 
102     elif answer == bool:
103         r = None
104         while True:
105             if default is True:
106                 r = _input_compat('> {0} (Y/n) '.format(question))
107             elif default is False:
108                 r = _input_compat('> {0} (y/N) '.format(question))
109             else:
110                 r = _input_compat('> {0} (y/n) '.format(question))
111 
112             r = r.strip().lower()
113 
114             if r in ('y', 'yes'):
115                 r = True
116                 break
117             elif r in ('n', 'no'):
118                 r = False
119                 break
120             elif not r:
121                 r = default
122                 break
123             else:
124                 print("You must answer 'yes' or 'no'")
125         return r
126     elif answer == int:
127         r = None
128         while True:
129             if default:
130                 r = _input_compat('> {0} [{1}] '.format(question, default))
131             else:
132                 r = _input_compat('> {0} '.format(question))
133 
134             r = r.strip()
135 
136             if not r:
137                 r = default
138                 break
139 
140             try:
141                 r = int(r)
142                 break
143             except:
144                 print('You must enter an integer')
145         return r
146     else:
147         raise NotImplemented('Argument `answer` must be str_compat, bool, or integer')
148 
149 
150 def main():
151     parser = argparse.ArgumentParser(
152         description="A kickstarter for Pelican",
153         formatter_class=argparse.ArgumentDefaultsHelpFormatter)
154     parser.add_argument('-p', '--path', default=os.curdir,
155             help="The path to generate the blog into")
156     parser.add_argument('-t', '--title', metavar="title",
157             help='Set the title of the website')
158     parser.add_argument('-a', '--author', metavar="author",
159             help='Set the author name of the website')
160     parser.add_argument('-l', '--lang', metavar="lang",
161             help='Set the default web site language')
162 
163     args = parser.parse_args()
164 
165     print('''Welcome to pelican-quickstart v{v}.
166 
167 This script will help you create a new Pelican-based website.
168 
169 Please answer the following questions so this script can generate the files
170 needed by Pelican.
171 
172     '''.format(v=__version__))
173 
174     project = os.path.join(
175         os.environ.get('VIRTUAL_ENV', os.curdir), '.project')
176     if os.path.isfile(project):
177         CONF['basedir'] = open(project, 'r').read().rstrip("\n")
178         print('Using project associated with current virtual environment.'
179               'Will save to:\n%s\n' % CONF['basedir'])
180     else:
181         CONF['basedir'] = os.path.abspath(ask('Where do you want to create your new web site?', answer=str_compat, default=args.path))
182 
183     CONF['sitename'] = ask('What will be the title of this web site?', answer=str_compat, default=args.title)
184     CONF['author'] = ask('Who will be the author of this web site?', answer=str_compat, default=args.author)
185     CONF['lang'] = ask('What will be the default language of this web site?', str_compat, args.lang or CONF['lang'], 2)
186 
187     if ask('Do you want to specify a URL prefix? e.g., http://example.com  ', answer=bool, default=True):
188         CONF['siteurl'] = ask('What is your URL prefix? (see above example; no trailing slash)', str_compat, CONF['siteurl'])
189 
190     CONF['with_pagination'] = ask('Do you want to enable article pagination?', bool, bool(CONF['default_pagination']))
191 
192     if CONF['with_pagination']:
193         CONF['default_pagination'] = ask('How many articles per page do you want?', int, CONF['default_pagination'])
194     else:
195         CONF['default_pagination'] = False
196 
197     mkfile = ask('Do you want to generate a Makefile to easily manage your website?', bool, True)
198     develop = ask('Do you want an auto-reload & simpleHTTP script to assist with theme and site development?', bool, True)
199 
200     if mkfile:
201         if ask('Do you want to upload your website using FTP?', answer=bool, default=False):
202             CONF['ftp_host'] = ask('What is the hostname of your FTP server?', str_compat, CONF['ftp_host'])
203             CONF['ftp_user'] = ask('What is your username on that server?', str_compat, CONF['ftp_user'])
204             CONF['ftp_target_dir'] = ask('Where do you want to put your web site on that server?', str_compat, CONF['ftp_target_dir'])
205         if ask('Do you want to upload your website using SSH?', answer=bool, default=False):
206             CONF['ssh_host'] = ask('What is the hostname of your SSH server?', str_compat, CONF['ssh_host'])
207             CONF['ssh_port'] = ask('What is the port of your SSH server?', int, CONF['ssh_port'])
208             CONF['ssh_user'] = ask('What is your username on that server?', str_compat, CONF['ssh_user'])
209             CONF['ssh_target_dir'] = ask('Where do you want to put your web site on that server?', str_compat, CONF['ssh_target_dir'])
210         if ask('Do you want to upload your website using Dropbox?', answer=bool, default=False):
211             CONF['dropbox_dir'] = ask('Where is your Dropbox directory?', str_compat, CONF['dropbox_dir'])
212         if ask('Do you want to upload your website using S3?', answer=bool, default=False):
213             CONF['s3_bucket'] = ask('What is the name of your S3 bucket?', str_compat, CONF['s3_bucket'])
214 
215     try:
216         os.makedirs(os.path.join(CONF['basedir'], 'content'))
217     except OSError as e:
218         print('Error: {0}'.format(e))
219 
220     try:
221         os.makedirs(os.path.join(CONF['basedir'], 'output'))
222     except OSError as e:
223         print('Error: {0}'.format(e))
224 
225     try:
226         with codecs.open(os.path.join(CONF['basedir'], 'pelicanconf.py'), 'w', 'utf-8') as fd:
227             conf_python = dict()
228             for key, value in CONF.items():
229                 conf_python[key] = repr(value)
230 
231             for line in get_template('pelicanconf.py'):
232                 template = string.Template(line)
233                 fd.write(template.safe_substitute(conf_python))
234             fd.close()
235     except OSError as e:
236         print('Error: {0}'.format(e))
237 
238     try:
239         with codecs.open(os.path.join(CONF['basedir'], 'publishconf.py'), 'w', 'utf-8') as fd:
240             for line in get_template('publishconf.py'):
241                 template = string.Template(line)
242                 fd.write(template.safe_substitute(CONF))
243             fd.close()
244     except OSError as e:
245         print('Error: {0}'.format(e))
246 
247     if mkfile:
248         try:
249             with codecs.open(os.path.join(CONF['basedir'], 'Makefile'), 'w', 'utf-8') as fd:
250                 mkfile_template_name = 'Makefile'
251                 py_v = 'PY=python'
252                 if six.PY3:
253                     py_v = 'PY=python3'
254                 template = string.Template(py_v)
255                 fd.write(template.safe_substitute(CONF))
256                 fd.write('\n')
257                 for line in get_template(mkfile_template_name):
258                     template = string.Template(line)
259                     fd.write(template.safe_substitute(CONF))
260                 fd.close()
261         except OSError as e:
262             print('Error: {0}'.format(e))
263 
264     if develop:
265         conf_shell = dict()
266         for key, value in CONF.items():
267             if isinstance(value, six.string_types) and ' ' in value:
268                 value = '"' + value.replace('"', '\\"') + '"'
269             conf_shell[key] = value
270         try:
271             with codecs.open(os.path.join(CONF['basedir'], 'develop_server.sh'), 'w', 'utf-8') as fd:
272                 lines = list(get_template('develop_server.sh'))
273                 py_v = 'PY=python\n'
274                 if six.PY3:
275                     py_v = 'PY=python3\n'
276                 lines = lines[:4] + [py_v] + lines[4:]
277                 for line in lines:
278                     template = string.Template(line)
279                     fd.write(template.safe_substitute(conf_shell))
280                 fd.close()
281                 os.chmod((os.path.join(CONF['basedir'], 'develop_server.sh')), 493) # mode 0o755
282         except OSError as e:
283             print('Error: {0}'.format(e))
284 
285     print('Done. Your new project is available at %s' % CONF['basedir'])
286
```
--- 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/pelican/tools/pelican_quickstart.py b/pelican/tools/pelican_quickstart.py
--- a/pelican/tools/pelican_quickstart.py
+++ b/pelican/tools/pelican_quickstart.py
@@ -37,8 +37,7 @@
     if six.PY3:
         r = input(prompt)
     else:
-        # FIXME: why use this with @decoding_strings?
-        r = raw_input(prompt).decode('utf-8')
+        r = raw_input(prompt)
     return r
 
 if six.PY3:

{"golden_diff": "diff --git a/pelican/tools/pelican_quickstart.py b/pelican/tools/pelican_quickstart.py\n--- a/pelican/tools/pelican_quickstart.py\n+++ b/pelican/tools/pelican_quickstart.py\n@@ -37,8 +37,7 @@\n     if six.PY3:\n         r = input(prompt)\n     else:\n-        # FIXME: why use this with @decoding_strings?\n-        r = raw_input(prompt).decode('utf-8')\n+        r = raw_input(prompt)\n     return r\n \n if six.PY3:\n", "issue": "pelican-quickstart: error with accented characters\nHello,\n\nI've got a problem with pelican-quickstart, when I put accented characters in answers.\n\nHere is the output I got : \n\n> Who will be the author of this web site? Guillaume LAM\u00c9\n> Traceback (most recent call last):\n>   File \"/home/lomig/StaticGen/Pelican/bin/pelican-quickstart\", line 9, in <module>\n>     load_entry_point('pelican==3.2.1', 'console_scripts', 'pelican-quickstart')()\n>   File \"/home/lomig/StaticGen/Pelican/local/lib/python2.7/site-packages/pelican/tools/pelican_quickstart.py\", line 184, in main\n>     CONF['author'] = ask('Who will be the author of this web site?', answer=str_compat, default=args.author)\n>   File \"/home/lomig/StaticGen/Pelican/local/lib/python2.7/site-packages/pelican/tools/pelican_quickstart.py\", line 57, in wrapper\n>     return out.decode(sys.stdin.encoding)\n>   File \"/home/lomig/StaticGen/Pelican/lib/python2.7/encodings/utf_8.py\", line 16, in decode\n>     return codecs.utf_8_decode(input, errors, True)\n> UnicodeEncodeError: 'ascii' codec can't encode character u'\\xc9' in position 13: ordinal not in range(128)\n\nThanks.\n\n", "before_files": [{"content": "#!/usr/bin/env python\n\n# -*- coding: utf-8 -*-\nfrom __future__ import unicode_literals, print_function\nimport six\n\nimport os\nimport string\nimport argparse\nimport sys\nimport codecs\n\nfrom pelican import __version__\n\n_TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)),\n                              \"templates\")\n\nCONF = {\n    'pelican': 'pelican',\n    'pelicanopts': '',\n    'basedir': os.curdir,\n    'ftp_host': 'localhost',\n    'ftp_user': 'anonymous',\n    'ftp_target_dir': '/',\n    'ssh_host': 'localhost',\n    'ssh_port': 22,\n    'ssh_user': 'root',\n    'ssh_target_dir': '/var/www',\n    's3_bucket': 'my_s3_bucket',\n    'dropbox_dir': '~/Dropbox/Public/',\n    'default_pagination': 10,\n    'siteurl': '',\n    'lang': 'en'\n}\n\ndef _input_compat(prompt):\n    if six.PY3:\n        r = input(prompt)\n    else:\n        # FIXME: why use this with @decoding_strings?\n        r = raw_input(prompt).decode('utf-8')\n    return r\n\nif six.PY3:\n    str_compat = str\nelse:\n    str_compat = unicode\n\ndef decoding_strings(f):\n    def wrapper(*args, **kwargs):\n        out = f(*args, **kwargs)\n        if isinstance(out, six.string_types) and not six.PY3:\n            # todo: make encoding configurable?\n            if six.PY3:\n                return out\n            else:\n                return out.decode(sys.stdin.encoding)\n        return out\n    return wrapper\n\n\ndef get_template(name, as_encoding='utf-8'):\n    template = os.path.join(_TEMPLATES_DIR, \"{0}.in\".format(name))\n\n    if not os.path.isfile(template):\n        raise RuntimeError(\"Cannot open {0}\".format(template))\n\n    with codecs.open(template, 'r', as_encoding) as fd:\n        line = fd.readline()\n        while line:\n            yield line\n            line = fd.readline()\n        fd.close()\n\n\n@decoding_strings\ndef ask(question, answer=str_compat, default=None, l=None):\n    if answer == str_compat:\n        r = ''\n        while True:\n            if default:\n                r = _input_compat('> {0} [{1}] '.format(question, default))\n            else:\n                r = _input_compat('> {0} '.format(question, default))\n\n            r = r.strip()\n\n            if len(r) <= 0:\n                if default:\n                    r = default\n                    break\n                else:\n                    print('You must enter something')\n            else:\n                if l and len(r) != l:\n                    print('You must enter a {0} letters long string'.format(l))\n                else:\n                    break\n\n        return r\n\n    elif answer == bool:\n        r = None\n        while True:\n            if default is True:\n                r = _input_compat('> {0} (Y/n) '.format(question))\n            elif default is False:\n                r = _input_compat('> {0} (y/N) '.format(question))\n            else:\n                r = _input_compat('> {0} (y/n) '.format(question))\n\n            r = r.strip().lower()\n\n            if r in ('y', 'yes'):\n                r = True\n                break\n            elif r in ('n', 'no'):\n                r = False\n                break\n            elif not r:\n                r = default\n                break\n            else:\n                print(\"You must answer 'yes' or 'no'\")\n        return r\n    elif answer == int:\n        r = None\n        while True:\n            if default:\n                r = _input_compat('> {0} [{1}] '.format(question, default))\n            else:\n                r = _input_compat('> {0} '.format(question))\n\n            r = r.strip()\n\n            if not r:\n                r = default\n                break\n\n            try:\n                r = int(r)\n                break\n            except:\n                print('You must enter an integer')\n        return r\n    else:\n        raise NotImplemented('Argument `answer` must be str_compat, bool, or integer')\n\n\ndef main():\n    parser = argparse.ArgumentParser(\n        description=\"A kickstarter for Pelican\",\n        formatter_class=argparse.ArgumentDefaultsHelpFormatter)\n    parser.add_argument('-p', '--path', default=os.curdir,\n            help=\"The path to generate the blog into\")\n    parser.add_argument('-t', '--title', metavar=\"title\",\n            help='Set the title of the website')\n    parser.add_argument('-a', '--author', metavar=\"author\",\n            help='Set the author name of the website')\n    parser.add_argument('-l', '--lang', metavar=\"lang\",\n            help='Set the default web site language')\n\n    args = parser.parse_args()\n\n    print('''Welcome to pelican-quickstart v{v}.\n\nThis script will help you create a new Pelican-based website.\n\nPlease answer the following questions so this script can generate the files\nneeded by Pelican.\n\n    '''.format(v=__version__))\n\n    project = os.path.join(\n        os.environ.get('VIRTUAL_ENV', os.curdir), '.project')\n    if os.path.isfile(project):\n        CONF['basedir'] = open(project, 'r').read().rstrip(\"\\n\")\n        print('Using project associated with current virtual environment.'\n              'Will save to:\\n%s\\n' % CONF['basedir'])\n    else:\n        CONF['basedir'] = os.path.abspath(ask('Where do you want to create your new web site?', answer=str_compat, default=args.path))\n\n    CONF['sitename'] = ask('What will be the title of this web site?', answer=str_compat, default=args.title)\n    CONF['author'] = ask('Who will be the author of this web site?', answer=str_compat, default=args.author)\n    CONF['lang'] = ask('What will be the default language of this web site?', str_compat, args.lang or CONF['lang'], 2)\n\n    if ask('Do you want to specify a URL prefix? e.g., http://example.com  ', answer=bool, default=True):\n        CONF['siteurl'] = ask('What is your URL prefix? (see above example; no trailing slash)', str_compat, CONF['siteurl'])\n\n    CONF['with_pagination'] = ask('Do you want to enable article pagination?', bool, bool(CONF['default_pagination']))\n\n    if CONF['with_pagination']:\n        CONF['default_pagination'] = ask('How many articles per page do you want?', int, CONF['default_pagination'])\n    else:\n        CONF['default_pagination'] = False\n\n    mkfile = ask('Do you want to generate a Makefile to easily manage your website?', bool, True)\n    develop = ask('Do you want an auto-reload & simpleHTTP script to assist with theme and site development?', bool, True)\n\n    if mkfile:\n        if ask('Do you want to upload your website using FTP?', answer=bool, default=False):\n            CONF['ftp_host'] = ask('What is the hostname of your FTP server?', str_compat, CONF['ftp_host'])\n            CONF['ftp_user'] = ask('What is your username on that server?', str_compat, CONF['ftp_user'])\n            CONF['ftp_target_dir'] = ask('Where do you want to put your web site on that server?', str_compat, CONF['ftp_target_dir'])\n        if ask('Do you want to upload your website using SSH?', answer=bool, default=False):\n            CONF['ssh_host'] = ask('What is the hostname of your SSH server?', str_compat, CONF['ssh_host'])\n            CONF['ssh_port'] = ask('What is the port of your SSH server?', int, CONF['ssh_port'])\n            CONF['ssh_user'] = ask('What is your username on that server?', str_compat, CONF['ssh_user'])\n            CONF['ssh_target_dir'] = ask('Where do you want to put your web site on that server?', str_compat, CONF['ssh_target_dir'])\n        if ask('Do you want to upload your website using Dropbox?', answer=bool, default=False):\n            CONF['dropbox_dir'] = ask('Where is your Dropbox directory?', str_compat, CONF['dropbox_dir'])\n        if ask('Do you want to upload your website using S3?', answer=bool, default=False):\n            CONF['s3_bucket'] = ask('What is the name of your S3 bucket?', str_compat, CONF['s3_bucket'])\n\n    try:\n        os.makedirs(os.path.join(CONF['basedir'], 'content'))\n    except OSError as e:\n        print('Error: {0}'.format(e))\n\n    try:\n        os.makedirs(os.path.join(CONF['basedir'], 'output'))\n    except OSError as e:\n        print('Error: {0}'.format(e))\n\n    try:\n        with codecs.open(os.path.join(CONF['basedir'], 'pelicanconf.py'), 'w', 'utf-8') as fd:\n            conf_python = dict()\n            for key, value in CONF.items():\n                conf_python[key] = repr(value)\n\n            for line in get_template('pelicanconf.py'):\n                template = string.Template(line)\n                fd.write(template.safe_substitute(conf_python))\n            fd.close()\n    except OSError as e:\n        print('Error: {0}'.format(e))\n\n    try:\n        with codecs.open(os.path.join(CONF['basedir'], 'publishconf.py'), 'w', 'utf-8') as fd:\n            for line in get_template('publishconf.py'):\n                template = string.Template(line)\n                fd.write(template.safe_substitute(CONF))\n            fd.close()\n    except OSError as e:\n        print('Error: {0}'.format(e))\n\n    if mkfile:\n        try:\n            with codecs.open(os.path.join(CONF['basedir'], 'Makefile'), 'w', 'utf-8') as fd:\n                mkfile_template_name = 'Makefile'\n                py_v = 'PY=python'\n                if six.PY3:\n                    py_v = 'PY=python3'\n                template = string.Template(py_v)\n                fd.write(template.safe_substitute(CONF))\n                fd.write('\\n')\n                for line in get_template(mkfile_template_name):\n                    template = string.Template(line)\n                    fd.write(template.safe_substitute(CONF))\n                fd.close()\n        except OSError as e:\n            print('Error: {0}'.format(e))\n\n    if develop:\n        conf_shell = dict()\n        for key, value in CONF.items():\n            if isinstance(value, six.string_types) and ' ' in value:\n                value = '\"' + value.replace('\"', '\\\\\"') + '\"'\n            conf_shell[key] = value\n        try:\n            with codecs.open(os.path.join(CONF['basedir'], 'develop_server.sh'), 'w', 'utf-8') as fd:\n                lines = list(get_template('develop_server.sh'))\n                py_v = 'PY=python\\n'\n                if six.PY3:\n                    py_v = 'PY=python3\\n'\n                lines = lines[:4] + [py_v] + lines[4:]\n                for line in lines:\n                    template = string.Template(line)\n                    fd.write(template.safe_substitute(conf_shell))\n                fd.close()\n                os.chmod((os.path.join(CONF['basedir'], 'develop_server.sh')), 493) # mode 0o755\n        except OSError as e:\n            print('Error: {0}'.format(e))\n\n    print('Done. Your new project is available at %s' % CONF['basedir'])\n", "path": "pelican/tools/pelican_quickstart.py"}], "after_files": [{"content": "#!/usr/bin/env python\n\n# -*- coding: utf-8 -*-\nfrom __future__ import unicode_literals, print_function\nimport six\n\nimport os\nimport string\nimport argparse\nimport sys\nimport codecs\n\nfrom pelican import __version__\n\n_TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)),\n                              \"templates\")\n\nCONF = {\n    'pelican': 'pelican',\n    'pelicanopts': '',\n    'basedir': os.curdir,\n    'ftp_host': 'localhost',\n    'ftp_user': 'anonymous',\n    'ftp_target_dir': '/',\n    'ssh_host': 'localhost',\n    'ssh_port': 22,\n    'ssh_user': 'root',\n    'ssh_target_dir': '/var/www',\n    's3_bucket': 'my_s3_bucket',\n    'dropbox_dir': '~/Dropbox/Public/',\n    'default_pagination': 10,\n    'siteurl': '',\n    'lang': 'en'\n}\n\ndef _input_compat(prompt):\n    if six.PY3:\n        r = input(prompt)\n    else:\n        r = raw_input(prompt)\n    return r\n\nif six.PY3:\n    str_compat = str\nelse:\n    str_compat = unicode\n\ndef decoding_strings(f):\n    def wrapper(*args, **kwargs):\n        out = f(*args, **kwargs)\n        if isinstance(out, six.string_types) and not six.PY3:\n            # todo: make encoding configurable?\n            if six.PY3:\n                return out\n            else:\n                return out.decode(sys.stdin.encoding)\n        return out\n    return wrapper\n\n\ndef get_template(name, as_encoding='utf-8'):\n    template = os.path.join(_TEMPLATES_DIR, \"{0}.in\".format(name))\n\n    if not os.path.isfile(template):\n        raise RuntimeError(\"Cannot open {0}\".format(template))\n\n    with codecs.open(template, 'r', as_encoding) as fd:\n        line = fd.readline()\n        while line:\n            yield line\n            line = fd.readline()\n        fd.close()\n\n\n@decoding_strings\ndef ask(question, answer=str_compat, default=None, l=None):\n    if answer == str_compat:\n        r = ''\n        while True:\n            if default:\n                r = _input_compat('> {0} [{1}] '.format(question, default))\n            else:\n                r = _input_compat('> {0} '.format(question, default))\n\n            r = r.strip()\n\n            if len(r) <= 0:\n                if default:\n                    r = default\n                    break\n                else:\n                    print('You must enter something')\n            else:\n                if l and len(r) != l:\n                    print('You must enter a {0} letters long string'.format(l))\n                else:\n                    break\n\n        return r\n\n    elif answer == bool:\n        r = None\n        while True:\n            if default is True:\n                r = _input_compat('> {0} (Y/n) '.format(question))\n            elif default is False:\n                r = _input_compat('> {0} (y/N) '.format(question))\n            else:\n                r = _input_compat('> {0} (y/n) '.format(question))\n\n            r = r.strip().lower()\n\n            if r in ('y', 'yes'):\n                r = True\n                break\n            elif r in ('n', 'no'):\n                r = False\n                break\n            elif not r:\n                r = default\n                break\n            else:\n                print(\"You must answer 'yes' or 'no'\")\n        return r\n    elif answer == int:\n        r = None\n        while True:\n            if default:\n                r = _input_compat('> {0} [{1}] '.format(question, default))\n            else:\n                r = _input_compat('> {0} '.format(question))\n\n            r = r.strip()\n\n            if not r:\n                r = default\n                break\n\n            try:\n                r = int(r)\n                break\n            except:\n                print('You must enter an integer')\n        return r\n    else:\n        raise NotImplemented('Argument `answer` must be str_compat, bool, or integer')\n\n\ndef main():\n    parser = argparse.ArgumentParser(\n        description=\"A kickstarter for Pelican\",\n        formatter_class=argparse.ArgumentDefaultsHelpFormatter)\n    parser.add_argument('-p', '--path', default=os.curdir,\n            help=\"The path to generate the blog into\")\n    parser.add_argument('-t', '--title', metavar=\"title\",\n            help='Set the title of the website')\n    parser.add_argument('-a', '--author', metavar=\"author\",\n            help='Set the author name of the website')\n    parser.add_argument('-l', '--lang', metavar=\"lang\",\n            help='Set the default web site language')\n\n    args = parser.parse_args()\n\n    print('''Welcome to pelican-quickstart v{v}.\n\nThis script will help you create a new Pelican-based website.\n\nPlease answer the following questions so this script can generate the files\nneeded by Pelican.\n\n    '''.format(v=__version__))\n\n    project = os.path.join(\n        os.environ.get('VIRTUAL_ENV', os.curdir), '.project')\n    if os.path.isfile(project):\n        CONF['basedir'] = open(project, 'r').read().rstrip(\"\\n\")\n        print('Using project associated with current virtual environment.'\n              'Will save to:\\n%s\\n' % CONF['basedir'])\n    else:\n        CONF['basedir'] = os.path.abspath(ask('Where do you want to create your new web site?', answer=str_compat, default=args.path))\n\n    CONF['sitename'] = ask('What will be the title of this web site?', answer=str_compat, default=args.title)\n    CONF['author'] = ask('Who will be the author of this web site?', answer=str_compat, default=args.author)\n    CONF['lang'] = ask('What will be the default language of this web site?', str_compat, args.lang or CONF['lang'], 2)\n\n    if ask('Do you want to specify a URL prefix? e.g., http://example.com  ', answer=bool, default=True):\n        CONF['siteurl'] = ask('What is your URL prefix? (see above example; no trailing slash)', str_compat, CONF['siteurl'])\n\n    CONF['with_pagination'] = ask('Do you want to enable article pagination?', bool, bool(CONF['default_pagination']))\n\n    if CONF['with_pagination']:\n        CONF['default_pagination'] = ask('How many articles per page do you want?', int, CONF['default_pagination'])\n    else:\n        CONF['default_pagination'] = False\n\n    mkfile = ask('Do you want to generate a Makefile to easily manage your website?', bool, True)\n    develop = ask('Do you want an auto-reload & simpleHTTP script to assist with theme and site development?', bool, True)\n\n    if mkfile:\n        if ask('Do you want to upload your website using FTP?', answer=bool, default=False):\n            CONF['ftp_host'] = ask('What is the hostname of your FTP server?', str_compat, CONF['ftp_host'])\n            CONF['ftp_user'] = ask('What is your username on that server?', str_compat, CONF['ftp_user'])\n            CONF['ftp_target_dir'] = ask('Where do you want to put your web site on that server?', str_compat, CONF['ftp_target_dir'])\n        if ask('Do you want to upload your website using SSH?', answer=bool, default=False):\n            CONF['ssh_host'] = ask('What is the hostname of your SSH server?', str_compat, CONF['ssh_host'])\n            CONF['ssh_port'] = ask('What is the port of your SSH server?', int, CONF['ssh_port'])\n            CONF['ssh_user'] = ask('What is your username on that server?', str_compat, CONF['ssh_user'])\n            CONF['ssh_target_dir'] = ask('Where do you want to put your web site on that server?', str_compat, CONF['ssh_target_dir'])\n        if ask('Do you want to upload your website using Dropbox?', answer=bool, default=False):\n            CONF['dropbox_dir'] = ask('Where is your Dropbox directory?', str_compat, CONF['dropbox_dir'])\n        if ask('Do you want to upload your website using S3?', answer=bool, default=False):\n            CONF['s3_bucket'] = ask('What is the name of your S3 bucket?', str_compat, CONF['s3_bucket'])\n\n    try:\n        os.makedirs(os.path.join(CONF['basedir'], 'content'))\n    except OSError as e:\n        print('Error: {0}'.format(e))\n\n    try:\n        os.makedirs(os.path.join(CONF['basedir'], 'output'))\n    except OSError as e:\n        print('Error: {0}'.format(e))\n\n    try:\n        with codecs.open(os.path.join(CONF['basedir'], 'pelicanconf.py'), 'w', 'utf-8') as fd:\n            conf_python = dict()\n            for key, value in CONF.items():\n                conf_python[key] = repr(value)\n\n            for line in get_template('pelicanconf.py'):\n                template = string.Template(line)\n                fd.write(template.safe_substitute(conf_python))\n            fd.close()\n    except OSError as e:\n        print('Error: {0}'.format(e))\n\n    try:\n        with codecs.open(os.path.join(CONF['basedir'], 'publishconf.py'), 'w', 'utf-8') as fd:\n            for line in get_template('publishconf.py'):\n                template = string.Template(line)\n                fd.write(template.safe_substitute(CONF))\n            fd.close()\n    except OSError as e:\n        print('Error: {0}'.format(e))\n\n    if mkfile:\n        try:\n            with codecs.open(os.path.join(CONF['basedir'], 'Makefile'), 'w', 'utf-8') as fd:\n                mkfile_template_name = 'Makefile'\n                py_v = 'PY=python'\n                if six.PY3:\n                    py_v = 'PY=python3'\n                template = string.Template(py_v)\n                fd.write(template.safe_substitute(CONF))\n                fd.write('\\n')\n                for line in get_template(mkfile_template_name):\n                    template = string.Template(line)\n                    fd.write(template.safe_substitute(CONF))\n                fd.close()\n        except OSError as e:\n            print('Error: {0}'.format(e))\n\n    if develop:\n        conf_shell = dict()\n        for key, value in CONF.items():\n            if isinstance(value, six.string_types) and ' ' in value:\n                value = '\"' + value.replace('\"', '\\\\\"') + '\"'\n            conf_shell[key] = value\n        try:\n            with codecs.open(os.path.join(CONF['basedir'], 'develop_server.sh'), 'w', 'utf-8') as fd:\n                lines = list(get_template('develop_server.sh'))\n                py_v = 'PY=python\\n'\n                if six.PY3:\n                    py_v = 'PY=python3\\n'\n                lines = lines[:4] + [py_v] + lines[4:]\n                for line in lines:\n                    template = string.Template(line)\n                    fd.write(template.safe_substitute(conf_shell))\n                fd.close()\n                os.chmod((os.path.join(CONF['basedir'], 'develop_server.sh')), 493) # mode 0o755\n        except OSError as e:\n            print('Error: {0}'.format(e))\n\n    print('Done. Your new project is available at %s' % CONF['basedir'])\n", "path": "pelican/tools/pelican_quickstart.py"}]}