minimize.py
Go to the documentation of this file.
00001 # Minimal Python Minimizer
00002 # Copyright 2008, Christopher Schmidt
00003 # Released under the MIT License
00004 #
00005 # Taken from: http://svn.crschmidt.net/personal/python/minimize.py
00006 # $Id: minimize.py 6 2008-01-03 06:33:35Z crschmidt $
00007 #
00008 # Permission is hereby granted, free of charge, to any person obtaining a copy
00009 # of this software and associated documentation files (the "Software"), to deal
00010 # in the Software without restriction, including without limitation the rights
00011 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00012 # copies of the Software, and to permit persons to whom the Software is
00013 # furnished to do so, subject to the following conditions:
00014 # 
00015 # The above copyright notice and this permission notice shall be included in
00016 # all copies or substantial portions of the Software.
00017 # 
00018 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00019 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00020 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00021 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00022 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00023 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00024 # THE SOFTWARE.
00025 
00026 import re
00027 
00028 def strip_comments_helper(data):
00029     """remove all /* */ format comments and surrounding whitespace."""
00030     p = re.compile(r'[\s]*/\*.*?\*/[\s]*', re.DOTALL)
00031     return p.sub('',data)
00032 
00033 def minimize(data, exclude=None):
00034     """Central function call. This will call all other compression
00035        functions. To add further compression algorithms, simply add
00036        functions whose names end in _helper which take a string as input 
00037        and return a more compressed string as output."""
00038     for key, item in globals().iteritems():
00039         if key.endswith("_helper"):
00040             func_key = key[:-7]
00041             if not exclude or not func_key in exclude:   
00042                 data = item(data)
00043     return data   
00044 
00045 if __name__ == "__main__":
00046     import sys
00047     print minimize(open(sys.argv[1]).read())


websocket_gui
Author(s): Benoit Lescot and Stéphane Magnenat
autogenerated on Sat Dec 28 2013 17:46:48