[yum-commits] Branch 'yum-3_2_X' - yum/sqlutils.py

Tim Lauridsen timlau at osuosl.org
Mon Mar 30 09:31:47 UTC 2009


 yum/sqlutils.py |  203 +++++++++++++++++++++++++++-----------------------------
 1 file changed, 101 insertions(+), 102 deletions(-)

New commits:
commit 47e8f10bc64dad4b8b1e47b6ed7a2146d9319189
Author: Tim Lauridsen <timlau at fedoraproject.org>
Date:   Mon Mar 30 11:31:37 2009 +0200

    pylint: tabs -> spaces

diff --git a/yum/sqlutils.py b/yum/sqlutils.py
index 58b63ab..fda380e 100644
--- a/yum/sqlutils.py
+++ b/yum/sqlutils.py
@@ -25,112 +25,112 @@ except ImportError:
     import sqlite
 
 class TokenizeError(Exception):
-	"""Tokenizer error class"""
-	pass
+    """Tokenizer error class"""
+    pass
 
 def Tokenize(str, whitespace=" \t\r\n", quotes="\"", escapes="\\"):
-	"""String tokenizer
-
-	This function tokenizes a string while taking quotation and
-	escaping into account.
-
-	  >>> import dhm.strtools
-	  >>> dhm.strtools.Tokenize("this is a test")
-	  ['this', 'is', 'a', 'test']
-	  >>> dhm.strtools.Tokenize("this \"is a\" test")
-	  ['this', 'is a', 'test']
-	  >>> dhm.strtools.Tokenize("this \\\"is\\\" a test")
-	  ['this', '"is"', 'a', 'test']
-	  >>> dhm.strtools.Tokenize("this \"is a test")
-	  Traceback (most recent call last):
-	    File "<stdin>", line 1, in ?
-	    File "/usr/local/lib/python2.2/site-packages/dhm/strtools.py", line 80, in Tokenize
-	      raise TokenizeError, "Unexpected end of string in quoted text"
-	  dhm.strtools.TokenizeError: Unexecpted end of string in quoted text
-
-	@param        str: string to tokenize
-	@type         str: string
-	@param whitespace: whitespace characters seperating tokens
-	@type  whitespace: string
-	@param     quotes: legal quoting characters
-	@type      quotes: string
-	@param    escapes: characters which can escape quoting characters
-	@type     escapes: string
-	@return: list of tokens
-	@rtype:  sequence of strings
-	"""
-	(buffer, tokens, curtoken, quote)=(str, [], None, None)
-
-	try:
-		while buffer:
-			if buffer[0]==quote:
-				quote=None
-			elif (quote==None) and (buffer[0] in quotes):
-				quote=buffer[0]
-			elif buffer[0] in whitespace:
-				if quote!=None:
-					curtoken+=buffer[0]
-				else:
-					tokens.append(curtoken)
-					curtoken=None
-					while buffer[1] in whitespace:
-						buffer=buffer[1:]
-			elif buffer[0] in escapes:
-				if curtoken==None:
-					curtoken=buffer[1]
-				else:
-					curtoken+=buffer[1]
-				buffer=buffer[1:]
-			else:
-				if curtoken==None:
-					curtoken=buffer[0]
-				else:
-					curtoken+=buffer[0]
-
-			buffer=buffer[1:]
-	except IndexError:
-		raise TokenizeError, "Unexpected end of string"
-	
-	if quote:
-		raise TokenizeError, "Unexpected end of string in quoted text"
-
-	if curtoken!=None:
-		tokens.append(curtoken)
-
-	return tokens
+    """String tokenizer
+
+    This function tokenizes a string while taking quotation and
+    escaping into account.
+
+      >>> import dhm.strtools
+      >>> dhm.strtools.Tokenize("this is a test")
+      ['this', 'is', 'a', 'test']
+      >>> dhm.strtools.Tokenize("this \"is a\" test")
+      ['this', 'is a', 'test']
+      >>> dhm.strtools.Tokenize("this \\\"is\\\" a test")
+      ['this', '"is"', 'a', 'test']
+      >>> dhm.strtools.Tokenize("this \"is a test")
+      Traceback (most recent call last):
+        File "<stdin>", line 1, in ?
+        File "/usr/local/lib/python2.2/site-packages/dhm/strtools.py", line 80, in Tokenize
+          raise TokenizeError, "Unexpected end of string in quoted text"
+      dhm.strtools.TokenizeError: Unexecpted end of string in quoted text
+
+    @param        str: string to tokenize
+    @type         str: string
+    @param whitespace: whitespace characters seperating tokens
+    @type  whitespace: string
+    @param     quotes: legal quoting characters
+    @type      quotes: string
+    @param    escapes: characters which can escape quoting characters
+    @type     escapes: string
+    @return: list of tokens
+    @rtype:  sequence of strings
+    """
+    (buffer, tokens, curtoken, quote)=(str, [], None, None)
+
+    try:
+        while buffer:
+            if buffer[0]==quote:
+                quote=None
+            elif (quote==None) and (buffer[0] in quotes):
+                quote=buffer[0]
+            elif buffer[0] in whitespace:
+                if quote!=None:
+                    curtoken+=buffer[0]
+                else:
+                    tokens.append(curtoken)
+                    curtoken=None
+                    while buffer[1] in whitespace:
+                        buffer=buffer[1:]
+            elif buffer[0] in escapes:
+                if curtoken==None:
+                    curtoken=buffer[1]
+                else:
+                    curtoken+=buffer[1]
+                buffer=buffer[1:]
+            else:
+                if curtoken==None:
+                    curtoken=buffer[0]
+                else:
+                    curtoken+=buffer[0]
+
+            buffer=buffer[1:]
+    except IndexError:
+        raise TokenizeError, "Unexpected end of string"
+    
+    if quote:
+        raise TokenizeError, "Unexpected end of string in quoted text"
+
+    if curtoken!=None:
+        tokens.append(curtoken)
+
+    return tokens
 
 
 def QmarkToPyformat(query, params):
