about summary refs log tree commit diff
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2016-02-08 16:57:57 +0100
committeraszlig <aszlig@redmoonstudios.org>2016-02-08 22:05:06 +0100
commit4655dc8299a6b91744a8c606dea95308388cc158 (patch)
treed53ba16feb47e7161348dee1b07174fc59abd3cc
parent53660e5d1ddda8b8c8b381f884b28a69d6374a63 (diff)
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 <aszlig@redmoonstudios.org>
-rw-r--r--humblebundle/fetch-humble-bundle/default.nix17
1 files 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