Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import original names get obfuscated so they cannot get imported #120

Open
David-Lor opened this issue Jul 11, 2019 · 0 comments
Open

Import original names get obfuscated so they cannot get imported #120

David-Lor opened this issue Jul 11, 2019 · 0 comments

Comments

@David-Lor
Copy link

David-Lor commented Jul 11, 2019

Trying pyminifier (great project btw) on this project of mine (just to test this tool): https://github.com/David-Lor/MQTT2MongoDB

The project have 3 files: __main__.py, mqtt.py, mongo.py. On the main file, the other two files get imported. But pyminifier obfuscates their names on the import statements at the main, like this:

# __main__.py
from w import Mongo  # <<< Here
q=KeyboardInterrupt
from O import MQTT  # <<< Here
from signal import pause

w = Mongo()
O = MQTT(w)

w.connect()
O.run()

try:
    L()
except q:
    pass

O.stop()
w.disconnect()
# Created by pyminifier (https://github.com/liftoff/pyminifier)

These two lines should keep their original names, so they can be imported (currently with this obfuscation they can't). Command used to obfuscate is pyminifier --nominify -O __main__.py. The other two files won't get the import statements obfuscated, and mqtt.py even imports from mongo.py without obfuscation on that line, as it should be:

# mqtt.py
import paho.mqtt.client as mqtt
q=isinstance
B=str
E=object
o=staticmethod
W=print
import os
h=os.getenv

from mongo import Mongo  # <<< HERE, importing from mongo.py


j = "127.0.0.1"
F = 1883
f = 60
S = 2
c = ("#",)

j = h("MQTT_BROKER", j)
F = h("MQTT_PORT", F)
f = h("MQTT_KEEPALIVE", f)
S = h("MQTT_QOS", S)
c = h("MQTT_TOPICS", c)
if q(c, B):
    c = [e.strip() for e in c.split(",")]


class C(E):
    def __init__(t, mongo: R):
        t.mongo: R = mongo
        t.mqtt_client = mqtt.Client()
        t.mqtt_client.on_connect = t.U
        t.mqtt_client.on_message = t.k

    # noinspection PyUnusedLocal
    @o
    def U(v: mqtt.Client, userdata, flags, rc):
        W("Connected MQTT")
        for m in c:
            v.subscribe(m, S)

    # noinspection PyUnusedLocal
    def k(t, v: mqtt.Client, userdata, msg: mqtt.MQTTMessage):
        W("Rx MQTT")
        t.mongo.save(msg)

    def X(t):
        W("Running MQTT")
        t.mqtt_client.connect(j, F, f)
        t.mqtt_client.loop_start()

    def l(t):
        W("Stopping MQTT")
        t.mqtt_client.loop_stop()
        t.mqtt_client.disconnect()
# Created by pyminifier (https://github.com/liftoff/pyminifier)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant