diff options
author | Yann Leboulanger <asterix@lagaule.org> | 2008-12-04 00:56:12 +0300 |
---|---|---|
committer | Yann Leboulanger <asterix@lagaule.org> | 2008-12-04 00:56:12 +0300 |
commit | e389e0b16b3a598efb29986673761b44360a1b59 (patch) | |
tree | a3ca3bff2e9998440d3030385c8accfeec2685ce /src/common/xmpp/debug.py | |
parent | 0d336839446d4ea223bcfc9bf849e620c825c3ec (diff) |
[thorstenp] remove whitespace at eol
Diffstat (limited to 'src/common/xmpp/debug.py')
-rw-r--r-- | src/common/xmpp/debug.py | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/src/common/xmpp/debug.py b/src/common/xmpp/debug.py index 769f09f19..4107ec895 100644 --- a/src/common/xmpp/debug.py +++ b/src/common/xmpp/debug.py @@ -1,4 +1,4 @@ -## debug.py +## debug.py ## ## Copyright (C) 2003 Jacob Lundqvist ## @@ -19,7 +19,7 @@ Other modules can always define extra debug flags for local usage, as long as they make sure they append them to debug_flags Also its always a good thing to prefix local flags with something, to reduce risk -of coliding flags. Nothing breaks if two flags would be identical, but it might +of coliding flags. Nothing breaks if two flags would be identical, but it might activate unintended debugging. flags can be numeric, but that makes analysing harder, on creation its @@ -104,12 +104,12 @@ class NoDebug: pass def active_set( self, active_flags = None ): return 0 - + LINE_FEED = '\n' -class Debug: +class Debug: def __init__( self, # # active_flags are those that will trigger output @@ -128,7 +128,7 @@ class Debug: prefix = 'DEBUG: ', sufix = '\n', # - # If you want unix style timestamps, + # If you want unix style timestamps, # 0 disables timestamps # 1 before prefix, good when prefix is a string # 2 after prefix, good when prefix is a color @@ -138,8 +138,8 @@ class Debug: # flag_show should normaly be of, but can be turned on to get a # good view of what flags are actually used for calls, # if it is not None, it should be a string - # flags for current call will be displayed - # with flag_show as separator + # flags for current call will be displayed + # with flag_show as separator # recomended values vould be '-' or ':', but any string goes # flag_show = None, @@ -153,14 +153,14 @@ class Debug: # default is to show welcome if any flags are active welcome = -1 ): - + self.debug_flags = [] if welcome == -1: if active_flags and len(active_flags): welcome = 1 else: welcome = 0 - + self._remove_dupe_flags() if log_file: if isinstance(log_file, str): @@ -173,7 +173,7 @@ class Debug: self._fh = log_file else: self._fh = sys.stdout - + if time_stamp not in (0,1,2): raise Exception('Invalid time_stamp param "%s"' % str(time_stamp)) self.prefix = prefix @@ -206,18 +206,18 @@ class Debug: flag can be of folowing types: None - this msg will always be shown if any debugging is on flag - will be shown if flag is active - (flag1,flag2,,,) - will be shown if any of the given flags + (flag1,flag2,,,) - will be shown if any of the given flags are active if prefix / sufix are not given, default ones from init will be used - + lf = -1 means strip linefeed if pressent lf = 1 means add linefeed if not pressent """ - + if self.validate_flags: self._validate_flag( flag ) - + if not self.is_active(flag): return if prefix: @@ -241,7 +241,7 @@ class Debug: ) else: output = pre - + if self.flag_show: if flag: output = '%s%s%s' % ( output, flag, self.flag_show ) @@ -271,7 +271,7 @@ class Debug: s=s+c self._fh.write( '%s%s%s' % ( pre, s, suf )) self._fh.flush() - + def active_set( self, active_flags = None ): "returns 1 if any flags where actually set, otherwise 0." r = 0 @@ -285,7 +285,7 @@ class Debug: if t not in self.debug_flags: print 'Invalid debugflag given', t ok_flags.append( t ) - + self.active = ok_flags r = 1 else: @@ -298,7 +298,7 @@ class Debug: self.show( '*** please correct your param!' ) self.show( '*** due to this, full debuging is enabled' ) self.active = self.debug_flags - + for f in flags: s = f.strip() ok_flags.append( s ) @@ -306,15 +306,15 @@ class Debug: self._remove_dupe_flags() return r - + def active_get( self ): "returns currently active flags." return self.active - - + + def _as_one_list( self, items ): """ init param might contain nested lists, typically from group flags. - + This code organises lst and remves dupes """ if not isinstance(items, (list, tuple)): @@ -323,15 +323,15 @@ class Debug: for l in items: if isinstance(l, list): lst2 = self._as_one_list( l ) - for l2 in lst2: + for l2 in lst2: self._append_unique_str(r, l2 ) elif l is None: continue else: self._append_unique_str(r, l ) return r - - + + def _append_unique_str( self, lst, item ): """filter out any dupes.""" if not isinstance(item, str): @@ -342,7 +342,7 @@ class Debug: lst.append( item ) return lst - + def _validate_flag( self, flags ): 'verify that flag is defined.' if flags: @@ -353,7 +353,7 @@ class Debug: def _remove_dupe_flags( self ): """ - if multiple instances of Debug is used in same app, + if multiple instances of Debug is used in same app, some flags might be created multiple time, filter out dupes """ unique_flags = [] @@ -371,12 +371,12 @@ class Debug: if not colors_enabled: prefixcolor='' elif flag in self.colors: prefixcolor=self.colors[flag] else: prefixcolor=color_none - + if prefix=='error': _exception = sys.exc_info() if _exception[0]: msg=msg+'\n'+''.join(traceback.format_exception(_exception[0], _exception[1], _exception[2])).rstrip() - + prefix= self.prefix+prefixcolor+(flag+' '*12)[:12]+' '+(prefix+' '*6)[:6] self.show(msg, flag, prefix) |