Show
Ignore:
Timestamp:
09/27/08 22:02:37 (16 years ago)
Author:
jerome
Message:

Removed unnecessary spaces at EOL.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storages/pgstorage.py

    r3411 r3413  
    88# the Free Software Foundation, either version 3 of the License, or 
    99# (at your option) any later version. 
    10 #  
     10# 
    1111# This program is distributed in the hope that it will be useful, 
    1212# but WITHOUT ANY WARRANTY; without even the implied warranty of 
    1313# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414# GNU General Public License for more details. 
    15 #  
     15# 
    1616# You should have received a copy of the GNU General Public License 
    1717# along with this program.  If not, see <http://www.gnu.org/licenses/>. 
     
    2929from pykota.storages.sql import SQLStorage 
    3030 
    31 from pykota.utils import *                            
     31from pykota.utils import * 
    3232 
    3333try : 
    3434    import pg 
    35 except ImportError :     
     35except ImportError : 
    3636    import sys 
    3737    # TODO : to translate or not to translate ? 
    3838    raise PyKotaStorageError, "This python version (%s) doesn't seem to have the PygreSQL module installed correctly." % sys.version.split()[0] 
    39 else :     
     39else : 
    4040    try : 
    4141        PGError = pg.Error 
    42     except AttributeError :     
     42    except AttributeError : 
    4343        PGError = pg.error 
    4444 
     
    5050            (host, port) = host.split(":") 
    5151            port = int(port) 
    52         except ValueError :     
     52        except ValueError : 
    5353            port = 5432         # Use PostgreSQL's default tcp/ip port (5432). 
    54          
     54 
    5555        self.tool.logdebug("Trying to open database (host=%s, port=%s, dbname=%s, user=%s)..." % (host, port, dbname, user)) 
    5656        try : 
    5757            self.database = pg.connect(host=host, port=port, dbname=dbname, user=user, passwd=passwd) 
    58         except PGError, msg :     
     58        except PGError, msg : 
    5959            msg = "%(msg)s --- the most probable cause of your problem is that PostgreSQL is down, or doesn't accept incoming connections because you didn't configure it as explained in PyKota's documentation." % locals() 
    6060            raise PGError, msg 
     
    6262        try : 
    6363            self.database.query("SET CLIENT_ENCODING TO 'UTF-8';") 
    64         except PGError, msg :     
     64        except PGError, msg : 
    6565            self.tool.logdebug("Impossible to set database client encoding to UTF-8 : %s" % msg) 
    6666        self.tool.logdebug("Database opened (host=%s, port=%s, dbname=%s, user=%s)" % (host, port, dbname, user)) 
    67              
    68     def close(self) :     
     67 
     68    def close(self) : 
    6969        """Closes the database connection.""" 
    7070        if not self.closed : 
     
    7272            self.closed = 1 
    7373            self.tool.logdebug("Database closed.") 
    74          
    75     def beginTransaction(self) :     
     74 
     75    def beginTransaction(self) : 
    7676        """Starts a transaction.""" 
    7777        self.database.query("BEGIN;") 
    7878        self.tool.logdebug("Transaction begins...") 
    79          
    80     def commitTransaction(self) :     
     79 
     80    def commitTransaction(self) : 
    8181        """Commits a transaction.""" 
    8282        self.database.query("COMMIT;") 
    8383        self.tool.logdebug("Transaction committed.") 
    84          
    85     def rollbackTransaction(self) :      
     84 
     85    def rollbackTransaction(self) : 
    8686        """Rollbacks a transaction.""" 
    8787        self.database.query("ROLLBACK;") 
    8888        self.tool.logdebug("Transaction aborted.") 
    89          
     89 
    9090    def doRawSearch(self, query) : 
    9191        """Does a raw search query.""" 
    92         query = query.strip()     
    93         if not query.endswith(';') :     
     92        query = query.strip() 
     93        if not query.endswith(';') : 
    9494            query += ';' 
    9595        try : 
    9696            self.querydebug("QUERY : %s" % query) 
    9797            return self.database.query(query) 
    98         except PGError, msg :     
     98        except PGError, msg : 
    9999            raise PyKotaStorageError, repr(msg) 
    100              
    101     def doSearch(self, query) :         
     100 
     101    def doSearch(self, query) : 
    102102        """Does a search query.""" 
    103103        result = self.doRawSearch(query) 
    104         if (result is not None) and (result.ntuples() > 0) :  
     104        if (result is not None) and (result.ntuples() > 0) : 
    105105            return result.dictresult() 
    106          
     106 
    107107    def doModify(self, query) : 
    108108        """Does a (possibly multiple) modify query.""" 
    109         query = query.strip()     
    110         if not query.endswith(';') :     
     109        query = query.strip() 
     110        if not query.endswith(';') : 
    111111            query += ';' 
    112112        try : 
    113113            self.querydebug("QUERY : %s" % query) 
    114114            return self.database.query(query) 
    115         except PGError, msg :     
     115        except PGError, msg : 
    116116            self.tool.logdebug("Query failed : %s" % repr(msg)) 
    117117            raise PyKotaStorageError, repr(msg) 
    118              
     118 
    119119    def doQuote(self, field) : 
    120120        """Quotes a field for use as a string in SQL queries.""" 
    121         if type(field) == type(0.0) :  
     121        if type(field) == type(0.0) : 
    122122            typ = "decimal" 
    123         elif type(field) == type(0) :     
     123        elif type(field) == type(0) : 
    124124            typ = "int" 
    125         elif type(field) == type(0L) :     
     125        elif type(field) == type(0L) : 
    126126            typ = "int" 
    127         else :     
     127        else : 
    128128            typ = "text" 
    129129        return pg._quote(field, typ) 
    130          
     130 
    131131    def prepareRawResult(self, result) : 
    132132        """Prepares a raw result by including the headers.""" 
     
    140140                    field = fields[j] 
    141141                    if type(field) == StringType : 
    142                         fields[j] = databaseToUnicode(field)  
    143                 entries[i] = tuple(fields)     
     142                        fields[j] = databaseToUnicode(field) 
     143                entries[i] = tuple(fields) 
    144144            return entries 
    145          
     145