Mon, 15 Apr 2019 19:53:29 +0200
setup.py: continued implementing support for setup.py.
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

1  # * coding: utf8 * 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

2  
4384
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

3  # Copyright (c) 2013  2015 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  """ 
4384
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

7  Module implementing some workarounds to let eric6 run under Python 2. 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

8  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

9  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

10  
4691
0fe41214fdd6
Get rid of the interruption by an import exception when using Python3.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4566
diff
changeset

11  import __builtin__ # __IGNORE_EXCEPTION__ 
4384
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

12  import codecs 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

13  import imp 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

14  import locale 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

15  import os 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

16  import sys 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

17  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

18  # convert all command line arguments to unicode 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

19  sys.argv = [arg.decode(locale.getpreferredencoding()) for arg in sys.argv] 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

20  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

21  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

22  Improvement for the os.path.join function because the original join doesn't 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

23  use the correct encoding. 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

24  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

25  # Save original function for use in joinAsUnicode 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

26  __join = os.path.join 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

27  # Flag to disable unicode conversion of join function 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

28  os.path.join_unicode = True 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

29  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

30  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

31  def joinAsUnicode(*args): 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

32  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

33  Convert none unicode parameter of the os.path.join into unicode. 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

34  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

35  @param args paths which should be joined (str, unicode) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

36  @return unicode str of the path (unicode) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

37  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

38  if os.path.join_unicode: 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

39  convArgs = [] 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

40  for arg in args: 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

41  if isinstance(arg, str): 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

42  arg = arg.decode(locale.getpreferredencoding(), 'replace') 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

43  convArgs.append(arg) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

44  return __join(*convArgs) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

45  else: 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

46  return __join(*args) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

47  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

48  # Replace os.path.join with unicode aware version 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

49  os.path.join = joinAsUnicode 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

50  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

51  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

52  Improvement for the imp.load_source and imp.find_module functions because the 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

53  originals doesn't use the correct encoding. 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

54  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

55  # Save original function for use in load_sourceAsStr and find_moduleAsStr 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

56  __load_source = imp.load_source 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

57  __find_module = imp.find_module 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

58  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

59  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

60  def load_sourceAsStr(*args): 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

61  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

62  Convert none str parameter of the imp.load_source into str. 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

63  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

64  @param args (str, unicode) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

65  @return list of args converted to str (list) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

66  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

67  convArgs = [] 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

68  for arg in args: 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

69  if isinstance(arg, unicode): 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

70  arg = arg.encode(sys.getfilesystemencoding(), 'strict') 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

71  convArgs.append(arg) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

72  return __load_source(*convArgs) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

73  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

74  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

75  def find_moduleAsStr(*args): 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

76  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

77  Convert none str parameter of the imp.find_module into str. 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

78  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

79  @param args (str, unicode) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

80  @return list of args converted to str (list) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

81  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

82  convArgs = [] 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

83  for arg in args: 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

84  if isinstance(arg, unicode): 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

85  arg = arg.encode(sys.getfilesystemencoding(), 'strict') 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

86  convArgs.append(arg) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

87  return __find_module(*convArgs) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

88  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

89  # Replace imp.load_source and imp.find_module with unicode aware version 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

90  imp.load_source = load_sourceAsStr 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

91  imp.find_module = find_moduleAsStr 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

92  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

93  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

94  Improvement for the sys.path list because some other functions doesn't expect 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

95  unicode in the sys.path list. 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

96  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

97  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

98  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

99  class PlainStrList(list): 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

100  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

101  Keep track that all added paths to sys.path are str. 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

102  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

103  def __init__(self, *args): 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

104  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

105  Constructor 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

106  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

107  @param args list of paths to start with (list) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

108  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

109  super(PlainStrList, self).__init__() 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

110  self.extend(list(args)) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

111  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

112  def __convert(self, element): 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

113  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

114  Private method to convert unicode to file system encoding. 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

115  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

116  @param element to convert from unicode to file system encoding (any) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

117  @return converted element 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

118  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

119  if isinstance(element, unicode): 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

120  # Throw exception if it can't be converted, otherwise exception 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

121  # could occur somewhere else 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

122  element = element.encode(sys.getfilesystemencoding(), 'strict') 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

123  return element 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

124  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

125  def __setitem__(self, idx, value): 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

126  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

127  Special method to overwrite a specific list item. 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

128  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

129  @param idx index of the item (int) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

130  @param value the new value (any) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

131  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

132  super(PlainStrList, self).__setitem__(idx, self.__convert(value)) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

133  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

134  def insert(self, idx, value): 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

135  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

136  Public method to insert a specific list item. 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

137  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

138  @param idx index of the item (int) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

139  @param value the new value (any) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

140  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

141  super(PlainStrList, self).insert(idx, self.__convert(value)) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

142  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

143  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

144  # insert a conversion function from unicode to str at sys.path access 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

145  sys.path = PlainStrList(*sys.path) 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

146  
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

147  """ 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

148  The open function and File class simulates the open behaviour of Python3. 
3065
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2790
diff
changeset

149  
3670
f0cb7579c0b4
Finished renaming eric5 for PyQt5 to eric6.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3591
diff
changeset

150  The Eric6 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

151  should throw a NotImplementedError exception. 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

152  """ 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

