# HG changeset patch # User paulb@localhost.localdomain # Date 1186958089 -7200 # Node ID 48e3ffe9a1bee347ff788f301c4d167ff87f774c # Parent 070e83791931a8b00ca44f1a65f6a2a3b6053b07 Added missing common module. diff -r 070e83791931 -r 48e3ffe9a1be sqlliterals/common.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sqlliterals/common.py Mon Aug 13 00:34:49 2007 +0200 @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +""" +Convert one paramstyle to another in SQL statements. + +Copyright (C) 2007 Paul Boddie + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +""" + +def replace(fromstyle, tostyle, regions): + + """ + Return a new sequence of regions, where the paramstyle 'fromstyle' is + replaced with 'tostyle' in the appropriate elements of 'regions'. + """ + + new_regions = [] + non_literal = 1 + for region in regions: + if non_literal: + new_regions.append(region.replace(fromstyle, tostyle)) + else: + new_regions.append(region) + non_literal = not non_literal + return new_regions + +# vim: tabstop=4 expandtab shiftwidth=4