remove trailing whitespaces

to improve codacy rating
This commit is contained in:
Bastian Schroll 2016-10-02 21:28:04 +02:00
parent bf27623839
commit 77fb7fb44f
13 changed files with 97 additions and 100 deletions

View file

@ -16,7 +16,7 @@ class MyTimedRotatingFileHandler(logging.handlers.TimedRotatingFileHandler):
def setBackupCount(self, backupCount):
"""Set/Change backupCount"""
self.backupCount = backupCount
def close(self):
"""Make shure logfile will be flushed"""
self.flush()

View file

@ -14,11 +14,11 @@ class NMAHandler(logging.Handler): # Inherit from logging.Handler
"""
Handler instances dispatch logging events to NotifyMyAndroid.
"""
def __init__(self, APIKey, application="BOSWatch", event="Logging-Handler"):
"""
Initializes the handler with NMA-specific parameters.
@param APIKey: might be a string containing 1 key or an array of keys
@param application: application name [256]
@param event: event name [1000]
@ -38,7 +38,7 @@ class NMAHandler(logging.Handler): # Inherit from logging.Handler
"""
# record.message is the log message
message = record.message
# if exist, add details as NMA event:
# record.module is the module- or filename
if (len(record.module) > 0):
@ -51,7 +51,7 @@ class NMAHandler(logging.Handler): # Inherit from logging.Handler
else:
# we have to set an event-text, use self.event now
event = self.event
# record.levelno is the log level
# loglevel: 10 = debug => priority: -2
# loglevel: 20 = info => priority: -1
@ -68,6 +68,6 @@ class NMAHandler(logging.Handler): # Inherit from logging.Handler
priority = -1
else:
priority = -2
# pynma.push(self, application="", event="", description="", url="", contenttype=None, priority=0, batch_mode=False, html=False)
self.nma.push(application=self.application, event=event, description=message, priority=priority)
self.nma.push(application=self.application, event=event, description=message, priority=priority)

View file

@ -47,7 +47,7 @@ def processAlarmHandler(typ, freq, data):
pass
else:
processAlarm(typ, freq, data)
##
#

View file

@ -42,7 +42,7 @@ def decodeString(inputString = ""):
pass
return decodedString
def convertToUnicode(inputString = ""):
"""
Returns given string as unicode
@ -53,10 +53,10 @@ def convertToUnicode(inputString = ""):
@return: string in unicode
@exception: Exception if converting to unicode failed
"""
decodedString = ""
logging.debug("call convertToUnicode('%s')", inputString)
# nothing to do if inputString is empty
if len(inputString) > 0:
# 1. check if integer
@ -68,12 +68,12 @@ def convertToUnicode(inputString = ""):
except ValueError:
# ... no integer is okay...
pass
# 2. Check if inputString is unicode...
if isinstance(inputString, unicode):
logging.debug("-- unicode")
return inputString
try:
# try to decoding:
decodedString = decodeString(inputString)
@ -83,9 +83,9 @@ def convertToUnicode(inputString = ""):
# no fixing possible, raise exception
raise
return decodedString
def convertToUTF8(inputString = ""):
"""
Returns given string in UTF-8
@ -99,7 +99,7 @@ def convertToUTF8(inputString = ""):
uft8String = ""
logging.debug("call convertToUTF8('%s')", inputString)
# nothing to do if inputString is empty
if len(inputString) > 0:
try:
@ -111,20 +111,20 @@ def convertToUTF8(inputString = ""):
return inputString
except ValueError:
pass
# 2. Check if inputString is unicode...
if isinstance(inputString, unicode):
logging.debug("-- unicode")
# ... then return it as UTF-8
uft8String = decodedString.encode('UTF-8')
return uft8String
# 2. check given inputString is already UTF-8...
decodedString = inputString.decode('UTF-8', 'strict')
# ... no UnicodeDecodeError exception, inputString ist UTF-8
logging.debug("-- UTF-8")
return inputString
except UnicodeDecodeError:
# inputString contains non-UTF-8 character
logging.debug("string contains non-UTF-8 characters: %s", inputString)
@ -137,9 +137,9 @@ def convertToUTF8(inputString = ""):
logging.debug("encoding string failed", exc_info=True)
# no fixing possible, raise exception
raise
# inputString should now decoded...
try:
# encode decodedString to UTF-8
uft8String = decodedString.encode('UTF-8')
@ -148,7 +148,7 @@ def convertToUTF8(inputString = ""):
logging.debug("encoding to UTF-8 failed", exc_info=True)
# no fixing possible, raise exception
raise
# Now we must have an utf8-string, check it:
try:
uft8String.decode('UTF-8', 'strict')
@ -158,7 +158,7 @@ def convertToUTF8(inputString = ""):
logging.debug("converting to UTF-8 failed", exc_info=True)
# no fixing possible, raise exception
raise
# End of exception UnicodeDecodeError: check given string is already UTF-8
pass
@ -168,4 +168,4 @@ def convertToUTF8(inputString = ""):
# no fixing possible, raise exception
raise
return uft8String
return uft8String

View file

@ -32,7 +32,7 @@ def replaceWildcards(text, data, lineBrakeAllowed=False):
try:
# replace date and time wildcards
text = text.replace("%TIME%", timeHandler.getTime(data["timestamp"])).replace("%DATE%", timeHandler.getDate(data["timestamp"]))
# replace some special chars
if lineBrakeAllowed == True:
text = text.replace("%BR%", "\r\n")

View file

@ -1,4 +1,3 @@
#!/usr/bin/python
from .pynma import PyNMA
from .pynma import PyNMA

View file

@ -14,7 +14,7 @@ except ImportError:
__version__ = "1.0"
API_SERVER = 'www.notifymyandroid.com'
API_SERVER = 'www.notifymyandroid.com'
ADD_PATH = '/publicapi/notify'
USER_AGENT="PyNMA/v%s"%__version__
@ -75,7 +75,7 @@ takes 2 optional arguments:
apikey = [apikey]
self._apikey = uniq(apikey)
return self.push(application, event, description, url, contenttype, priority, batch_mode, html)
def push(self, application="", event="", description="", url="", contenttype=None, priority=0, batch_mode=False, html=False):
"""Pushes a message on the registered API keys.
takes 5 arguments:
@ -99,10 +99,10 @@ Warning: using batch_mode will return error only if all API keys are bad
if url:
datas['url'] = url[:512]
if contenttype == "text/html" or html == True: # Currently only accepted content type
datas['content-type'] = "text/html"
if self._developerkey:
datas['developerkey'] = self._developerkey
@ -118,7 +118,7 @@ Warning: using batch_mode will return error only if all API keys are bad
res = self.callapi('POST', ADD_PATH, datas)
results[datas['apikey']] = res
return results
def callapi(self, method, path, args):
headers = { 'User-Agent': USER_AGENT }
if method == "POST":
@ -135,7 +135,7 @@ Warning: using batch_mode will return error only if all API keys are bad
'message': str(e)
}
pass
return res
def _parse_reponse(self, response):
@ -152,5 +152,3 @@ Warning: using batch_mode will return error only if all API keys are bad
res['message'] = elem.firstChild.nodeValue
res['type'] = elem.tagName
return res