128040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# Copyright (C) 2010 Apple Inc. All rights reserved. 228040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# 328040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# Redistribution and use in source and binary forms, with or without 428040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# modification, are permitted provided that the following conditions 528040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# are met: 628040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# 1. Redistributions of source code must retain the above copyright 728040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# notice, this list of conditions and the following disclaimer. 828040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# 2. Redistributions in binary form must reproduce the above copyright 928040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# notice, this list of conditions and the following disclaimer in the 1028040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# documentation and/or other materials provided with the distribution. 1128040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# 1228040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND 1328040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 1428040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 1528040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR 1628040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1728040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 1828040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 1928040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2028040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2128040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2228040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu 2328040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhuimport sys 2428040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu 2528040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu 2628040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhudef make_stdout_binary(): 2728040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu """Puts sys.stdout into binary mode (on platforms that have a distinction 2828040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu between text and binary mode).""" 2928040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu if sys.platform != 'win32' or not hasattr(sys.stdout, 'fileno'): 3028040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu return 3128040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu import msvcrt 3228040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu import os 3328040489d744e0c5d475a88663056c9040ed5320Teng-Hui Zhu msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) 34