prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  `mkdocs new` broken under python2
  current master, python 2.7.9 virtualenv
  only top directory and mkdocs.yml created, no docs dir or index.md
  
  ```
  (karasu)[lashni@orphan src]$ mkdocs new karasu
  Creating project directory: karasu
  Writing config file: karasu/mkdocs.yml
  Traceback (most recent call last):
    File "/home/lashni/dev/karasu/bin/mkdocs", line 9, in <module>
      load_entry_point('mkdocs==0.11.1', 'console_scripts', 'mkdocs')()
    File "/home/lashni/dev/karasu/src/mkdocs/mkdocs/main.py", line 74, in run_main
      main(cmd, args=sys.argv[2:], options=dict(opts))
    File "/home/lashni/dev/karasu/src/mkdocs/mkdocs/main.py", line 58, in main
      new(args, options)
    File "/home/lashni/dev/karasu/src/mkdocs/mkdocs/new.py", line 47, in new
      open(config_path, 'w', encoding='utf-8').write(config_text)
  TypeError: must be unicode, not str
  ```
  
  current master, python 3.4.3 virtualenv, files/dirs created successfully
  
  ```
  (test)[lashni@orphan src]$ mkdocs new karasu
  Creating project directory: karasu
  Writing config file: karasu/mkdocs.yml
  Writing initial docs: karasu/docs/index.md
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `mkdocs/new.py`
  Content:
  ```
  1 # coding: utf-8
  2 from __future__ import print_function
  3 import os
  4 from io import open
  5 
  6 config_text = 'site_name: My Docs\n'
  7 index_text = """# Welcome to MkDocs
  8 
  9 For full documentation visit [mkdocs.org](http://mkdocs.org).
  10 
  11 ## Commands
  12 
  13 * `mkdocs new [dir-name]` - Create a new project.
  14 * `mkdocs serve` - Start the live-reloading docs server.
  15 * `mkdocs build` - Build the documentation site.
  16 * `mkdocs help` - Print this help message.
  17 
  18 ## Project layout
  19 
  20     mkdocs.yml    # The configuration file.
  21     docs/
  22         index.md  # The documentation homepage.
  23         ...       # Other markdown pages, images and other files.
  24 """
  25 
  26 
  27 def new(args, options):
  28     if len(args) != 1:
  29         print("Usage 'mkdocs new [directory-name]'")
  30         return
  31 
  32     output_dir = args[0]
  33 
  34     docs_dir = os.path.join(output_dir, 'docs')
  35     config_path = os.path.join(output_dir, 'mkdocs.yml')
  36     index_path = os.path.join(docs_dir, 'index.md')
  37 
  38     if os.path.exists(config_path):
  39         print('Project already exists.')
  40         return
  41 
  42     if not os.path.exists(output_dir):
  43         print('Creating project directory: %s' % output_dir)
  44         os.mkdir(output_dir)
  45 
  46     print('Writing config file: %s' % config_path)
  47     open(config_path, 'w', encoding='utf-8').write(config_text)
  48 
  49     if os.path.exists(index_path):
  50         return
  51 
  52     print('Writing initial docs: %s' % index_path)
  53     if not os.path.exists(docs_dir):
  54         os.mkdir(docs_dir)
  55     open(index_path, 'w', encoding='utf-8').write(index_text)
  56
  ```
  
  Path: `mkdocs/main.py`
  Content:
  ```
  1 #!/usr/bin/env python
  2 # coding: utf-8
  3 from __future__ import print_function
  4 
  5 import logging
  6 import sys
  7 
  8 from mkdocs import __version__
  9 from mkdocs.build import build
  10 from mkdocs.config import load_config
  11 from mkdocs.exceptions import MkDocsException
  12 from mkdocs.gh_deploy import gh_deploy
  13 from mkdocs.new import new
  14 from mkdocs.serve import serve
  15 
  16 
  17 def configure_logging(options):
  18     '''When a --verbose flag is passed, increase the verbosity of mkdocs'''
  19     logger = logging.getLogger('mkdocs')
  20     logger.addHandler(logging.StreamHandler())
  21     if 'verbose' in options:
  22         logger.setLevel(logging.DEBUG)
  23     else:
  24         logger.setLevel(logging.WARNING)
  25 
  26 
  27 def arg_to_option(arg):
  28     """
  29     Convert command line arguments into two-tuples of config key/value pairs.
  30     """
  31     arg = arg.lstrip('--')
  32     option = True
  33     if '=' in arg:
  34         arg, option = arg.split('=', 1)
  35     return (arg.replace('-', '_'), option)
  36 
  37 
  38 def main(cmd, args, options=None):
  39     """
  40     Build the documentation, and optionally start the devserver.
  41     """
  42     configure_logging(options)
  43     clean_site_dir = 'clean' in options
  44     if cmd == 'serve':
  45         config = load_config(options=options)
  46         serve(config, options=options)
  47     elif cmd == 'build':
  48         config = load_config(options=options)
  49         build(config, clean_site_dir=clean_site_dir)
  50     elif cmd == 'json':
  51         config = load_config(options=options)
  52         build(config, dump_json=True, clean_site_dir=clean_site_dir)
  53     elif cmd == 'gh-deploy':
  54         config = load_config(options=options)
  55         build(config, clean_site_dir=clean_site_dir)
  56         gh_deploy(config)
  57     elif cmd == 'new':
  58         new(args, options)
  59     else:
  60         print('MkDocs (version {0})'.format(__version__))
  61         print('mkdocs [help|new|build|serve|gh-deploy|json] {options}')
  62 
  63 
  64 def run_main():
  65     """
  66     Invokes main() with the contents of sys.argv
  67 
  68     This is a separate function so it can be invoked
  69     by a setuptools console_script.
  70     """
  71     cmd = sys.argv[1] if len(sys.argv) >= 2 else None
  72     opts = [arg_to_option(arg) for arg in sys.argv[2:] if arg.startswith('--')]
  73     try:
  74         main(cmd, args=sys.argv[2:], options=dict(opts))
  75     except MkDocsException as e:
  76         print(e.args[0], file=sys.stderr)
  77 
  78 
  79 if __name__ == '__main__':
  80     run_main()
  81
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/mkdocs/main.py b/mkdocs/main.py
  --- a/mkdocs/main.py
  +++ b/mkdocs/main.py
  @@ -55,7 +55,7 @@
           build(config, clean_site_dir=clean_site_dir)
           gh_deploy(config)
       elif cmd == 'new':
  -        new(args, options)
  +        new(args)
       else:
           print('MkDocs (version {0})'.format(__version__))
           print('mkdocs [help|new|build|serve|gh-deploy|json] {options}')
  diff --git a/mkdocs/new.py b/mkdocs/new.py
  --- a/mkdocs/new.py
  +++ b/mkdocs/new.py
  @@ -1,10 +1,13 @@
   # coding: utf-8
   from __future__ import print_function
  +
   import os
   from io import open
   
  -config_text = 'site_name: My Docs\n'
  -index_text = """# Welcome to MkDocs
  +from mkdocs import compat
  +
  +config_text = compat.unicode('site_name: My Docs\n')
  +index_text = compat.unicode("""# Welcome to MkDocs
   
   For full documentation visit [mkdocs.org](http://mkdocs.org).
   
  @@ -21,10 +24,11 @@
       docs/
           index.md  # The documentation homepage.
           ...       # Other markdown pages, images and other files.
  -"""
  +""")
  +
   
  +def new(args):
   
  -def new(args, options):
       if len(args) != 1:
           print("Usage 'mkdocs new [directory-name]'")
           return
  
