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
         None,
114
         None,
115
         1,
115
         1,
116
         0)},
116
         0)},
117
-                     loc('sources/config.py'): {51L: (0,
117
+                     loc('sources/config.py'): {53: (0,
118
         None,
118
         None,
119
         1,
119
         1,
120
         0),
120
         0),
121
-        106L: (0,
121
+        107L: (0,
122
                None,
122
                None,
123
                1,
123
                1,
124
                0),
124
                0),
125
-        114L: (0,
125
+        116L: (0,
126
                None,
126
                None,
127
                1,
127
                1,
128
                0)},
128
                0)},
794
         'top-node': [('generic attribute',
794
         'top-node': [('generic attribute',
795
                       loc('../../../../../Python27/lib/site-packages/PIL/Image.py'),
795
                       loc('../../../../../Python27/lib/site-packages/PIL/Image.py'),
796
                       'ADAPTIVE')]},
796
                       'ADAPTIVE')]},
797
-        loc('unknown:<untitled> #6'): {'column-widths': [1.0],
797
+        loc('unknown:<untitled> #3'): {'column-widths': [1.0],
798
                                        'expanded-nodes': [],
798
                                        'expanded-nodes': [],
799
                                        'selected-nodes': [],
799
                                        'selected-nodes': [],
800
                                        'top-node': None},
800
                                        'top-node': None},
801
-        loc('unknown:<untitled> #3'): {'column-widths': [1.0],
801
+        loc('unknown:<untitled> #4'): {'column-widths': [1.0],
802
                                        'expanded-nodes': [],
802
                                        'expanded-nodes': [],
803
                                        'selected-nodes': [],
803
                                        'selected-nodes': [],
804
                                        'top-node': None},
804
                                        'top-node': None},
805
-        loc('unknown:<untitled> #4'): {'expanded-nodes': [],
805
+        loc('unknown:<untitled> #5'): {'expanded-nodes': [],
806
                                        'selected-nodes': [],
806
                                        'selected-nodes': [],
807
                                        'top-node': None},
807
                                        'top-node': None},
808
-        loc('unknown:<untitled> #5'): {'expanded-nodes': [],
808
+        loc('unknown:<untitled> #6'): {'expanded-nodes': [],
809
                                        'selected-nodes': [],
809
                                        'selected-nodes': [],
810
                                        'top-node': None}},
810
                                        'top-node': None}},
811
                                 'browse_mode': u'Current Module',
811
                                 'browse_mode': u'Current Module',
833
                  'primary_view_state': {'area': 'wide',
833
                  'primary_view_state': {'area': 'wide',
834
         'constraint': None,
834
         'constraint': None,
835
         'current_pages': [2,
835
         'current_pages': [2,
836
-                          4],
836
+                          5],
837
         'notebook_display': 'normal',
837
         'notebook_display': 'normal',
838
         'notebook_percent': 0.4761133603238866,
838
         'notebook_percent': 0.4761133603238866,
839
         'override_title': None,
839
         'override_title': None,
986
         -1,
986
         -1,
987
         -1),
987
         -1),
988
                        'attrib-starts': [],
988
                        'attrib-starts': [],
989
-                       'first-line': 0L,
989
+                       'first-line': 2L,
990
                        'folded-linenos': [],
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
                        'launch-id': None,
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
                        'zoom': 0L})],
1003
                        'zoom': 0L})],
