File: msysio.py

package info (click to toggle)
pygame 1.9.1release%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,276 kB
  • sloc: ansic: 41,205; python: 21,987; cpp: 537; objc: 196; php: 92; sh: 77; makefile: 35
file content (63 lines) | stat: -rw-r--r-- 1,350 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# module msysio.py
# Requires Python 2.2 or better.

"""Provide helpful routines for interactive IO on the MSYS console"""

# Output needs to be flushed to be seen. It is especially important
# when prompting for user input.

import sys
import os

__all__ = ['raw_input_', 'print_', 'is_msys']

# 2.x/3.x compatibility stuff
try:
    raw_input
except NameError:
    raw_input = input

# Exported functions
__all__ = ['raw_input_', 'print_', 'is_msys']

# 2.x/3.x compatibility stuff
try:
    raw_input
except NameError:
    raw_input = input

# Exported functions
def raw_input_(prompt=None):
    """Prompt for user input in an MSYS console friendly way"""
    if prompt is None:
        prompt = ''
    print_(prompt, end='')
    return raw_input()

def print_(*args, **kwds):
    """Print arguments in an MSYS console friendly way

    Keyword arguments:
        file, sep, end
    """

    stream = kwds.get('file', sys.stdout)
    sep = kwds.get('sep', ' ')
    end = kwds.get('end', '\n')

    if args:
        stream.write(sep.join([str(arg) for arg in args]))
    if end:
        stream.write(end)
    try:
        stream.flush()
    except AttributeError:
        pass

def is_msys():
    """Return true if the execution environment is MSYS"""

    try:
        return os.environ['OSTYPE'] == 'msys'
    except KeyError:
        return False