Skip to content

Commit 94d3fc3

Browse files
hugho-adetobella
authored andcommitted
[FIX] dual compatibility py2.7 py3.5 (#3)
1 parent 4a04ada commit 94d3fc3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

profiler/models/profiler_profile.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
import pstats
66
import re
77
import subprocess
8-
import lxml.html
8+
import sys
99
from contextlib import contextmanager
1010
from cProfile import Profile
11-
from io import BytesIO
1211

12+
import lxml.html
1313
from psycopg2 import OperationalError, ProgrammingError
1414

15-
from odoo import api, exceptions, fields, models, sql_db, tools, _
15+
from odoo import _, api, exceptions, fields, models, sql_db, tools
16+
17+
if sys.version_info[0] >= 3:
18+
from io import StringIO as IO
19+
else:
20+
from io import BytesIO as IO
1621

1722
DATETIME_FORMAT_FILE = "%Y%m%d_%H%M%S"
1823
CPROFILE_EMPTY_CHARS = b"{0"
@@ -241,7 +246,7 @@ def _reset_connection(self, enable):
241246
ProfilerProfile.activate_deactivate_pglogs = enable
242247

243248
def get_stats_string(self, cprofile_path):
244-
pstats_stream = BytesIO()
249+
pstats_stream = IO()
245250
pstats_obj = pstats.Stats(cprofile_path, stream=pstats_stream)
246251
pstats_obj.sort_stats('cumulative')
247252
pstats_obj.print_stats()

0 commit comments

Comments
 (0)