Utilities/compatibility_fixes.py

Mon, 08 Jul 2013 21:47:26 +0200

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Mon, 08 Jul 2013 21:47:26 +0200
branch
Py2 comp.
changeset 2790
6686a3326df8
parent 2526
a91cba8291b9
child 3065
070b35dde35e
permissions
-rw-r--r--

Special case if no 'b' or 't' in access mode fixed. Source docu added.

2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
2
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
3 # Copyright (c) 2013 - 2013 Tobias Rzepka <tobias.rzepka@gmail.com>
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
4 #
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
5
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
6 """
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
7 Module implementing the open behavior of Python3 for use with Eric5.
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
8 The Eric5 used features are emulated only. The not emulated features
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
9 should throw a NotImplementedError exception.
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
10 """
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
11
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
12 from __future__ import unicode_literals # __IGNORE_WARNING__
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
13
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
14 import __builtin__
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
15 import codecs
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
16
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
17
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
18 def open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True):
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
19 """
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
20 Replacement for the build in open function.
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
21
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
22 @param file filename or file descriptor (string)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
23 @keyparam mode access mode (string)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
24 @keyparam buffering size of the read buffer (string)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
25 @keyparam encoding character encoding for reading/ writing (string)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
26 @keyparam errors behavior for the character encoding ('strict', 'explicit', ...) (string)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
27 @keyparam newline controls how universal newlines works (string)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
28 @keyparam closefd close underlying file descriptor if given as file parameter (boolean)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
29 """
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
30 return File(file, mode, buffering, encoding, errors, newline, closefd)
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
31
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
32
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
33 class File(file): #__IGNORE_WARNING__
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
34 """
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
35 Facade for the original file class.
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
36 """
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
37 def __init__(self, filein, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True):
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
38 """
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
39 Constructor, checks for unimplemented parameters.
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
40
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
41 @param filein filename or file descriptor (string)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
42 @keyparam mode access mode (string)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
43 @keyparam buffering size of the read buffer (string)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
44 @keyparam encoding character encoding for reading/ writing (string)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
45 @keyparam errors behavior for the character encoding ('strict', 'explicit', ...) (string)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
46 @keyparam newline controls how universal newlines works (string)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
47 @keyparam closefd close underlying file descriptor if given as file parameter (boolean)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
48 """
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
49 self.__encoding = encoding
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
50 self.__newline = newline
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
51 self.__closefd = closefd
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
52 if newline is not None:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
53 if 'r' in mode:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
54 raise NotImplementedError
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
55 else:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
56 mode = mode.replace('t', 'b')
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
57 if 'b' not in mode:
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
58 mode = mode + 'b'
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
59
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
60 if closefd == False:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
61 raise NotImplementedError
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
62
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
63 if errors is None:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
64 self.__errors = 'strict'
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
65 else:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
66 self.__errors = errors
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
67
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
68 file.__init__(self, filein, mode, buffering)
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
69
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
70 def read(self, n=-1):
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
71 """
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
72 Read n bytes or all if n=-1 from file.
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
73
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
74 @keyparam n bytecount or all if n=-1 (int)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
75 @return decoded bytes read
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
76 """
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
77 txt = super(File, self).read(n)
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
78 if self.__encoding is None:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
79 return txt
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
80 else:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
81 return codecs.decode(txt, self.__encoding)
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
82
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
83 def readline(self, limit=-1):
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
84 """
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
85 Read one line from file.
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
86
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
87 @keyparam limit maximum bytes to read or all if limit=-1 (int)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
88 @return decoded line read
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
89 """
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
90 txt = super(File, self).readline(limit)
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
91 if self.__encoding is None:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
92 return txt
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
93 else:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
94 return codecs.decode(txt, self.__encoding)
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
95
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
96 def readlines(self, hint=-1):
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
97 """
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
98 Read all lines from file.
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
99
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
100 @keyparam hint maximum bytes to read or all if hint=-1 (int)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
101 @return decoded lines read
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
102 """
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
103 if self.__encoding is None:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
104 return super(File, self).readlines(hint)
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
105 else:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
106 return [codecs.decode(txt, self.__encoding) for txt in super(File, self).readlines(hint)]
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
107
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
108 def write(self, txt):
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
109 """
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
110 Write given data to file. Encode if needed.
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
111
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
112 @param txt data to write. (str, bytes)
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
113 """
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
114 if self.__encoding is not None:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
115 txt = codecs.encode(txt, self.__encoding, self.__errors)
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
116
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
117 if self.__newline in ['\r\n', '\r']:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
118 txt = txt.replace('\n', self.__newline)
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
119
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
120 super(File, self).write(txt)
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
121
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
122 def next(self):
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
123 """
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
124 Method if used in a iterator.
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
125
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
126 @return decoded data read
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
127 """
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
128 txt = super(File, self).next()
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
129 if self.__encoding is None:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
130 return txt
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
131 else:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
132 return codecs.decode(txt, self.__encoding)
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
133
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
134 # Inject into the __builtin__ dictionary
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
135 __builtin__.open = open
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
136
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
137 if __name__ == '__main__':
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
138 fp = open('compatibility_fixes.py', encoding='latin1')
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
139 print(fp.read())
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
140 fp.close()
2790
6686a3326df8 Special case if no 'b' or 't' in access mode fixed. Source docu added.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2526
diff changeset
141
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
142 with open('compatibility_fixes.py', encoding='UTF-8') as fp:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
143 rlines = fp.readlines()
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
144 print(rlines[-1])

eric ide

mercurial