verification_info: {"golden_diff": "diff --git a/mkdocs/main.py b/mkdocs/main.py\n--- a/mkdocs/main.py\n+++ b/mkdocs/main.py\n@@ -55,7 +55,7 @@\n         build(config, clean_site_dir=clean_site_dir)\n         gh_deploy(config)\n     elif cmd == 'new':\n-        new(args, options)\n+        new(args)\n     else:\n         print('MkDocs (version {0})'.format(__version__))\n         print('mkdocs [help|new|build|serve|gh-deploy|json] {options}')\ndiff --git a/mkdocs/new.py b/mkdocs/new.py\n--- a/mkdocs/new.py\n+++ b/mkdocs/new.py\n@@ -1,10 +1,13 @@\n # coding: utf-8\n from __future__ import print_function\n+\n import os\n from io import open\n \n-config_text = 'site_name: My Docs\\n'\n-index_text = \"\"\"# Welcome to MkDocs\n+from mkdocs import compat\n+\n+config_text = compat.unicode('site_name: My Docs\\n')\n+index_text = compat.unicode(\"\"\"# Welcome to MkDocs\n \n For full documentation visit [mkdocs.org](http://mkdocs.org).\n \n@@ -21,10 +24,11 @@\n     docs/\n         index.md  # The documentation homepage.\n         ...       # Other markdown pages, images and other files.\n-\"\"\"\n+\"\"\")\n+\n \n+def new(args):\n \n-def new(args, options):\n     if len(args) != 1:\n         print(\"Usage 'mkdocs new [directory-name]'\")\n         return\n", "issue": "`mkdocs new` broken under python2\ncurrent master, python 2.7.9 virtualenv\nonly top directory and mkdocs.yml created, no docs dir or index.md\n\n```\n(karasu)[lashni@orphan src]$ mkdocs new karasu\nCreating project directory: karasu\nWriting config file: karasu/mkdocs.yml\nTraceback (most recent call last):\n  File \"/home/lashni/dev/karasu/bin/mkdocs\", line 9, in <module>\n    load_entry_point('mkdocs==0.11.1', 'console_scripts', 'mkdocs')()\n  File \"/home/lashni/dev/karasu/src/mkdocs/mkdocs/main.py\", line 74, in run_main\n    main(cmd, args=sys.argv[2:], options=dict(opts))\n  File \"/home/lashni/dev/karasu/src/mkdocs/mkdocs/main.py\", line 58, in main\n    new(args, options)\n  File \"/home/lashni/dev/karasu/src/mkdocs/mkdocs/new.py\", line 47, in new\n    open(config_path, 'w', encoding='utf-8').write(config_text)\nTypeError: must be unicode, not str\n```\n\ncurrent master, python 3.4.3 virtualenv, files/dirs created successfully\n\n```\n(test)[lashni@orphan src]$ mkdocs new karasu\nCreating project directory: karasu\nWriting config file: karasu/mkdocs.yml\nWriting initial docs: karasu/docs/index.md\n```\n\n", "before_files": [{"content": "# coding: utf-8\nfrom __future__ import print_function\nimport os\nfrom io import open\n\nconfig_text = 'site_name: My Docs\\n'\nindex_text = \"\"\"# Welcome to MkDocs\n\nFor full documentation visit [mkdocs.org](http://mkdocs.org).\n\n## Commands\n\n* `mkdocs new [dir-name]` - Create a new project.\n* `mkdocs serve` - Start the live-reloading docs server.\n* `mkdocs build` - Build the documentation site.\n* `mkdocs help` - Print this help message.\n\n## Project layout\n\n    mkdocs.yml    # The configuration file.\n    docs/\n        index.md  # The documentation homepage.\n        ...       # Other markdown pages, images and other files.\n\"\"\"\n\n\ndef new(args, options):\n    if len(args) != 1:\n        print(\"Usage 'mkdocs new [directory-name]'\")\n        return\n\n    output_dir = args[0]\n\n    docs_dir = os.path.join(output_dir, 'docs')\n    config_path = os.path.join(output_dir, 'mkdocs.yml')\n    index_path = os.path.join(docs_dir, 'index.md')\n\n    if os.path.exists(config_path):\n        print('Project already exists.')\n        return\n\n    if not os.path.exists(output_dir):\n        print('Creating project directory: %s' % output_dir)\n        os.mkdir(output_dir)\n\n    print('Writing config file: %s' % config_path)\n    open(config_path, 'w', encoding='utf-8').write(config_text)\n\n    if os.path.exists(index_path):\n        return\n\n    print('Writing initial docs: %s' % index_path)\n    if not os.path.exists(docs_dir):\n        os.mkdir(docs_dir)\n    open(index_path, 'w', encoding='utf-8').write(index_text)\n", "path": "mkdocs/new.py"}, {"content": "#!/usr/bin/env python\n# coding: utf-8\nfrom __future__ import print_function\n\nimport logging\nimport sys\n\nfrom mkdocs import __version__\nfrom mkdocs.build import build\nfrom mkdocs.config import load_config\nfrom mkdocs.exceptions import MkDocsException\nfrom mkdocs.gh_deploy import gh_deploy\nfrom mkdocs.new import new\nfrom mkdocs.serve import serve\n\n\ndef configure_logging(options):\n    '''When a --verbose flag is passed, increase the verbosity of mkdocs'''\n    logger = logging.getLogger('mkdocs')\n    logger.addHandler(logging.StreamHandler())\n    if 'verbose' in options:\n        logger.setLevel(logging.DEBUG)\n    else:\n        logger.setLevel(logging.WARNING)\n\n\ndef arg_to_option(arg):\n    \"\"\"\n    Convert command line arguments into two-tuples of config key/value pairs.\n    \"\"\"\n    arg = arg.lstrip('--')\n    option = True\n    if '=' in arg:\n        arg, option = arg.split('=', 1)\n    return (arg.replace('-', '_'), option)\n\n\ndef main(cmd, args, options=None):\n    \"\"\"\n    Build the documentation, and optionally start the devserver.\n    \"\"\"\n    configure_logging(options)\n    clean_site_dir = 'clean' in options\n    if cmd == 'serve':\n        config = load_config(options=options)\n        serve(config, options=options)\n    elif cmd == 'build':\n        config = load_config(options=options)\n        build(config, clean_site_dir=clean_site_dir)\n    elif cmd == 'json':\n        config = load_config(options=options)\n        build(config, dump_json=True, clean_site_dir=clean_site_dir)\n    elif cmd == 'gh-deploy':\n        config = load_config(options=options)\n        build(config, clean_site_dir=clean_site_dir)\n        gh_deploy(config)\n    elif cmd == 'new':\n        new(args, options)\n    else:\n        print('MkDocs (version {0})'.format(__version__))\n        print('mkdocs [help|new|build|serve|gh-deploy|json] {options}')\n\n\ndef run_main():\n    \"\"\"\n    Invokes main() with the contents of sys.argv\n\n    This is a separate function so it can be invoked\n    by a setuptools console_script.\n    \"\"\"\n    cmd = sys.argv[1] if len(sys.argv) >= 2 else None\n    opts = [arg_to_option(arg) for arg in sys.argv[2:] if arg.startswith('--')]\n    try:\n        main(cmd, args=sys.argv[2:], options=dict(opts))\n    except MkDocsException as e:\n        print(e.args[0], file=sys.stderr)\n\n\nif __name__ == '__main__':\n    run_main()\n", "path": "mkdocs/main.py"}], "after_files": [{"content": "# coding: utf-8\nfrom __future__ import print_function\n\nimport os\nfrom io import open\n\nfrom mkdocs import compat\n\nconfig_text = compat.unicode('site_name: My Docs\\n')\nindex_text = compat.unicode(\"\"\"# Welcome to MkDocs\n\nFor full documentation visit [mkdocs.org](http://mkdocs.org).\n\n## Commands\n\n* `mkdocs new [dir-name]` - Create a new project.\n* `mkdocs serve` - Start the live-reloading docs server.\n* `mkdocs build` - Build the documentation site.\n* `mkdocs help` - Print this help message.\n\n## Project layout\n\n    mkdocs.yml    # The configuration file.\n    docs/\n        index.md  # The documentation homepage.\n        ...       # Other markdown pages, images and other files.\n\"\"\")\n\n\ndef new(args):\n\n    if len(args) != 1:\n        print(\"Usage 'mkdocs new [directory-name]'\")\n        return\n\n    output_dir = args[0]\n\n    docs_dir = os.path.join(output_dir, 'docs')\n    config_path = os.path.join(output_dir, 'mkdocs.yml')\n    index_path = os.path.join(docs_dir, 'index.md')\n\n    if os.path.exists(config_path):\n        print('Project already exists.')\n        return\n\n    if not os.path.exists(output_dir):\n        print('Creating project directory: %s' % output_dir)\n        os.mkdir(output_dir)\n\n    print('Writing config file: %s' % config_path)\n    open(config_path, 'w', encoding='utf-8').write(config_text)\n\n    if os.path.exists(index_path):\n        return\n\n    print('Writing initial docs: %s' % index_path)\n    if not os.path.exists(docs_dir):\n        os.mkdir(docs_dir)\n    open(index_path, 'w', encoding='utf-8').write(index_text)\n", "path": "mkdocs/new.py"}, {"content": "#!/usr/bin/env python\n# coding: utf-8\nfrom __future__ import print_function\n\nimport logging\nimport sys\n\nfrom mkdocs import __version__\nfrom mkdocs.build import build\nfrom mkdocs.config import load_config\nfrom mkdocs.exceptions import MkDocsException\nfrom mkdocs.gh_deploy import gh_deploy\nfrom mkdocs.new import new\nfrom mkdocs.serve import serve\n\n\ndef configure_logging(options):\n    '''When a --verbose flag is passed, increase the verbosity of mkdocs'''\n    logger = logging.getLogger('mkdocs')\n    logger.addHandler(logging.StreamHandler())\n    if 'verbose' in options:\n        logger.setLevel(logging.DEBUG)\n    else:\n        logger.setLevel(logging.WARNING)\n\n\ndef arg_to_option(arg):\n    \"\"\"\n    Convert command line arguments into two-tuples of config key/value pairs.\n    \"\"\"\n    arg = arg.lstrip('--')\n    option = True\n    if '=' in arg:\n        arg, option = arg.split('=', 1)\n    return (arg.replace('-', '_'), option)\n\n\ndef main(cmd, args, options=None):\n    \"\"\"\n    Build the documentation, and optionally start the devserver.\n    \"\"\"\n    configure_logging(options)\n    clean_site_dir = 'clean' in options\n    if cmd == 'serve':\n        config = load_config(options=options)\n        serve(config, options=options)\n    elif cmd == 'build':\n        config = load_config(options=options)\n        build(config, clean_site_dir=clean_site_dir)\n    elif cmd == 'json':\n        config = load_config(options=options)\n        build(config, dump_json=True, clean_site_dir=clean_site_dir)\n    elif cmd == 'gh-deploy':\n        config = load_config(options=options)\n        build(config, clean_site_dir=clean_site_dir)\n        gh_deploy(config)\n    elif cmd == 'new':\n        new(args)\n    else:\n        print('MkDocs (version {0})'.format(__version__))\n        print('mkdocs [help|new|build|serve|gh-deploy|json] {options}')\n\n\ndef run_main():\n    \"\"\"\n    Invokes main() with the contents of sys.argv\n\n    This is a separate function so it can be invoked\n    by a setuptools console_script.\n    \"\"\"\n    cmd = sys.argv[1] if len(sys.argv) >= 2 else None\n    opts = [arg_to_option(arg) for arg in sys.argv[2:] if arg.startswith('--')]\n    try:\n        main(cmd, args=sys.argv[2:], options=dict(opts))\n    except MkDocsException as e:\n        print(e.args[0], file=sys.stderr)\n\n\nif __name__ == '__main__':\n    run_main()\n", "path": "mkdocs/main.py"}]}