-	"""Convert from qmark to pyformat parameter style.
-
-	The python DB-API 2.0 specifies four different possible parameter
-	styles that can be used by drivers. This function convers from the
-	qmark style to pyformat style.
-
-	@param  query: SQL query to transform
-	@type   query: string
-	@param params: arguments to query
-	@type  params: sequence of strings
-	@return: converted query and parameters
-	@rtype:  tuple with the new command and a dictionary of arguments
-	"""
-	tokens=Tokenize(query, quotes="'")
-	output=[]
-	count=1
-	for token in tokens:
-		if token.endswith("?"):
-			output.append(token[:-1] + "%%(param%d)s" % count)
-			count+=1
-		else:
-			output.append(token)
-
-	dict={}
-	count=1
-	for param in params:
-		dict["param%d" % count]=param
-		count+=1
-	
-	return (" ".join(output), dict)
+    """Convert from qmark to pyformat parameter style.
+
+    The python DB-API 2.0 specifies four different possible parameter
+    styles that can be used by drivers. This function convers from the
+    qmark style to pyformat style.
+
+    @param  query: SQL query to transform
+    @type   query: string
+    @param params: arguments to query
+    @type  params: sequence of strings
+    @return: converted query and parameters
+    @rtype:  tuple with the new command and a dictionary of arguments
+    """
+    tokens=Tokenize(query, quotes="'")
+    output=[]
+    count=1
+    for token in tokens:
+        if token.endswith("?"):
+            output.append(token[:-1] + "%%(param%d)s" % count)
+            count+=1
+        else:
+            output.append(token)
+
+    dict={}
+    count=1
+    for param in params:
+        dict["param%d" % count]=param
+        count+=1
+    
+    return (" ".join(output), dict)
 
 
 def executeSQLPyFormat(cursor, query, params=None):
@@ -168,4 +168,3 @@ else:
     executeSQL = executeSQLPyFormat
 
 
-


More information about the Yum-commits mailing list