Utilities/compatibility_fixes.py

Sat, 05 Jul 2014 11:41:14 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 05 Jul 2014 11:41:14 +0200
changeset 3669
ac84ac3c0f05
parent 3591
2f2a4a76dd22
child 3670
f0cb7579c0b4
permissions
-rw-r--r--

Continued renaming eric5 for PyQt5 to eric6.

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.
3065
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
8
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
9 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
10 should throw a NotImplementedError exception.
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
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3065
diff changeset
13 from __future__ import unicode_literals
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
14
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
15 import __builtin__
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
16 import codecs
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
3065
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
19 def open(file, mode='r', buffering=-1, encoding=None,
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
20 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
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 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
23
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 @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
25 @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
26 @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
27 @keyparam encoding character encoding for reading/ writing (string)
3065
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
28 @keyparam errors behavior for the character encoding ('strict',
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
29 'explicit', ...) (string)
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
30 @keyparam newline controls how universal newlines works (string)
3065
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
31 @keyparam closefd close underlying file descriptor if given as file
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
32 parameter (boolean)
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
33 @return Returns the new file object
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
34 """
3539
0c2dc1446ebf Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
35 return File(file, mode, buffering, encoding, errors, newline, closefd)
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
36
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
37
3515
1b8381afe38f Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
38 class File(file): # __IGNORE_WARNING__
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
39 """
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 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
41 """
3065
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
42 def __init__(self, filein, mode='r', buffering=-1,
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
43 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
44 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3539
diff changeset
45 Constructor
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3539
diff changeset
46
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3539
diff changeset
47 It checks for unimplemented parameters.
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
48
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
49 @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
50 @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
51 @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
52 @keyparam encoding character encoding for reading/ writing (string)
3065
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
53 @keyparam errors behavior for the character encoding ('strict',
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
54 'explicit', ...) (string)
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
55 @keyparam newline controls how universal newlines works (string)
3065
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
56 @keyparam closefd close underlying file descriptor if given as file
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
57 parameter (boolean)
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
58 @exception NotImplementedError for not implemented method parameters
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
59 """
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
60 self.__encoding = encoding
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
61 self.__newline = newline
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
62 self.__closefd = closefd
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
63 if newline is not None:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
64 if 'r' in mode:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
65 raise NotImplementedError
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
66 else:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
67 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
68 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
69 mode = mode + 'b'
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
70
3065
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
71 if closefd is False:
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
72 raise NotImplementedError
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
73
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
74 if errors is None:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
75 self.__errors = 'strict'
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
76 else:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
77 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
78
3515
1b8381afe38f Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3145
diff changeset
79 file.__init__(self, filein, mode, buffering) # __IGNORE_WARNING__
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
80
3539
0c2dc1446ebf Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
81 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
82 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3539
diff changeset
83 Public method to read n bytes or all if n=-1 from file.
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 @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
86 @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
87 """
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
88 txt = super(File, self).read(n)
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
89 if self.__encoding is None:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
90 return txt
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
91 else:
3539
0c2dc1446ebf Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
92 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
93
3539
0c2dc1446ebf Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
94 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
95 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3539
diff changeset
96 Public method to read one line from file.
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 @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
99 @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
100 """
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
101 txt = super(File, self).readline(limit)
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
102 if self.__encoding is None:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
103 return txt
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
104 else:
3539
0c2dc1446ebf Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
105 return codecs.decode(txt, self.__encoding)
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
106
3539
0c2dc1446ebf Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
107 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
108 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3539
diff changeset
109 Public method to read all lines from file.
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
110
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 @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
112 @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
113 """
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
114 if self.__encoding is None:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
115 return super(File, self).readlines(hint)
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
116 else:
3539
0c2dc1446ebf Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
117 return [codecs.decode(txt, self.__encoding)
3065
070b35dde35e Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2790
diff changeset
118 for txt in super(File, self).readlines(hint)]
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
119
3539
0c2dc1446ebf Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
120 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
121 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3539
diff changeset
122 Public method to write given data to file and encode if needed.
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 @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
125 """
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
126 if self.__encoding is not None:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
127 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
128
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
129 if self.__newline in ['\r\n', '\r']:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
130 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
131
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
132 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
133
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
134 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
135 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3539
diff changeset
136 Public method used in an iterator.
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
137
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
138 @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
139 """
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
140 txt = super(File, self).next()
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
141 if self.__encoding is None:
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
142 return txt
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
143 else:
3539
0c2dc1446ebf Fixed a few code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3515
diff changeset
144 return codecs.decode(txt, self.__encoding)
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
145
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
146 # Inject into the __builtin__ dictionary
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
147 __builtin__.open = open
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
148
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
149 if __name__ == '__main__':
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
150 fp = open('compatibility_fixes.py', encoding='latin1')
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
151 print(fp.read())
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
152 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
153
2526
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
154 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
155 rlines = fp.readlines()
a91cba8291b9 Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff changeset
156 print(rlines[-1])

eric ide

mercurial