paulb@8 | 1 | #!/usr/bin/env python |
paulb@8 | 2 | |
paulb@8 | 3 | """ |
paulb@8 | 4 | Convert one paramstyle to another in SQL statements. |
paulb@8 | 5 | |
paulb@8 | 6 | Copyright (C) 2007 Paul Boddie <paul@boddie.org.uk> |
paulb@8 | 7 | |
paulb@8 | 8 | This library is free software; you can redistribute it and/or |
paulb@8 | 9 | modify it under the terms of the GNU Lesser General Public |
paulb@8 | 10 | License as published by the Free Software Foundation; either |
paulb@8 | 11 | version 2.1 of the License, or (at your option) any later version. |
paulb@8 | 12 | |
paulb@8 | 13 | This library is distributed in the hope that it will be useful, |
paulb@8 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
paulb@8 | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
paulb@8 | 16 | Lesser General Public License for more details. |
paulb@8 | 17 | |
paulb@8 | 18 | You should have received a copy of the GNU Lesser General Public |
paulb@8 | 19 | License along with this library; if not, write to the Free Software |
paulb@8 | 20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
paulb@8 | 21 | """ |
paulb@8 | 22 | |
paulb@8 | 23 | def replace(fromstyle, tostyle, regions): |
paulb@8 | 24 | |
paulb@8 | 25 | """ |
paulb@8 | 26 | Return a new sequence of regions, where the paramstyle 'fromstyle' is |
paulb@8 | 27 | replaced with 'tostyle' in the appropriate elements of 'regions'. |
paulb@8 | 28 | """ |
paulb@8 | 29 | |
paulb@8 | 30 | new_regions = [] |
paulb@8 | 31 | non_literal = 1 |
paulb@8 | 32 | for region in regions: |
paulb@8 | 33 | if non_literal: |
paulb@8 | 34 | new_regions.append(region.replace(fromstyle, tostyle)) |
paulb@8 | 35 | else: |
paulb@8 | 36 | new_regions.append(region) |
paulb@8 | 37 | non_literal = not non_literal |
paulb@8 | 38 | return new_regions |
paulb@8 | 39 | |
paulb@8 | 40 | # vim: tabstop=4 expandtab shiftwidth=4 |