Browse Source

Use six.StringIO/BytesIO instead of StringIO.StringIO

to keep Python 3.x compatibility, use six.StringIO/BytesIO to
replace StringIO.StringIO

StringIO works for unicode
BytesIO works for bytes

Change-Id: I3892098e31d8d6984d58136110aae653dc4047ab
Closes-Bug: #1280100
tags/2014.1.b3
He Yongli 5 years ago
parent
commit
9bd6754b57
2 changed files with 4 additions and 5 deletions
  1. 1
    2
      neutron/agent/linux/dhcp.py
  2. 3
    3
      neutron/tests/unit/test_policy.py

+ 1
- 2
neutron/agent/linux/dhcp.py View File

@@ -21,7 +21,6 @@ import os
21 21
 import re
22 22
 import shutil
23 23
 import socket
24
-import StringIO
25 24
 import sys
26 25
 import uuid
27 26
 
@@ -413,7 +412,7 @@ class Dnsmasq(DhcpLocalProcess):
413 412
     def _output_hosts_file(self):
414 413
         """Writes a dnsmasq compatible hosts file."""
415 414
         r = re.compile('[:.]')
416
-        buf = StringIO.StringIO()
415
+        buf = six.StringIO()
417 416
 
418 417
         for port in self.network.ports:
419 418
             for alloc in port.fixed_ips:

+ 3
- 3
neutron/tests/unit/test_policy.py View File

@@ -16,11 +16,11 @@
16 16
 """Test of Policy Engine For Neutron"""
17 17
 
18 18
 import json
19
-import StringIO
20 19
 import urllib2
21 20
 
22 21
 import fixtures
23 22
 import mock
23
+import six
24 24
 
25 25
 import neutron
26 26
 from neutron.api.v2 import attributes
@@ -120,7 +120,7 @@ class PolicyTestCase(base.BaseTestCase):
120 120
     def test_enforce_http_true(self):
121 121
 
122 122
         def fakeurlopen(url, post_data):
123
-            return StringIO.StringIO("True")
123
+            return six.StringIO("True")
124 124
 
125 125
         with mock.patch.object(urllib2, 'urlopen', new=fakeurlopen):
126 126
             action = "example:get_http"
@@ -131,7 +131,7 @@ class PolicyTestCase(base.BaseTestCase):
131 131
     def test_enforce_http_false(self):
132 132
 
133 133
         def fakeurlopen(url, post_data):
134
-            return StringIO.StringIO("False")
134
+            return six.StringIO("False")
135 135
 
136 136
         with mock.patch.object(urllib2, 'urlopen', new=fakeurlopen):
137 137
             action = "example:get_http"

Loading…
Cancel
Save