Browse Source

tmpfile -> StringIO

Ivars 6 years ago
parent
commit
154041b5e6
2 changed files with 80 additions and 53 deletions
  1. 71
    48
      project.wpr
  2. 9
    5
      sources/config.py

+ 71
- 48
project.wpr View File

@@ -114,15 +114,15 @@ debug.breakpoints = {loc('Downloader.py'): {182L: (0,
114 114
         None,
115 115
         1,
116 116
         0)},
117
-                     loc('sources/config.py'): {51L: (0,
117
+                     loc('sources/config.py'): {53: (0,
118 118
         None,
119 119
         1,
120 120
         0),
121
-        106L: (0,
121
+        107L: (0,
122 122
                None,
123 123
                1,
124 124
                0),
125
-        114L: (0,
125
+        116L: (0,
126 126
                None,
127 127
                1,
128 128
                0)},
@@ -794,18 +794,18 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
794 794
         'top-node': [('generic attribute',
795 795
                       loc('../../../../../Python27/lib/site-packages/PIL/Image.py'),
796 796
                       'ADAPTIVE')]},
797
-        loc('unknown:<untitled> #6'): {'column-widths': [1.0],
797
+        loc('unknown:<untitled> #3'): {'column-widths': [1.0],
798 798
                                        'expanded-nodes': [],
799 799
                                        'selected-nodes': [],
800 800
                                        'top-node': None},
801
-        loc('unknown:<untitled> #3'): {'column-widths': [1.0],
801
+        loc('unknown:<untitled> #4'): {'column-widths': [1.0],
802 802
                                        'expanded-nodes': [],
803 803
                                        'selected-nodes': [],
804 804
                                        'top-node': None},
805
-        loc('unknown:<untitled> #4'): {'expanded-nodes': [],
805
+        loc('unknown:<untitled> #5'): {'expanded-nodes': [],
806 806
                                        'selected-nodes': [],
807 807
                                        'top-node': None},
808
-        loc('unknown:<untitled> #5'): {'expanded-nodes': [],
808
+        loc('unknown:<untitled> #6'): {'expanded-nodes': [],
809 809
                                        'selected-nodes': [],
810 810
                                        'top-node': None}},
811 811
                                 'browse_mode': u'Current Module',
@@ -833,7 +833,7 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
833 833
                  'primary_view_state': {'area': 'wide',
834 834
         'constraint': None,
835 835
         'current_pages': [2,
836
-                          4],
836
+                          5],
837 837
         'notebook_display': 'normal',
838 838
         'notebook_percent': 0.4761133603238866,
839 839
         'override_title': None,
@@ -986,47 +986,31 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
986 986
         -1,
987 987
         -1),
988 988
                        'attrib-starts': [],
989
-                       'first-line': 0L,
989
+                       'first-line': 2L,
990 990
                        'folded-linenos': [],
991
-                       'history': {},
991
+                       'history': {None: ['import StringIO\n',
992
+        'a = StringIO.StringIO()\n',
993
+        'a.write("adfaf")\n',
994
+        'a.write("\\nadfaf")\n',
995
+        'a\n',
996
+        'a.seek(0)\n',
997
+        'a.read()\n']},
992 998
                        'launch-id': None,
993
-                       'sel-line': 2L,
994
-                       'sel-line-start': 174L,
995
-                       'selection_end': 174L,
996
-                       'selection_start': 174L,
999
+                       'sel-line': 14L,
1000
+                       'sel-line-start': 351L,
1001
+                       'selection_end': 351L,
1002
+                       'selection_start': 351L,
997 1003
                        'zoom': 0L})],
998 1004
         'primary_view_state': {'editor_states': ({'bookmarks': ([[loc('run.py'),
999
-        {'attrib-starts': [('run',
1000
-                            531)],
1001
-         'first-line': 525L,
1005
+        {'attrib-starts': [],
1006
+         'first-line': 715L,
1002 1007
          'folded-linenos': [],
1003
-         'sel-line': 532L,
1004
-         'sel-line-start': 22109L,
1005
-         'selection_end': 22150L,
1006
-         'selection_start': 22142L,
1008
+         'sel-line': 724L,
1009
+         'sel-line-start': 29166L,
1010
+         'selection_end': 29178L,
1011
+         'selection_start': 29170L,
1007 1012
          'zoom': 0L},
1008
-        1520694105.709],
1009
-        [loc('run.py'),
1010
-         {'attrib-starts': [('run_cli',
1011
-                             538)],
1012
-          'first-line': 531L,
1013
-          'folded-linenos': [],
1014
-          'sel-line': 538L,
1015
-          'sel-line-start': 22221L,
1016
-          'selection_end': 22285L,
1017
-          'selection_start': 22277L,
1018
-          'zoom': 0L},
1019
-         1520694111.18],
1020
-        [loc('run.py'),
1021
-         {'attrib-starts': [],
1022
-          'first-line': 715L,
1023
-          'folded-linenos': [],
1024
-          'sel-line': 724L,
1025
-          'sel-line-start': 29166L,
1026
-          'selection_end': 29178L,
1027
-          'selection_start': 29170L,
1028
-          'zoom': 0L},
1029
-         1520694112.068],
1013
+        1520694112.068],
1030 1014
         [loc('run.py'),
1031 1015
          {'attrib-starts': [],
1032 1016
           'first-line': 720L,
@@ -1235,9 +1219,33 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1235 1219
           'selection_end': 4309L,
1236 1220
           'selection_start': 4309L,
1237 1221
           'zoom': 0L},
1238
-         1520715655.96]],
1222
+         1520715655.96],
1223
+        [loc('util.py'),
1224
+         {'attrib-starts': [('_substitute_entity',
1225
+                             506)],
1226
+          'first-line': 537L,
1227
+          'folded-linenos': [],
1228
+          'sel-line': 522L,
1229
+          'sel-line-start': 16579L,
1230
+          'selection_end': 16598L,
1231
+          'selection_start': 16598L,
1232
+          'zoom': 0L},
1233
+         1520720563.343],
1234
+        [loc('sources/config.py'),
1235
+         {'attrib-starts': [('Source',
1236
+                             12),
1237
+                            ('Source.get_title',
1238
+                             123)],
1239
+          'first-line': 112L,
1240
+          'folded-linenos': [],
1241
+          'sel-line': 123L,
1242
+          'sel-line-start': 4446L,
1243
+          'selection_end': 4475L,
1244
+          'selection_start': 4475L,
1245
+          'zoom': 0L},
1246
+         1520720569.948]],
1239 1247
         20),
1240
-        'current-loc': loc('util.py'),
1248
+        'current-loc': loc('sources/config.py'),
1241 1249
         'editor-state-list': [(loc('run.py'),
1242 1250
                                {'attrib-starts': [('Main',
1243 1251
         22),
@@ -1378,6 +1386,18 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1378 1386
                                 'sel-line-start': 7831L,
1379 1387
                                 'selection_end': 7831L,
1380 1388
                                 'selection_start': 7831L,
1389
+                                'zoom': 0L}),
1390
+                              (loc('sources/config.py'),
1391
+                               {'attrib-starts': [('Source',
1392
+        12),
1393
+        ('Source.write_streams',
1394
+         73)],
1395
+                                'first-line': 104L,
1396
+                                'folded-linenos': [],
1397
+                                'sel-line': 113L,
1398
+                                'sel-line-start': 4268L,
1399
+                                'selection_end': 4268L,
1400
+                                'selection_start': 4268L,
1381 1401
                                 'zoom': 0L})],
1382 1402
         'has-focus': True,
1383 1403
         'locked': False},
@@ -1393,7 +1413,8 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1393 1413
          loc('sources/euronews.py'),
1394 1414
          loc('resolver.py'),
1395 1415
          loc('resolvers/cloudsany.py'),
1396
-         loc('../../../../../Python27/Lib/ftplib.py')]),
1416
+         loc('../../../../../Python27/Lib/ftplib.py'),
1417
+         loc('sources/config.py')]),
1397 1418
                                'open_files': [u'ContentSources.py',
1398 1419
         u'Downloader.py',
1399 1420
         u'resolver.py',
@@ -1406,7 +1427,8 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1406 1427
         u'sources/ltc.py',
1407 1428
         u'sources/replay.py',
1408 1429
         u'../../../../../Python27/Lib/ftplib.py',
1409
-        u'util.py']},
1430
+        u'util.py',
1431
+        u'sources/config.py']},
1410 1432
         'saved_notebook_display': None,
