diff options
author | Frederic Peters <fpeters@entrouvert.com> | 2008-04-29 12:03:40 +0000 |
---|---|---|
committer | Frederic Peters <fpeters@entrouvert.com> | 2008-04-29 12:03:40 +0000 |
commit | f8233551a19ce4ead9f809d39cff49a94126d141 (patch) | |
tree | 68e751acd033f8c0b99f935fe578ae2b32bef338 /bindings/utils.py | |
parent | 21607461fee5e76640aff9bee710119c07fcc69f (diff) | |
download | lasso-f8233551a19ce4ead9f809d39cff49a94126d141.tar.gz lasso-f8233551a19ce4ead9f809d39cff49a94126d141.tar.xz lasso-f8233551a19ce4ead9f809d39cff49a94126d141.zip |
[project @ fpeters@0d.be-20071031114522-jkrmvbpphcm0rms8]
moved identifier name formatting functions to their own module, so they are not
duplicated everywhere.
Original author: Frederic Peters <fpeters@0d.be>
Date: 2007-10-31 12:45:22.367000+01:00
Diffstat (limited to 'bindings/utils.py')
-rw-r--r-- | bindings/utils.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/bindings/utils.py b/bindings/utils.py new file mode 100644 index 00000000..3e95a7ac --- /dev/null +++ b/bindings/utils.py @@ -0,0 +1,49 @@ +# Lasso - A free implementation of the Liberty Alliance specifications. +# +# Copyright (C) 2004-2007 Entr'ouvert +# http://lasso.entrouvert.org +# +# Authors: See AUTHORS file in top-level directory. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import re +import string + +def format_as_camelcase(var): + '''Format an identifier name into CamelCase''' + if '_' in var: + return format_underscore_as_camelcase(var) + if var[0] in string.uppercase: + var = var[0].lower() + var[1:] + return var + +def format_as_underscored(var): + '''Format an identifier name into underscored_name''' + def rep(s): + return s.group(0)[0] + '_' + s.group(1).lower() + var = re.sub(r'[a-z0-9]([A-Z])', rep, var).lower() + var = var.replace('id_wsf2_', 'idwsf2_') + var = var.replace('_saslresponse', '_sasl_response') + return var + +def format_underscore_as_camelcase(var): + '''Format an underscored identifier name into CamelCase''' + def rep(s): + return s.group(1)[0].upper() + s.group(1)[1:] + var = re.sub(r'_([A-Za-z0-9]+)', rep, var) + var = re.sub(r'([a-z])(ID)([A-Z]|$)', r'\1Id\3', var) # replace standing ID by Id + return var + |