QQuick / Opy

Obfuscator for Python
Other
364 stars 61 forks source link

'#' in string causes python syntax error #8

Closed perplexedfingers closed 8 years ago

perplexedfingers commented 8 years ago

In opy_config.txt, I stated my module name as you suggested, and I wrote a usage function that prints out the usage when any invalid parameter given, in which I state the module name again. However, while Opy obfuscates my script, the module name is reserved and this reservation makes the string ill-formed. Python gets error running the ill-formed obfuscated script.

Is this a bug, or an intended behavior?

--Update

print("test.here #hey")

becomes

print("test.here 

and these are fine

" '' "
' "" '
""" '' """
''' "" '''
perplexedfingers commented 8 years ago

I found this situation is actually quite complicated. Could we just fix pound signs in one quotation mark pairs(' ', " ")? It could be like

" hey ' # ' "
' hey " # " '
JdeH commented 8 years ago

Hi,

Since Opy does'nt really parse your source, but rather uses regular expressions, the following syntax limitations hold:

The trick is to make # appear only at the start of a string literal. A general way to do that is splitting your string literals as follows:

print("test.here #hey")

should be written as become:

print("test.here ""#""hey")

actually printing the concatenation of three strings, namely:

"test.here ", "#" and "hey"

Or, with single quotes if you prefer them:

print('test.here ''#''hey')

(Note that there are no double quotes here, '' are two single quotes)

actually again printing the concatenation of three strings, namely:

'test.here ', '#' and 'hey'

Hope this helps.

Kind regards Jacques

perplexedfingers commented 8 years ago

It seems this is the easiest way to have jobs done. Thanks!

JdeH commented 8 years ago

Glad that it worked for you!