1411 1433
         'split_percents': {0: 0.42670046472327844},
1412 1434
         'splits': 2,
@@ -1421,7 +1443,8 @@ guimgr.overall-gui-state = {'windowing-policy': 'combined-window',
1421 1443
                          -1080,
1422 1444
                          1858,
1423 1445
                          1080)}]}
1424
-guimgr.recent-documents = [loc('util.py'),
1446
+guimgr.recent-documents = [loc('sources/config.py'),
1447
+                           loc('util.py'),
1425 1448
                            loc('run.py'),
1426 1449
                            loc('ContentSources.py'),
1427 1450
                            loc('sources/filmix.py'),

+ 9
- 5
sources/config.py View File

@@ -83,9 +83,11 @@ class Source(SourceBase):
83 83
             mode = "file"
84 84
 
85 85
         if mode == "ftp":
86
-            import tempfile
87
-            f = tempfile.NamedTemporaryFile("w", delete=False)
88
-            tmp_file = f.name
86
+            #import tempfile
87
+            #f = tempfile.NamedTemporaryFile("w", delete=False)
88
+            #tmp_file = f.name
89
+            import StringIO
90
+            f = StringIO.StringIO()
89 91
         else:  # Parasts fails
90 92
             try:
91 93
                 f = open(self.streams_file, "w")
@@ -100,7 +102,6 @@ class Source(SourceBase):
100 102
             for item in self.lists[l]:
101 103
                 f.write("%s|%s|%s|%s\n"%(item[0].replace("\n",""),item[1],item[2],item[3].replace("\n","\\n")))
102 104
             f.write("\n")
103
-        f.close()
104 105
 
105 106
         if mode == "ftp":
106 107
             import ftplib, urlparse
@@ -108,10 +109,13 @@ class Source(SourceBase):
108 109
             try:
109 110
                 ftp = ftplib.FTP(p.hostname)
110 111
                 ftp.login(p.username, p.password)
111
-                ftp.storbinary("STOR "+p.path, open(tmp_file, "r"))
112
+                f.seek(0)
113
+                ftp.storbinary("STOR "+p.path, f)
112 114
                 ftp.close()
113 115
             except Exception as e:
114 116
                 print e.message
117
+        else:
118
+            f.close()
115 119
 
116 120
 
117 121