File: python3.py

package info (click to toggle)
pcbasic 2.0.7-9
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 35,416 kB
  • sloc: python: 28,411; sh: 103; makefile: 10
file content (60 lines) | stat: -rw-r--r-- 1,155 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
"""
PC-BASIC - compat.python3
Python 2/Python 3 functionality

Contains lines of code from package six, which is
Copyright (c) 2010-2018 Benjamin Peterson
and released under an MIT licence https://opensource.org/licenses/MIT
"""

import sys
import os
import struct


# deal with broken pipes

def is_broken_pipe(e):
    return isinstance(e, BrokenPipeError)

# strings

int2byte = struct.Struct(">B").pack

def add_str(cls):
    """Decorator to implement the correct str() function."""
    try:
        cls.__str__ = cls.__unicode__
    except AttributeError:
        pass
    return cls

# unicode system interfaces

getcwdu = os.getcwd
getenvu = os.getenv
iterenvu = os.environ.keys

def setenvu(key, value):
    os.environ[key] = value

# iterators
zip = zip
xrange = range

def iterchar(s):
    """Iterate over bytes, returning char."""
    return (s[_i:_i+1] for _i in range(len(s)))

def iterbytes(s):
    """Iterate over bytes/bytearray/memoryview, returning int."""
    return s

def iteritems(d, **kw):
    return iter(d.items(**kw))

def itervalues(d, **kw):
    return iter(d.values(**kw))

def iterkeys(d, **kw):
    return iter(d.keys(**kw))