153  
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

154  
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4691
diff
changeset

155  def open(filein, mode='r', buffering=1, encoding=None, 
3065
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2790
diff
changeset

156  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

157  """ 
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

158  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

159  
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4691
diff
changeset

160  @param filein filename or file descriptor (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

161  @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

162  @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

163  @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

164  @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

165  '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

166  @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

167  @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

168  parameter (boolean) 
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2790
diff
changeset

169  @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

170  """ 
5587
ea526b78ee6c
Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4691
diff
changeset

171  return File(filein, mode, buffering, encoding, errors, newline, closefd) 
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

172  
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

173  
3515
1b8381afe38f
Merge with default branch.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3145
diff
changeset

174  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

175  """ 
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

176  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

177  """ 
3065
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2790
diff
changeset

178  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

179  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

180  """ 
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3539
diff
changeset

181  Constructor 
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3539
diff
changeset

182  
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3539
diff
changeset

183  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

184  
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

185  @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

186  @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

187  @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

188  @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

189  @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

190  '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

191  @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

192  @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

193  parameter (boolean) 
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2790
diff
changeset

194  @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

195  """ 
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

196  self.__encoding = encoding 
4184
6dbd901a8b1a
Bugfix for Issue176: Forms with special characters and a not unix lineending throws exception.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3670
diff
changeset

197  self.__newline = str(newline) 
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

198  self.__closefd = closefd 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

199  if newline is not None: 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

200  if 'r' in mode: 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

201  raise NotImplementedError 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

202  else: 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

203  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

204  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

205  mode = mode + 'b' 
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

206  
3065
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2790
diff
changeset

207  if closefd is False: 
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

208  raise NotImplementedError 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

209  
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

210  if errors is None: 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

211  self.__errors = 'strict' 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

212  else: 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

213  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

214  
4289
6c1ab651c9ce
Fixed some code style issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4184
diff
changeset

215  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

216  
3539
0c2dc1446ebf
Fixed a few code style issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3515
diff
changeset

217  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

218  """ 
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3539
diff
changeset

219  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

220  
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

221  @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

222  @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

223  """ 
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

224  txt = super(File, self).read(n) 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

225  if self.__encoding is None: 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

226  return txt 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

227  else: 
3539
0c2dc1446ebf
Fixed a few code style issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3515
diff
changeset

228  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

229  
3539
0c2dc1446ebf
Fixed a few code style issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3515
diff
changeset

230  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

231  """ 
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3539
diff
changeset

232  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

233  
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

234  @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

235  @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

236  """ 
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

237  txt = super(File, self).readline(limit) 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

238  if self.__encoding is None: 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

239  return txt 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

240  else: 
3539
0c2dc1446ebf
Fixed a few code style issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3515
diff
changeset

241  return codecs.decode(txt, self.__encoding) 
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

242  
3539
0c2dc1446ebf
Fixed a few code style issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3515
diff
changeset

243  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

244  """ 
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3539
diff
changeset

245  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

246  
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

247  @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

248  @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

249  """ 
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

250  if self.__encoding is None: 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

251  return super(File, self).readlines(hint) 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

252  else: 
3539
0c2dc1446ebf
Fixed a few code style issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3515
diff
changeset

253  return [codecs.decode(txt, self.__encoding) 
3065
070b35dde35e
Fixed a bunch of indentation issues.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2790
diff
changeset

254  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

255  
3539
0c2dc1446ebf
Fixed a few code style issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3515
diff
changeset

256  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

257  """ 
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3539
diff
changeset

258  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

259  
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

260  @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

261  """ 
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

262  if self.__encoding is not None: 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

263  txt = codecs.encode(txt, self.__encoding, self.__errors) 
4384
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

264  elif isinstance(txt, unicode): 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

265  txt = codecs.encode(txt, 'utf8', 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

266  
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

267  if self.__newline in ['\r\n', '\r']: 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

268  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

269  
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

270  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

271  
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

272  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

273  """ 
3591
2f2a4a76dd22
Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3539
diff
changeset

274  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

275  
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

276  @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

277  """ 
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

278  txt = super(File, self).next() 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

279  if self.__encoding is None: 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

280  return txt 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

281  else: 
3539
0c2dc1446ebf
Fixed a few code style issues.
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
3515
diff
changeset

282  return codecs.decode(txt, self.__encoding) 
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

283  
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

284  # Inject into the __builtin__ dictionary 
2526
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

285  __builtin__.open = open 
a91cba8291b9
Minimum modifications to start Eric5 with Py2.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
diff
changeset

286  
4384
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

287  # 
04896c4a5a8e
Handling of unicode chars in user name now handled correctly, + importing of PySide doesn't waste memory any more.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
4359
diff
changeset

288  # eflag: FileType = Python2 
4543
2e6a880670e9
Fixed a few code style issues (forgotten future imports, copyrights,...).
Detlev Offenbach <detlev@dieoffenbachs.de>
parents:
4384
diff
changeset

289  # eflag: noqa = M702 