liftoff / pyminifier

Pyminifier is a Python code minifier, obfuscator, and compressor.
GNU General Public License v3.0
1.46k stars 221 forks source link

Obfuscation conflicts with submodules and function names #38

Open themiurgo opened 9 years ago

themiurgo commented 9 years ago

Pyminifier seems to have problems with submodules that have the same name as modules, such as datetime.datetime:

# test.py
import datetime
print datetime.datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M")

# test_obf.py
# Produced by `pyminifier -O test.py > test_obf.py`
import datetime
q=datetime.strptime
V=datetime.datetime
print V.strptime("21/11/06 16:30","%d/%m/%y %H:%M")
# Created by pyminifier (https://github.com/liftoff/pyminifier)

$ python test_obf.py
Traceback (most recent call last):
  File "test_min.py", line 2, in <module>
    q=datetime.strptime
AttributeError: 'module' object has no attribute 'strptime'

It also seems to have issues when there is a method (even a class method) that has the same name as a module.

# test2.py
import geojson
class ExampleClass(object):
    def geojson(self):
        return {'something': 'foo'}
p = geojson.Point((-115.81, 37.24))

#test2_obf.py
# Produced by `pyminifier -O test2.py > test2_obf.py`
import P
s=object
d=P.Point
class e(s):
 def P(self):
  return{'something':'foo'}
p=d((-115.81,37.24))
# Created by pyminifier (https://github.com/liftoff/pyminifier)

$ python test2_obf.py 
Traceback (most recent call last):
  File "test2_obf.py", line 1, in <module>
    import P
ImportError: No module named P
diggerdu commented 6 years ago

any workaround?