Changed indentation and wrote docstring for each function.
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
# @Author: KevinMidboe
|
# @Author: KevinMidboe
|
||||||
# @Date: 2017-11-01 15:57:23
|
# @Date: 2017-11-01 15:57:23
|
||||||
# @Last Modified by: KevinMidboe
|
# @Last Modified by: KevinMidboe
|
||||||
# @Last Modified time: 2017-12-22 11:16:09
|
# @Last Modified time: 2017-12-22 12:07:18
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
@@ -24,6 +24,9 @@ SYMBOLS = {
|
|||||||
__all__ = ('ColorizeFilter', )
|
__all__ = ('ColorizeFilter', )
|
||||||
|
|
||||||
class ColorizeFilter(logging.Filter):
|
class ColorizeFilter(logging.Filter):
|
||||||
|
"""
|
||||||
|
Class for setting specific colors to levels of severity for log output
|
||||||
|
"""
|
||||||
|
|
||||||
color_by_level = {
|
color_by_level = {
|
||||||
logging.DEBUG: 'yellow',
|
logging.DEBUG: 'yellow',
|
||||||
@@ -40,7 +43,8 @@ class ColorizeFilter(logging.Filter):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def sanitize(string, ignore_characters=None, replace_characters=None):
|
def sanitize(string, ignore_characters=None, replace_characters=None):
|
||||||
"""Sanitize a string to strip special characters.
|
"""
|
||||||
|
Sanitize a string to strip special characters.
|
||||||
|
|
||||||
:param str string: the string to sanitize.
|
:param str string: the string to sanitize.
|
||||||
:param set ignore_characters: characters to ignore.
|
:param set ignore_characters: characters to ignore.
|
||||||
@@ -63,24 +67,31 @@ def sanitize(string, ignore_characters=None, replace_characters=None):
|
|||||||
return string
|
return string
|
||||||
|
|
||||||
def return_re_match(string, re_statement):
|
def return_re_match(string, re_statement):
|
||||||
|
"""
|
||||||
|
Helper function for checking if a string contains a given regex statement
|
||||||
|
|
||||||
|
:param str string, str re_statement: string we want to check and regex string we
|
||||||
|
check for in string
|
||||||
|
:return: sanitized string of the match we found
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
if string is None:
|
if string is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
m = re.search(re_statement, string)
|
m = re.search(re_statement, string)
|
||||||
|
# This is here for a edge case for piratebay torrent dates
|
||||||
if 'Y-day' in m.group():
|
if 'Y-day' in m.group():
|
||||||
return datetime.now().strftime('%m-%d %Y')
|
return datetime.now().strftime('%m-%d %Y')
|
||||||
return sanitize(m.group(), '\xa0', ' ')
|
return sanitize(m.group(), '\xa0', ' ')
|
||||||
|
|
||||||
|
|
||||||
# Can maybe be moved away from this class
|
|
||||||
# returns a number that is either the value of multiple_pages
|
|
||||||
# or if it exceeds total_pages, return total_pages.
|
|
||||||
def pagesToCount(multiple, total):
|
|
||||||
if (multiple > total):
|
|
||||||
return total
|
|
||||||
return multiple
|
|
||||||
|
|
||||||
def representsInteger(str):
|
def representsInteger(str):
|
||||||
|
"""
|
||||||
|
Checks if a string only contains integers
|
||||||
|
|
||||||
|
:param str str: string we want to check only has integers
|
||||||
|
:return: if string only contains integers
|
||||||
|
:rtype: boolean
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
int(str)
|
int(str)
|
||||||
return True
|
return True
|
||||||
@@ -121,6 +132,13 @@ def deHumansize(s):
|
|||||||
return int(num * prefix[letter])
|
return int(num * prefix[letter])
|
||||||
|
|
||||||
def humansize(nbytes):
|
def humansize(nbytes):
|
||||||
|
"""
|
||||||
|
Translates a size in bytes to a human readable size format
|
||||||
|
|
||||||
|
:param int nbytes: integer of size of torrent file
|
||||||
|
:return: size in bytes in a human readable format
|
||||||
|
:rtype: str
|
||||||
|
"""
|
||||||
suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
|
suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
|
||||||
i = 0
|
i = 0
|
||||||
while nbytes >= 1024 and i < len(suffixes)-1:
|
while nbytes >= 1024 and i < len(suffixes)-1:
|
||||||
@@ -128,3 +146,4 @@ def humansize(nbytes):
|
|||||||
i += 1
|
i += 1
|
||||||
f = ('%.2f' % nbytes).rstrip('0').rstrip('.')
|
f = ('%.2f' % nbytes).rstrip('0').rstrip('.')
|
||||||
return '{} {}'.format(f, suffixes[i])
|
return '{} {}'.format(f, suffixes[i])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user