Created
September 9, 2019 12:31
-
-
Save FRex/51f73862efd916221a5df6b6baca9db1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get = (sum and __import__ or require)('requests').get | |
url = "http://translate.googleapis.com/translate_a/single" | |
params = {} | |
params['client'] = 'gtx' | |
params['sl'] = 'en' | |
params['tl'] = 'de' | |
params['dt'] = 't' | |
params['q'] = 'hello!' | |
params['params'] = params | |
r = get(url, params) | |
print(r.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tricks/kludges used:
get{url, params=params}
that I proposed in JakobGreen/lua-requests/issues/14 and that later got added since it'd fail as Python.params['params'] = params
because in Lua requests without using{}
the second argument is a table of all params (GET params, POST data, etc.), not table of GET params themselves.?:
tertiary operator-like behavior usingand
andor
which works in both, to pick right module importing function since only in Pythonsum
is a global function (truthy), in Lua it doesn't exist so it's nil - falsy, but okay and not an exception or error to access.__import__
function instead of theimport
statement.require 'requests'
since in Python parens on function calls are mandatory unlike Lua where they can be skipped for single arg call with new table or literal string.params.q
instead ofparams['q']
since it doesn't work in Python (it's attribute access, not shortcut for access by string literal key).local
would make it fail as Python.