Refactoring: make functions to be private if we can

Make external API of class/module to be smaller, explicitely mark
all internal functions.  Also annotate methods that are implemented
as the part of the parent class interface.

Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
This commit is contained in:
Eygene Ryabinkin
2014-03-16 16:27:35 +04:00
parent af2d6dc5e1
commit 6cbd2498ae
14 changed files with 218 additions and 136 deletions

View File

@ -21,7 +21,7 @@ import string
from offlineimap.ui import getglobalui
def debug(*args):
def __debug(*args):
msg = []
for arg in args:
msg.append(str(arg))
@ -50,7 +50,7 @@ def flagsplit(string):
raise ValueError("Passed string '%s' is not a flag list" % string)
return imapsplit(string[1:-1])
def options2hash(list):
def __options2hash(list):
"""convert list [1,2,3,4,5,6] to {1:2, 3:4, 5:6}"""
# effectively this does dict(zip(l[::2],l[1::2])), however
# measurements seemed to have indicated that the manual variant is
@ -60,7 +60,7 @@ def options2hash(list):
while (counter < len(list)):
retval[list[counter]] = list[counter + 1]
counter += 2
debug("options2hash returning:", retval)
__debug("__options2hash returning:", retval)
return retval
def flags2hash(flags):
@ -68,7 +68,7 @@ def flags2hash(flags):
E.g. '(FLAGS (\\Seen Old) UID 4807)' leads to
{'FLAGS': '(\\Seen Old)', 'UID': '4807'}"""
return options2hash(flagsplit(flags))
return __options2hash(flagsplit(flags))
def imapsplit(imapstring):
"""Takes a string from an IMAP conversation and returns a list containing
@ -81,7 +81,7 @@ def imapsplit(imapstring):
['(\\HasNoChildren)', '"."', '"INBOX.Sent"']"""
if not isinstance(imapstring, basestring):
debug("imapsplit() got a non-string input; working around.")
__debug("imapsplit() got a non-string input; working around.")
# Sometimes, imaplib will throw us a tuple if the input
# contains a literal. See Python bug
# #619732 at https://sourceforge.net/tracker/index.php?func=detail&aid=619732&group_id=5470&atid=105470
@ -103,7 +103,7 @@ def imapsplit(imapstring):
arg = arg.replace('\\', '\\\\')
arg = arg.replace('"', '\\"')
arg = '"%s"' % arg
debug("imapsplit() non-string [%d]: Appending %s" %\
__debug("imapsplit() non-string [%d]: Appending %s" %\
(i, arg))
retval.append(arg)
else:
@ -113,10 +113,10 @@ def imapsplit(imapstring):
# Recursion to the rescue.
arg = imapstring[i]
arg = re.sub('\{\d+\}$', '', arg)
debug("imapsplit() non-string [%d]: Feeding %s to recursion" %\
__debug("imapsplit() non-string [%d]: Feeding %s to recursion" %\
(i, arg))
retval.extend(imapsplit(arg))
debug("imapsplit() non-string: returning %s" % str(retval))
__debug("imapsplit() non-string: returning %s" % str(retval))
return retval
workstr = imapstring.strip()
@ -137,7 +137,7 @@ def imapsplit(imapstring):
retval.append(parenlist)
elif workstr[0] == '"':
# quoted fragments '"...\"..."'
(quoted, rest) = _split_quoted(workstr)
(quoted, rest) = __split_quoted(workstr)
retval.append(quoted)
workstr = rest
else:
@ -213,7 +213,7 @@ def uid_sequence(uidlist):
return ",".join(retval)
def _split_quoted(string):
def __split_quoted(string):
"""
Looks for the ending quote character in the string that starts
with quote character, splitting out quoted component and the