We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Not properly outputting in MINGW
System: Windows 7 64bit

steps to reproduce:
1. Open mingw64 (git bash) 
2. Run `aws configure`
3. Observe no output
4. Hit enter 4 times
5. Observe output

It looks as if AWS CLI is thinking it is outputting text however it actually isn't.

![image](https://cloud.githubusercontent.com/assets/855184/14644114/86f4eb30-0616-11e6-835c-21cb94db9eb4.png)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `awscli/compat.py`
Content:
```
1 # Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 
3 # Licensed under the Apache License, Version 2.0 (the "License"). You
4 # may not use this file except in compliance with the License. A copy of
5 # the License is located at
6 
7 #     http://aws.amazon.com/apache2.0/
8 
9 # or in the "license" file accompanying this file. This file is
10 # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11 # ANY KIND, either express or implied. See the License for the specific
12 # language governing permissions and limitations under the License.
13 import sys
14 import os
15 import zipfile
16 
17 from botocore.compat import six
18 #import botocore.compat
19 
20 # If you ever want to import from the vendored six. Add it here and then
21 # import from awscli.compat. Also try to keep it in alphabetical order.
22 # This may get large.
23 advance_iterator = six.advance_iterator
24 PY3 = six.PY3
25 queue = six.moves.queue
26 shlex_quote = six.moves.shlex_quote
27 StringIO = six.StringIO
28 urlopen = six.moves.urllib.request.urlopen
29 
30 # Most, but not all, python installations will have zlib. This is required to
31 # compress any files we send via a push. If we can't compress, we can still
32 # package the files in a zip container.
33 try:
34     import zlib
35     ZIP_COMPRESSION_MODE = zipfile.ZIP_DEFLATED
36 except ImportError:
37     ZIP_COMPRESSION_MODE = zipfile.ZIP_STORED
38 
39 
40 class BinaryStdout(object):
41     def __enter__(self):
42         if sys.platform == "win32":
43             import msvcrt
44             self.previous_mode = msvcrt.setmode(sys.stdout.fileno(),
45                                                 os.O_BINARY)
46         return sys.stdout
47 
48     def __exit__(self, type, value, traceback):
49         if sys.platform == "win32":
50             import msvcrt
51             msvcrt.setmode(sys.stdout.fileno(), self.previous_mode)                
52 
53 
54 if six.PY3:
55     import locale
56     import urllib.parse as urlparse
57 
58     from urllib.error import URLError
59 
60     raw_input = input
61 
62     def get_stdout_text_writer():
63         return sys.stdout
64 
65     def compat_open(filename, mode='r', encoding=None):
66         """Back-port open() that accepts an encoding argument.
67 
68         In python3 this uses the built in open() and in python2 this
69         uses the io.open() function.
70 
71         If the file is not being opened in binary mode, then we'll
72         use locale.getpreferredencoding() to find the preferred
73         encoding.
74 
75         """
76         if 'b' not in mode:
77             encoding = locale.getpreferredencoding()
78         return open(filename, mode, encoding=encoding)
79 
80 else:
81     import codecs
82     import locale
83     import io
84     import urlparse
85 
86     from urllib2 import URLError
87 
88     raw_input = raw_input
89 
90     def get_stdout_text_writer():
91         # In python3, all the sys.stdout/sys.stderr streams are in text
92         # mode.  This means they expect unicode, and will encode the
93         # unicode automatically before actually writing to stdout/stderr.
94         # In python2, that's not the case.  In order to provide a consistent
95         # interface, we can create a wrapper around sys.stdout that will take
96         # unicode, and automatically encode it to the preferred encoding.
97         # That way consumers can just call get_stdout_text_writer() and write
98         # unicode to the returned stream.  Note that get_stdout_text_writer
99         # just returns sys.stdout in the PY3 section above because python3
100         # handles this.
101         return codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
102 
103     def compat_open(filename, mode='r', encoding=None):
104         # See docstring for compat_open in the PY3 section above.
105         if 'b' not in mode:
106             encoding = locale.getpreferredencoding()
107         return io.open(filename, mode, encoding=encoding)
108
```

Path: `awscli/customizations/configure/configure.py`
Content:
```
1 # Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"). You
4 # may not use this file except in compliance with the License. A copy of
5 # the License is located at
6 #
7 #     http://aws.amazon.com/apache2.0/
8 #
9 # or in the "license" file accompanying this file. This file is
10 # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11 # ANY KIND, either express or implied. See the License for the specific
12 # language governing permissions and limitations under the License.
13 import os
14 import logging
15 
16 from botocore.exceptions import ProfileNotFound
17 
18 from awscli.compat import raw_input
19 from awscli.customizations.commands import BasicCommand
20 from awscli.customizations.configure.addmodel import AddModelCommand
21 from awscli.customizations.configure.set import ConfigureSetCommand
22 from awscli.customizations.configure.get import ConfigureGetCommand
23 from awscli.customizations.configure.list import ConfigureListCommand
24 from awscli.customizations.configure.writer import ConfigFileWriter
25 
26 from . import mask_value
27 
28 
29 logger = logging.getLogger(__name__)
30 
31 
32 def register_configure_cmd(cli):
33     cli.register('building-command-table.main',
34                  ConfigureCommand.add_command)
35 
36 
37 class InteractivePrompter(object):
38 
39     def get_value(self, current_value, config_name, prompt_text=''):
40         if config_name in ('aws_access_key_id', 'aws_secret_access_key'):
41             current_value = mask_value(current_value)
42         response = raw_input("%s [%s]: " % (prompt_text, current_value))
43         if not response:
44             # If the user hits enter, we return a value of None
45             # instead of an empty string.  That way we can determine
46             # whether or not a value has changed.
47             response = None
48         return response
49 
50 
51 class ConfigureCommand(BasicCommand):
52     NAME = 'configure'
53     DESCRIPTION = BasicCommand.FROM_FILE()
54     SYNOPSIS = ('aws configure [--profile profile-name]')
55     EXAMPLES = (
56         'To create a new configuration::\n'
57         '\n'
58         '    $ aws configure\n'
59         '    AWS Access Key ID [None]: accesskey\n'
60         '    AWS Secret Access Key [None]: secretkey\n'
61         '    Default region name [None]: us-west-2\n'
62         '    Default output format [None]:\n'
63         '\n'
64         'To update just the region name::\n'
65         '\n'
66         '    $ aws configure\n'
67         '    AWS Access Key ID [****]:\n'
68         '    AWS Secret Access Key [****]:\n'
69         '    Default region name [us-west-1]: us-west-2\n'
70         '    Default output format [None]:\n'
71     )
72     SUBCOMMANDS = [
73         {'name': 'list', 'command_class': ConfigureListCommand},
74         {'name': 'get', 'command_class': ConfigureGetCommand},
75         {'name': 'set', 'command_class': ConfigureSetCommand},
76         {'name': 'add-model', 'command_class': AddModelCommand}
77     ]
78 
79     # If you want to add new values to prompt, update this list here.
80     VALUES_TO_PROMPT = [
81         # (logical_name, config_name, prompt_text)
82         ('aws_access_key_id', "AWS Access Key ID"),
83         ('aws_secret_access_key', "AWS Secret Access Key"),
84         ('region', "Default region name"),
85         ('output', "Default output format"),
86     ]
87 
88     def __init__(self, session, prompter=None, config_writer=None):
89         super(ConfigureCommand, self).__init__(session)
90         if prompter is None:
91             prompter = InteractivePrompter()
92         self._prompter = prompter
93         if config_writer is None:
94             config_writer = ConfigFileWriter()
95         self._config_writer = config_writer
96 
97     def _run_main(self, parsed_args, parsed_globals):
98         # Called when invoked with no args "aws configure"
99         new_values = {}
100         # This is the config from the config file scoped to a specific
101         # profile.
102         try:
103             config = self._session.get_scoped_config()
104         except ProfileNotFound:
105             config = {}
106         for config_name, prompt_text in self.VALUES_TO_PROMPT:
107             current_value = config.get(config_name)
108             new_value = self._prompter.get_value(current_value, config_name,
109                                                  prompt_text)
110             if new_value is not None and new_value != current_value:
111                 new_values[config_name] = new_value
112         config_filename = os.path.expanduser(
113             self._session.get_config_variable('config_file'))
114         if new_values:
115             self._write_out_creds_file_values(new_values,
116                                               parsed_globals.profile)
117             if parsed_globals.profile is not None:
118                 new_values['__section__'] = (
119                     'profile %s' % parsed_globals.profile)
120             self._config_writer.update_config(new_values, config_filename)
121 
122     def _write_out_creds_file_values(self, new_values, profile_name):
123         # The access_key/secret_key are now *always* written to the shared
124         # credentials file (~/.aws/credentials), see aws/aws-cli#847.
125         # post-conditions: ~/.aws/credentials will have the updated credential
126         # file values and new_values will have the cred vars removed.
127         credential_file_values = {}
128         if 'aws_access_key_id' in new_values:
129             credential_file_values['aws_access_key_id'] = new_values.pop(
130                 'aws_access_key_id')
131         if 'aws_secret_access_key' in new_values:
132             credential_file_values['aws_secret_access_key'] = new_values.pop(
133                 'aws_secret_access_key')
134         if credential_file_values:
135             if profile_name is not None:
136                 credential_file_values['__section__'] = profile_name
137             shared_credentials_filename = os.path.expanduser(
138                 self._session.get_config_variable('credentials_file'))
139             self._config_writer.update_config(
140                 credential_file_values,
141                 shared_credentials_filename)
142
```
--- 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/awscli/compat.py b/awscli/compat.py
--- a/awscli/compat.py
+++ b/awscli/compat.py
@@ -105,3 +105,20 @@
         if 'b' not in mode:
             encoding = locale.getpreferredencoding()
         return io.open(filename, mode, encoding=encoding)
+
+
+def compat_input(prompt):
+    """
+    Cygwin's pty's are based on pipes. Therefore, when it interacts with a Win32
+    program (such as Win32 python), what that program sees is a pipe instead of
+    a console. This is important because python buffers pipes, and so on a
+    pty-based terminal, text will not necessarily appear immediately. In most
+    cases, this isn't a big deal. But when we're doing an interactive prompt,
+    the result is that the prompts won't display until we fill the buffer. Since
+    raw_input does not flush the prompt, we need to manually write and flush it.
+
+    See https://github.com/mintty/mintty/issues/56 for more details.
+    """
+    sys.stdout.write(prompt)
+    sys.stdout.flush()
+    return raw_input()
diff --git a/awscli/customizations/configure/configure.py b/awscli/customizations/configure/configure.py
--- a/awscli/customizations/configure/configure.py
+++ b/awscli/customizations/configure/configure.py
@@ -15,7 +15,7 @@
 
 from botocore.exceptions import ProfileNotFound
 
-from awscli.compat import raw_input
+from awscli.compat import compat_input
 from awscli.customizations.commands import BasicCommand
 from awscli.customizations.configure.addmodel import AddModelCommand
 from awscli.customizations.configure.set import ConfigureSetCommand
@@ -39,7 +39,7 @@
     def get_value(self, current_value, config_name, prompt_text=''):
         if config_name in ('aws_access_key_id', 'aws_secret_access_key'):
             current_value = mask_value(current_value)
-        response = raw_input("%s [%s]: " % (prompt_text, current_value))
+        response = compat_input("%s [%s]: " % (prompt_text, current_value))
         if not response:
             # If the user hits enter, we return a value of None
             # instead of an empty string.  That way we can determine

{"golden_diff": "diff --git a/awscli/compat.py b/awscli/compat.py\n--- a/awscli/compat.py\n+++ b/awscli/compat.py\n@@ -105,3 +105,20 @@\n         if 'b' not in mode:\n             encoding = locale.getpreferredencoding()\n         return io.open(filename, mode, encoding=encoding)\n+\n+\n+def compat_input(prompt):\n+    \"\"\"\n+    Cygwin's pty's are based on pipes. Therefore, when it interacts with a Win32\n+    program (such as Win32 python), what that program sees is a pipe instead of\n+    a console. This is important because python buffers pipes, and so on a\n+    pty-based terminal, text will not necessarily appear immediately. In most\n+    cases, this isn't a big deal. But when we're doing an interactive prompt,\n+    the result is that the prompts won't display until we fill the buffer. Since\n+    raw_input does not flush the prompt, we need to manually write and flush it.\n+\n+    See https://github.com/mintty/mintty/issues/56 for more details.\n+    \"\"\"\n+    sys.stdout.write(prompt)\n+    sys.stdout.flush()\n+    return raw_input()\ndiff --git a/awscli/customizations/configure/configure.py b/awscli/customizations/configure/configure.py\n--- a/awscli/customizations/configure/configure.py\n+++ b/awscli/customizations/configure/configure.py\n@@ -15,7 +15,7 @@\n \n from botocore.exceptions import ProfileNotFound\n \n-from awscli.compat import raw_input\n+from awscli.compat import compat_input\n from awscli.customizations.commands import BasicCommand\n from awscli.customizations.configure.addmodel import AddModelCommand\n from awscli.customizations.configure.set import ConfigureSetCommand\n@@ -39,7 +39,7 @@\n     def get_value(self, current_value, config_name, prompt_text=''):\n         if config_name in ('aws_access_key_id', 'aws_secret_access_key'):\n             current_value = mask_value(current_value)\n-        response = raw_input(\"%s [%s]: \" % (prompt_text, current_value))\n+        response = compat_input(\"%s [%s]: \" % (prompt_text, current_value))\n         if not response:\n             # If the user hits enter, we return a value of None\n             # instead of an empty string.  That way we can determine\n", "issue": "Not properly outputting in MINGW\nSystem: Windows 7 64bit\n\nsteps to reproduce:\n1. Open mingw64 (git bash) \n2. Run `aws configure`\n3. Observe no output\n4. Hit enter 4 times\n5. Observe output\n\nIt looks as if AWS CLI is thinking it is outputting text however it actually isn't.\n\n![image](https://cloud.githubusercontent.com/assets/855184/14644114/86f4eb30-0616-11e6-835c-21cb94db9eb4.png)\n\n", "before_files": [{"content": "# Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n\n# Licensed under the Apache License, Version 2.0 (the \"License\"). You\n# may not use this file except in compliance with the License. A copy of\n# the License is located at\n\n#     http://aws.amazon.com/apache2.0/\n\n# or in the \"license\" file accompanying this file. This file is\n# distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n# ANY KIND, either express or implied. See the License for the specific\n# language governing permissions and limitations under the License.\nimport sys\nimport os\nimport zipfile\n\nfrom botocore.compat import six\n#import botocore.compat\n\n# If you ever want to import from the vendored six. Add it here and then\n# import from awscli.compat. Also try to keep it in alphabetical order.\n# This may get large.\nadvance_iterator = six.advance_iterator\nPY3 = six.PY3\nqueue = six.moves.queue\nshlex_quote = six.moves.shlex_quote\nStringIO = six.StringIO\nurlopen = six.moves.urllib.request.urlopen\n\n# Most, but not all, python installations will have zlib. This is required to\n# compress any files we send via a push. If we can't compress, we can still\n# package the files in a zip container.\ntry:\n    import zlib\n    ZIP_COMPRESSION_MODE = zipfile.ZIP_DEFLATED\nexcept ImportError:\n    ZIP_COMPRESSION_MODE = zipfile.ZIP_STORED\n\n\nclass BinaryStdout(object):\n    def __enter__(self):\n        if sys.platform == \"win32\":\n            import msvcrt\n            self.previous_mode = msvcrt.setmode(sys.stdout.fileno(),\n                                                os.O_BINARY)\n        return sys.stdout\n\n    def __exit__(self, type, value, traceback):\n        if sys.platform == \"win32\":\n            import msvcrt\n            msvcrt.setmode(sys.stdout.fileno(), self.previous_mode)                \n\n\nif six.PY3:\n    import locale\n    import urllib.parse as urlparse\n\n    from urllib.error import URLError\n\n    raw_input = input\n\n    def get_stdout_text_writer():\n        return sys.stdout\n\n    def compat_open(filename, mode='r', encoding=None):\n        \"\"\"Back-port open() that accepts an encoding argument.\n\n        In python3 this uses the built in open() and in python2 this\n        uses the io.open() function.\n\n        If the file is not being opened in binary mode, then we'll\n        use locale.getpreferredencoding() to find the preferred\n        encoding.\n\n        \"\"\"\n        if 'b' not in mode:\n            encoding = locale.getpreferredencoding()\n        return open(filename, mode, encoding=encoding)\n\nelse:\n    import codecs\n    import locale\n    import io\n    import urlparse\n\n    from urllib2 import URLError\n\n    raw_input = raw_input\n\n    def get_stdout_text_writer():\n        # In python3, all the sys.stdout/sys.stderr streams are in text\n        # mode.  This means they expect unicode, and will encode the\n        # unicode automatically before actually writing to stdout/stderr.\n        # In python2, that's not the case.  In order to provide a consistent\n        # interface, we can create a wrapper around sys.stdout that will take\n        # unicode, and automatically encode it to the preferred encoding.\n        # That way consumers can just call get_stdout_text_writer() and write\n        # unicode to the returned stream.  Note that get_stdout_text_writer\n        # just returns sys.stdout in the PY3 section above because python3\n        # handles this.\n        return codecs.getwriter(locale.getpreferredencoding())(sys.stdout)\n\n    def compat_open(filename, mode='r', encoding=None):\n        # See docstring for compat_open in the PY3 section above.\n        if 'b' not in mode:\n            encoding = locale.getpreferredencoding()\n        return io.open(filename, mode, encoding=encoding)\n", "path": "awscli/compat.py"}, {"content": "# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\"). You\n# may not use this file except in compliance with the License. A copy of\n# the License is located at\n#\n#     http://aws.amazon.com/apache2.0/\n#\n# or in the \"license\" file accompanying this file. This file is\n# distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n# ANY KIND, either express or implied. See the License for the specific\n# language governing permissions and limitations under the License.\nimport os\nimport logging\n\nfrom botocore.exceptions import ProfileNotFound\n\nfrom awscli.compat import raw_input\nfrom awscli.customizations.commands import BasicCommand\nfrom awscli.customizations.configure.addmodel import AddModelCommand\nfrom awscli.customizations.configure.set import ConfigureSetCommand\nfrom awscli.customizations.configure.get import ConfigureGetCommand\nfrom awscli.customizations.configure.list import ConfigureListCommand\nfrom awscli.customizations.configure.writer import ConfigFileWriter\n\nfrom . import mask_value\n\n\nlogger = logging.getLogger(__name__)\n\n\ndef register_configure_cmd(cli):\n    cli.register('building-command-table.main',\n                 ConfigureCommand.add_command)\n\n\nclass InteractivePrompter(object):\n\n    def get_value(self, current_value, config_name, prompt_text=''):\n        if config_name in ('aws_access_key_id', 'aws_secret_access_key'):\n            current_value = mask_value(current_value)\n        response = raw_input(\"%s [%s]: \" % (prompt_text, current_value))\n        if not response:\n            # If the user hits enter, we return a value of None\n            # instead of an empty string.  That way we can determine\n            # whether or not a value has changed.\n            response = None\n        return response\n\n\nclass ConfigureCommand(BasicCommand):\n    NAME = 'configure'\n    DESCRIPTION = BasicCommand.FROM_FILE()\n    SYNOPSIS = ('aws configure [--profile profile-name]')\n    EXAMPLES = (\n        'To create a new configuration::\\n'\n        '\\n'\n        '    $ aws configure\\n'\n        '    AWS Access Key ID [None]: accesskey\\n'\n        '    AWS Secret Access Key [None]: secretkey\\n'\n        '    Default region name [None]: us-west-2\\n'\n        '    Default output format [None]:\\n'\n        '\\n'\n        'To update just the region name::\\n'\n        '\\n'\n        '    $ aws configure\\n'\n        '    AWS Access Key ID [****]:\\n'\n        '    AWS Secret Access Key [****]:\\n'\n        '    Default region name [us-west-1]: us-west-2\\n'\n        '    Default output format [None]:\\n'\n    )\n    SUBCOMMANDS = [\n        {'name': 'list', 'command_class': ConfigureListCommand},\n        {'name': 'get', 'command_class': ConfigureGetCommand},\n        {'name': 'set', 'command_class': ConfigureSetCommand},\n        {'name': 'add-model', 'command_class': AddModelCommand}\n    ]\n\n    # If you want to add new values to prompt, update this list here.\n    VALUES_TO_PROMPT = [\n        # (logical_name, config_name, prompt_text)\n        ('aws_access_key_id', \"AWS Access Key ID\"),\n        ('aws_secret_access_key', \"AWS Secret Access Key\"),\n        ('region', \"Default region name\"),\n        ('output', \"Default output format\"),\n    ]\n\n    def __init__(self, session, prompter=None, config_writer=None):\n        super(ConfigureCommand, self).__init__(session)\n        if prompter is None:\n            prompter = InteractivePrompter()\n        self._prompter = prompter\n        if config_writer is None:\n            config_writer = ConfigFileWriter()\n        self._config_writer = config_writer\n\n    def _run_main(self, parsed_args, parsed_globals):\n        # Called when invoked with no args \"aws configure\"\n        new_values = {}\n        # This is the config from the config file scoped to a specific\n        # profile.\n        try:\n            config = self._session.get_scoped_config()\n        except ProfileNotFound:\n            config = {}\n        for config_name, prompt_text in self.VALUES_TO_PROMPT:\n            current_value = config.get(config_name)\n            new_value = self._prompter.get_value(current_value, config_name,\n                                                 prompt_text)\n            if new_value is not None and new_value != current_value:\n                new_values[config_name] = new_value\n        config_filename = os.path.expanduser(\n            self._session.get_config_variable('config_file'))\n        if new_values:\n            self._write_out_creds_file_values(new_values,\n                                              parsed_globals.profile)\n            if parsed_globals.profile is not None:\n                new_values['__section__'] = (\n                    'profile %s' % parsed_globals.profile)\n            self._config_writer.update_config(new_values, config_filename)\n\n    def _write_out_creds_file_values(self, new_values, profile_name):\n        # The access_key/secret_key are now *always* written to the shared\n        # credentials file (~/.aws/credentials), see aws/aws-cli#847.\n        # post-conditions: ~/.aws/credentials will have the updated credential\n        # file values and new_values will have the cred vars removed.\n        credential_file_values = {}\n        if 'aws_access_key_id' in new_values:\n            credential_file_values['aws_access_key_id'] = new_values.pop(\n                'aws_access_key_id')\n        if 'aws_secret_access_key' in new_values:\n            credential_file_values['aws_secret_access_key'] = new_values.pop(\n                'aws_secret_access_key')\n        if credential_file_values:\n            if profile_name is not None:\n                credential_file_values['__section__'] = profile_name\n            shared_credentials_filename = os.path.expanduser(\n                self._session.get_config_variable('credentials_file'))\n            self._config_writer.update_config(\n                credential_file_values,\n                shared_credentials_filename)\n", "path": "awscli/customizations/configure/configure.py"}], "after_files": [{"content": "# Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n\n# Licensed under the Apache License, Version 2.0 (the \"License\"). You\n# may not use this file except in compliance with the License. A copy of\n# the License is located at\n\n#     http://aws.amazon.com/apache2.0/\n\n# or in the \"license\" file accompanying this file. This file is\n# distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n# ANY KIND, either express or implied. See the License for the specific\n# language governing permissions and limitations under the License.\nimport sys\nimport os\nimport zipfile\n\nfrom botocore.compat import six\n#import botocore.compat\n\n# If you ever want to import from the vendored six. Add it here and then\n# import from awscli.compat. Also try to keep it in alphabetical order.\n# This may get large.\nadvance_iterator = six.advance_iterator\nPY3 = six.PY3\nqueue = six.moves.queue\nshlex_quote = six.moves.shlex_quote\nStringIO = six.StringIO\nurlopen = six.moves.urllib.request.urlopen\n\n# Most, but not all, python installations will have zlib. This is required to\n# compress any files we send via a push. If we can't compress, we can still\n# package the files in a zip container.\ntry:\n    import zlib\n    ZIP_COMPRESSION_MODE = zipfile.ZIP_DEFLATED\nexcept ImportError:\n    ZIP_COMPRESSION_MODE = zipfile.ZIP_STORED\n\n\nclass BinaryStdout(object):\n    def __enter__(self):\n        if sys.platform == \"win32\":\n            import msvcrt\n            self.previous_mode = msvcrt.setmode(sys.stdout.fileno(),\n                                                os.O_BINARY)\n        return sys.stdout\n\n    def __exit__(self, type, value, traceback):\n        if sys.platform == \"win32\":\n            import msvcrt\n            msvcrt.setmode(sys.stdout.fileno(), self.previous_mode)                \n\n\nif six.PY3:\n    import locale\n    import urllib.parse as urlparse\n\n    from urllib.error import URLError\n\n    raw_input = input\n\n    def get_stdout_text_writer():\n        return sys.stdout\n\n    def compat_open(filename, mode='r', encoding=None):\n        \"\"\"Back-port open() that accepts an encoding argument.\n\n        In python3 this uses the built in open() and in python2 this\n        uses the io.open() function.\n\n        If the file is not being opened in binary mode, then we'll\n        use locale.getpreferredencoding() to find the preferred\n        encoding.\n\n        \"\"\"\n        if 'b' not in mode:\n            encoding = locale.getpreferredencoding()\n        return open(filename, mode, encoding=encoding)\n\nelse:\n    import codecs\n    import locale\n    import io\n    import urlparse\n\n    from urllib2 import URLError\n\n    raw_input = raw_input\n\n    def get_stdout_text_writer():\n        # In python3, all the sys.stdout/sys.stderr streams are in text\n        # mode.  This means they expect unicode, and will encode the\n        # unicode automatically before actually writing to stdout/stderr.\n        # In python2, that's not the case.  In order to provide a consistent\n        # interface, we can create a wrapper around sys.stdout that will take\n        # unicode, and automatically encode it to the preferred encoding.\n        # That way consumers can just call get_stdout_text_writer() and write\n        # unicode to the returned stream.  Note that get_stdout_text_writer\n        # just returns sys.stdout in the PY3 section above because python3\n        # handles this.\n        return codecs.getwriter(locale.getpreferredencoding())(sys.stdout)\n\n    def compat_open(filename, mode='r', encoding=None):\n        # See docstring for compat_open in the PY3 section above.\n        if 'b' not in mode:\n            encoding = locale.getpreferredencoding()\n        return io.open(filename, mode, encoding=encoding)\n\n\ndef compat_input(prompt):\n    \"\"\"\n    Cygwin's pty's are based on pipes. Therefore, when it interacts with a Win32\n    program (such as Win32 python), what that program sees is a pipe instead of\n    a console. This is important because python buffers pipes, and so on a\n    pty-based terminal, text will not necessarily appear immediately. In most\n    cases, this isn't a big deal. But when we're doing an interactive prompt,\n    the result is that the prompts won't display until we fill the buffer. Since\n    raw_input does not flush the prompt, we need to manually write and flush it.\n\n    See https://github.com/mintty/mintty/issues/56 for more details.\n    \"\"\"\n    sys.stdout.write(prompt)\n    sys.stdout.flush()\n    return raw_input()\n", "path": "awscli/compat.py"}, {"content": "# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\"). You\n# may not use this file except in compliance with the License. A copy of\n# the License is located at\n#\n#     http://aws.amazon.com/apache2.0/\n#\n# or in the \"license\" file accompanying this file. This file is\n# distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF\n# ANY KIND, either express or implied. See the License for the specific\n# language governing permissions and limitations under the License.\nimport os\nimport logging\n\nfrom botocore.exceptions import ProfileNotFound\n\nfrom awscli.compat import compat_input\nfrom awscli.customizations.commands import BasicCommand\nfrom awscli.customizations.configure.addmodel import AddModelCommand\nfrom awscli.customizations.configure.set import ConfigureSetCommand\nfrom awscli.customizations.configure.get import ConfigureGetCommand\nfrom awscli.customizations.configure.list import ConfigureListCommand\nfrom awscli.customizations.configure.writer import ConfigFileWriter\n\nfrom . import mask_value\n\n\nlogger = logging.getLogger(__name__)\n\n\ndef register_configure_cmd(cli):\n    cli.register('building-command-table.main',\n                 ConfigureCommand.add_command)\n\n\nclass InteractivePrompter(object):\n\n    def get_value(self, current_value, config_name, prompt_text=''):\n        if config_name in ('aws_access_key_id', 'aws_secret_access_key'):\n            current_value = mask_value(current_value)\n        response = compat_input(\"%s [%s]: \" % (prompt_text, current_value))\n        if not response:\n            # If the user hits enter, we return a value of None\n            # instead of an empty string.  That way we can determine\n            # whether or not a value has changed.\n            response = None\n        return response\n\n\nclass ConfigureCommand(BasicCommand):\n    NAME = 'configure'\n    DESCRIPTION = BasicCommand.FROM_FILE()\n    SYNOPSIS = ('aws configure [--profile profile-name]')\n    EXAMPLES = (\n        'To create a new configuration::\\n'\n        '\\n'\n        '    $ aws configure\\n'\n        '    AWS Access Key ID [None]: accesskey\\n'\n        '    AWS Secret Access Key [None]: secretkey\\n'\n        '    Default region name [None]: us-west-2\\n'\n        '    Default output format [None]:\\n'\n        '\\n'\n        'To update just the region name::\\n'\n        '\\n'\n        '    $ aws configure\\n'\n        '    AWS Access Key ID [****]:\\n'\n        '    AWS Secret Access Key [****]:\\n'\n        '    Default region name [us-west-1]: us-west-2\\n'\n        '    Default output format [None]:\\n'\n    )\n    SUBCOMMANDS = [\n        {'name': 'list', 'command_class': ConfigureListCommand},\n        {'name': 'get', 'command_class': ConfigureGetCommand},\n        {'name': 'set', 'command_class': ConfigureSetCommand},\n        {'name': 'add-model', 'command_class': AddModelCommand}\n    ]\n\n    # If you want to add new values to prompt, update this list here.\n    VALUES_TO_PROMPT = [\n        # (logical_name, config_name, prompt_text)\n        ('aws_access_key_id', \"AWS Access Key ID\"),\n        ('aws_secret_access_key', \"AWS Secret Access Key\"),\n        ('region', \"Default region name\"),\n        ('output', \"Default output format\"),\n    ]\n\n    def __init__(self, session, prompter=None, config_writer=None):\n        super(ConfigureCommand, self).__init__(session)\n        if prompter is None:\n            prompter = InteractivePrompter()\n        self._prompter = prompter\n        if config_writer is None:\n            config_writer = ConfigFileWriter()\n        self._config_writer = config_writer\n\n    def _run_main(self, parsed_args, parsed_globals):\n        # Called when invoked with no args \"aws configure\"\n        new_values = {}\n        # This is the config from the config file scoped to a specific\n        # profile.\n        try:\n            config = self._session.get_scoped_config()\n        except ProfileNotFound:\n            config = {}\n        for config_name, prompt_text in self.VALUES_TO_PROMPT:\n            current_value = config.get(config_name)\n            new_value = self._prompter.get_value(current_value, config_name,\n                                                 prompt_text)\n            if new_value is not None and new_value != current_value:\n                new_values[config_name] = new_value\n        config_filename = os.path.expanduser(\n            self._session.get_config_variable('config_file'))\n        if new_values:\n            self._write_out_creds_file_values(new_values,\n                                              parsed_globals.profile)\n            if parsed_globals.profile is not None:\n                new_values['__section__'] = (\n                    'profile %s' % parsed_globals.profile)\n            self._config_writer.update_config(new_values, config_filename)\n\n    def _write_out_creds_file_values(self, new_values, profile_name):\n        # The access_key/secret_key are now *always* written to the shared\n        # credentials file (~/.aws/credentials), see aws/aws-cli#847.\n        # post-conditions: ~/.aws/credentials will have the updated credential\n        # file values and new_values will have the cred vars removed.\n        credential_file_values = {}\n        if 'aws_access_key_id' in new_values:\n            credential_file_values['aws_access_key_id'] = new_values.pop(\n                'aws_access_key_id')\n        if 'aws_secret_access_key' in new_values:\n            credential_file_values['aws_secret_access_key'] = new_values.pop(\n                'aws_secret_access_key')\n        if credential_file_values:\n            if profile_name is not None:\n                credential_file_values['__section__'] = profile_name\n            shared_credentials_filename = os.path.expanduser(\n                self._session.get_config_variable('credentials_file'))\n            self._config_writer.update_config(\n                credential_file_values,\n                shared_credentials_filename)\n", "path": "awscli/customizations/configure/configure.py"}]}