From 20a7a0c4263c5c6b501a8321adefc2d335498132 Mon Sep 17 00:00:00 2001 From: Nikos Kouremenos Date: Fri, 26 Aug 2005 12:34:11 +0000 Subject: [PATCH] isinstance() is faster than type. pydoc timeit --- src/common/logger.py | 9 +++++---- src/common/optparser.py | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/common/logger.py b/src/common/logger.py index 7d0848f05..16e3dc231 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -127,13 +127,14 @@ class Logger: files.append(ji + '/' + ji) jid = 'gc' show = nick - if type(tim) == unicode: + # convert to utf8 before writing to file if needed + if isinstance(tim, unicode): tim = tim.encode('utf-8') - if type(jid) == unicode: + if isinstance(jid, unicode): jid = jid.encode('utf-8') - if type(show) == unicode: + if isinstance(show, unicode): show = show.encode('utf-8') - if msg and type(msg) == unicode: + if msg and isinstance(msg, unicode): msg = msg.encode('utf-8') for f in files: path_to_file = os.path.join(LOGPATH, f) diff --git a/src/common/optparser.py b/src/common/optparser.py index 2dc3820fb..f507db5ec 100644 --- a/src/common/optparser.py +++ b/src/common/optparser.py @@ -61,18 +61,19 @@ class OptionsParser: if value == None: return value = value[1] - if type(value) == unicode: + # convert to utf8 before writing to file if needed + if isinstance(value, unicode): value = value.encode('utf-8') else: value = str(value) - if type(opt) == unicode: + if isinstance(opt, unicode): opt = opt.encode('utf-8') s = '' if parents: if len(parents) == 1: return for p in parents: - if type(p) == unicode: + if isinstance(p, unicode): p = p.encode('utf-8') s += p + '.' s += opt