998
         'primary_view_state': {'editor_states': ({'bookmarks': ([[loc('run.py'),
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
          'folded-linenos': [],
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
          'zoom': 0L},
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
         [loc('run.py'),
1014
         [loc('run.py'),
1031
          {'attrib-starts': [],
1015
          {'attrib-starts': [],
1032
           'first-line': 720L,
1016
           'first-line': 720L,
1235
           'selection_end': 4309L,
1219
           'selection_end': 4309L,
1236
           'selection_start': 4309L,
1220
           'selection_start': 4309L,
1237
           'zoom': 0L},
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
         20),
1247
         20),
1240
-        'current-loc': loc('util.py'),
1248
+        'current-loc': loc('sources/config.py'),
1241
         'editor-state-list': [(loc('run.py'),
1249
         'editor-state-list': [(loc('run.py'),
1242
                                {'attrib-starts': [('Main',
1250
                                {'attrib-starts': [('Main',
1243
         22),
1251
         22),
1378
                                 'sel-line-start': 7831L,
1386
                                 'sel-line-start': 7831L,
1379
                                 'selection_end': 7831L,
1387
                                 'selection_end': 7831L,
1380
                                 'selection_start': 7831L,
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
                                 'zoom': 0L})],
1401
                                 'zoom': 0L})],
1382
         'has-focus': True,
1402
         'has-focus': True,
1383
         'locked': False},
1403
         'locked': False},
1393
          loc('sources/euronews.py'),
1413
          loc('sources/euronews.py'),
1394
          loc('resolver.py'),
1414
          loc('resolver.py'),
1395
          loc('resolvers/cloudsany.py'),
1415
          loc('resolvers/cloudsany.py'),
1396
-         loc('../../../../../Python27/Lib/ftplib.py')]),
1416
+         loc('../../../../../Python27/Lib/ftplib.py'),
1417
+         loc('sources/config.py')]),
1397
                                'open_files': [u'ContentSources.py',
1418
                                'open_files': [u'ContentSources.py',
1398
         u'Downloader.py',
1419
         u'Downloader.py',
1399
         u'resolver.py',
1420
         u'resolver.py',
1406
         u'sources/ltc.py',
1427
         u'sources/ltc.py',
1407
         u'sources/replay.py',
1428
         u'sources/replay.py',
1408
         u'../../../../../Python27/Lib/ftplib.py',
1429
         u'../../../../../Python27/Lib/ftplib.py',
1409
-        u'util.py']},
1430
+        u'util.py',
1431
+        u'sources/config.py']},
1410
         'saved_notebook_display': None,
1432
         'saved_notebook_display': None,
1411
         'split_percents': {0: 0.42670046472327844},
1433
         'split_percents': {0: 0.42670046472327844},
1412
         'splits': 2,
1434
         'splits': 2,
1421
                          -1080,
1443
                          -1080,
1422
                          1858,
1444
                          1858,
1423
                          1080)}]}
1445
                          1080)}]}
1424
-guimgr.recent-documents = [loc('util.py'),
1446
+guimgr.recent-documents = [loc('sources/config.py'),
1447
+                           loc('util.py'),
1425
                            loc('run.py'),
1448
                            loc('run.py'),
1426
                            loc('ContentSources.py'),
1449
                            loc('ContentSources.py'),
1427
                            loc('sources/filmix.py'),
1450
                            loc('sources/filmix.py'),

+ 9
- 5
sources/config.py View File

83
             mode = "file"
83
             mode = "file"
84
 
84
 
85
         if mode == "ftp":
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
         else:  # Parasts fails
91
         else:  # Parasts fails
90
             try:
92
             try:
91
                 f = open(self.streams_file, "w")
93
                 f = open(self.streams_file, "w")
100
             for item in self.lists[l]:
102
             for item in self.lists[l]:
101
                 f.write("%s|%s|%s|%s\n"%(item[0].replace("\n",""),item[1],item[2],item[3].replace("\n","\\n")))
103
                 f.write("%s|%s|%s|%s\n"%(item[0].replace("\n",""),item[1],item[2],item[3].replace("\n","\\n")))
102
             f.write("\n")
104
             f.write("\n")
103
-        f.close()
104
 
105
 
105
         if mode == "ftp":
106
         if mode == "ftp":
106
             import ftplib, urlparse
107
             import ftplib, urlparse
108
             try:
109
             try:
109
                 ftp = ftplib.FTP(p.hostname)
110
                 ftp = ftplib.FTP(p.hostname)
110
                 ftp.login(p.username, p.password)
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
                 ftp.close()
114
                 ftp.close()
113
             except Exception as e:
115
             except Exception as e:
114
                 print e.message
116
                 print e.message
117
+        else:
118
+            f.close()
115
 
119
 
116
 
120
 
117
 
121