Skip to content

Commit 6900bf0

Browse files
author
qq
committed
config parser python 2/3 copability
1 parent 3e23b9f commit 6900bf0

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

pyprind/email_notification.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import base64
22
import os
3-
from ConfigParser import ConfigParser
3+
try:
4+
import configparser
5+
except ImportError:
6+
import ConfigParser as configparser
47

58
try:
69
from Crypto.Cipher import AES
@@ -61,10 +64,10 @@ def setup_email(smtp_server, smtp_port, username, password):
6164
dir_path = os.path.dirname(os.path.abspath(__file__))
6265
file_path = os.path.join(dir_path, 'email_settings.ini.enc')
6366
cipher = AESCipher()
64-
config = ConfigParser()
67+
config = configparser.ConfigParser()
6568
config.add_section('Email')
6669
config.set('Email', 'smtp_server', smtp_server)
67-
config.set('Email', 'smtp_port', smtp_port)
70+
config.set('Email', 'smtp_port', str(smtp_port))
6871
config.set('Email', 'username', username)
6972
config.set('Email', 'password', password)
7073
with open(file_path, 'wb') as f:

pyprind/prog_class.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@
2525
from io import StringIO
2626

2727
try:
28-
from ConfigParser import ConfigParser
28+
import configparser
2929
except ImportError:
30-
from configparser import ConfigParser
31-
30+
import ConfigParser as configparser
3231

3332
try:
3433
import psutil
@@ -86,7 +85,7 @@ def parse_email_config():
8685
raw_data = cipher.decrypt()
8786
buf.write(raw_data)
8887
buf.seek(0, os.SEEK_SET)
89-
config = ConfigParser()
88+
config = configparser.ConfigParser()
9089
config.readfp(buf)
9190
return config
9291

0 commit comments

Comments
 (0)