3 # Copyright (c) 2013 - 2013 Tobias Rzepka <tobias.rzepka@gmail.com> |
3 # Copyright (c) 2013 - 2013 Tobias Rzepka <tobias.rzepka@gmail.com> |
4 # |
4 # |
5 |
5 |
6 """ |
6 """ |
7 Module implementing the open behavior of Python3 for use with Eric5. |
7 Module implementing the open behavior of Python3 for use with Eric5. |
|
8 |
8 The Eric5 used features are emulated only. The not emulated features |
9 The Eric5 used features are emulated only. The not emulated features |
9 should throw a NotImplementedError exception. |
10 should throw a NotImplementedError exception. |
10 """ |
11 """ |
11 |
12 |
12 from __future__ import unicode_literals # __IGNORE_WARNING__ |
13 from __future__ import unicode_literals # __IGNORE_WARNING__ |
13 |
14 |
14 import __builtin__ |
15 import __builtin__ |
15 import codecs |
16 import codecs |
16 |
17 |
17 |
18 |
18 def open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True): |
19 def open(file, mode='r', buffering=-1, encoding=None, |
|
20 errors=None, newline=None, closefd=True): |
19 """ |
21 """ |
20 Replacement for the build in open function. |
22 Replacement for the build in open function. |
21 |
23 |
22 @param file filename or file descriptor (string) |
24 @param file filename or file descriptor (string) |
23 @keyparam mode access mode (string) |
25 @keyparam mode access mode (string) |
24 @keyparam buffering size of the read buffer (string) |
26 @keyparam buffering size of the read buffer (string) |
25 @keyparam encoding character encoding for reading/ writing (string) |
27 @keyparam encoding character encoding for reading/ writing (string) |
26 @keyparam errors behavior for the character encoding ('strict', 'explicit', ...) (string) |
28 @keyparam errors behavior for the character encoding ('strict', |
|
29 'explicit', ...) (string) |
27 @keyparam newline controls how universal newlines works (string) |
30 @keyparam newline controls how universal newlines works (string) |
28 @keyparam closefd close underlying file descriptor if given as file parameter (boolean) |
31 @keyparam closefd close underlying file descriptor if given as file |
|
32 parameter (boolean) |
|
33 @return Returns the new file object |
29 """ |
34 """ |
30 return File(file, mode, buffering, encoding, errors, newline, closefd) |
35 return File(file, mode, buffering, encoding, errors, newline, closefd) |
31 |
36 |
32 |
37 |
33 class File(file): #__IGNORE_WARNING__ |
38 class File(file): #__IGNORE_WARNING__ |
34 """ |
39 """ |
35 Facade for the original file class. |
40 Facade for the original file class. |
36 """ |
41 """ |
37 def __init__(self, filein, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True): |
42 def __init__(self, filein, mode='r', buffering=-1, |
|
43 encoding=None, errors=None, newline=None, closefd=True): |
38 """ |
44 """ |
39 Constructor, checks for unimplemented parameters. |
45 Constructor, checks for unimplemented parameters. |
40 |
46 |
41 @param filein filename or file descriptor (string) |
47 @param filein filename or file descriptor (string) |
42 @keyparam mode access mode (string) |
48 @keyparam mode access mode (string) |
43 @keyparam buffering size of the read buffer (string) |
49 @keyparam buffering size of the read buffer (string) |
44 @keyparam encoding character encoding for reading/ writing (string) |
50 @keyparam encoding character encoding for reading/ writing (string) |
45 @keyparam errors behavior for the character encoding ('strict', 'explicit', ...) (string) |
51 @keyparam errors behavior for the character encoding ('strict', |
|
52 'explicit', ...) (string) |
46 @keyparam newline controls how universal newlines works (string) |
53 @keyparam newline controls how universal newlines works (string) |
47 @keyparam closefd close underlying file descriptor if given as file parameter (boolean) |
54 @keyparam closefd close underlying file descriptor if given as file |
|
55 parameter (boolean) |
|
56 @exception NotImplementedError for not implemented method parameters |
48 """ |
57 """ |
49 self.__encoding = encoding |
58 self.__encoding = encoding |
50 self.__newline = newline |
59 self.__newline = newline |
51 self.__closefd = closefd |
60 self.__closefd = closefd |
52 if newline is not None: |
61 if newline is not None: |