From 4655dc8299a6b91744a8c606dea95308388cc158 Mon Sep 17 00:00:00 2001 From: aszlig Date: Mon, 8 Feb 2016 16:57:57 +0100 Subject: fetch-humble-bundle: Escape Python strings This fixes aszlig/nixgames#2 but instead of using """ for the strings, we now have a pyStr function which is taking care of escaping nasty characters :-) Signed-off-by: aszlig --- humblebundle/fetch-humble-bundle/default.nix | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/humblebundle/fetch-humble-bundle/default.nix b/humblebundle/fetch-humble-bundle/default.nix index 36601bd1..c37e2043 100644 --- a/humblebundle/fetch-humble-bundle/default.nix +++ b/humblebundle/fetch-humble-bundle/default.nix @@ -21,6 +21,8 @@ propagatedBuildInputs = with pythonPackages; [ requests2 ]; }; + pyStr = str: "'${stdenv.lib.escape ["'" "\\"] str}'"; + getDownloadURL = writeText "gethburl.py" '' import sys, humblebundle @@ -38,32 +40,33 @@ def find_download(downloads): for machine_name, dstruct in sum(downloads.values(), []): - if machine_name == '${machineName}': + if machine_name == ${pyStr machineName}: for ds in dstruct: - if ds.name == '${downloadName}': + if ds.name == ${pyStr downloadName}: return ds print >>sys.stderr, \ - 'Unable to find ${downloadName} for ${machineName}!' + ${pyStr "Unable to find ${downloadName} for ${machineName}!"} print >>sys.stderr, 'Available download types:' for ds in dstruct: print >>sys.stderr, " " + ds.name raise SystemExit(1) hb = humblebundle.HumbleApi() - hb.login('${email}', '${password}') + hb.login(${pyStr email}, ${pyStr password}) products = dict(get_products(hb)) dstruct = find_download(products) if dstruct is None: - print >>sys.stderr, 'Cannot find download for ${machineName}!' + print >>sys.stderr, ${pyStr "Cannot find download for ${machineName}!"} print >>sys.stderr, 'Available machine names:' for name, dstructs in sorted(products.items(), key=lambda x: x[0]): print >>sys.stderr, " * " + name print >>sys.stderr, " " + ', '.join(map(lambda x: x[0], dstructs)) raise SystemExit(1) - elif dstruct.md5 != '${md5}': + elif dstruct.md5 != ${pyStr md5}: print >>sys.stderr, \ - 'MD5 for ${machineName} is not ${md5} but ' + dstruct.md5 + '.' + ${pyStr "MD5 for ${machineName} is not ${md5} but "} \ + + dstruct.md5 + '.' raise SystemExit(1) else: print dstruct.url.web -- cgit 1.4.1