Skip to content

Commit

Permalink
Check chardet availability before using it
Browse files Browse the repository at this point in the history
The use of chardet python library is quite useful in order to detect character encodings, but it's not installed in all systems by default. So, it's a good practice to check its availability before using it.

This pull request enhances shinken-monitoring#7
  • Loading branch information
dgilm committed Sep 29, 2014
1 parent 7bcfdee commit bab7f8b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
except ImportError:
MySQLdb = None

import chardet
try:
import chardet
except ImportError:
chardet = None

from shinken.basemodule import BaseModule
from shinken.log import logger
Expand Down Expand Up @@ -140,7 +143,9 @@ def get_objects(self):
for column in row:
if row[column]:
value = str(row[column])
h[column] = self.ensure_encoding(value)
if chardet:
value = self.ensure_encoding(value)
h[column] = value
r[k].append(h)

cursor.close()
Expand Down

0 comments on commit bab7f8b

Please sign in to comment.