From 6addaadf417deab853d4a8f79e6dda0ab0dd68bf Mon Sep 17 00:00:00 2001 From: Iliana Weller Date: Mon, 3 Jul 2017 19:48:42 -0500 Subject: [PATCH 1/2] stallmanW --- kappa123/server/main/views.py | 13 ++++++++++++- requirements.txt | 5 +++-- zappa_settings.json | 9 ++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/kappa123/server/main/views.py b/kappa123/server/main/views.py index d92868e..e5a6156 100644 --- a/kappa123/server/main/views.py +++ b/kappa123/server/main/views.py @@ -5,7 +5,8 @@ #### imports #### ################# -from flask import render_template, Blueprint +import botocore.session +from flask import render_template, Blueprint, request, redirect #from aaaaaaa import pack_ints, unpack_ints from kappa123.server.runs import inject_run_class, fetch_or_cache_runs def pack_ints(s): @@ -48,3 +49,13 @@ def returning_user(preferences): "main/home.html", runs=runs ) + +@main_blueprint.route("/code") +def agplv3_compliance(): + context = request.environ.get('lambda.context') + session = botocore.session.get_session() + # region name is detected from lambda environment + client = session.create_client('lambda') + code = client.get_function(FunctionName=context.function_name, + Qualifier=context.function_version) + return redirect(code['Code']['Location'], code=303) diff --git a/requirements.txt b/requirements.txt index d8dd15e..3517185 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,10 @@ +# zappa needs to come first because it locks to deps :( +zappa + coverage==4.3.4 Flask==0.12 Flask-Bootstrap==3.3.7.1 -Werkzeug==0.12 simplejson requests arrow -zappa diff --git a/zappa_settings.json b/zappa_settings.json index 27aa9b0..4dd837f 100644 --- a/zappa_settings.json +++ b/zappa_settings.json @@ -3,6 +3,13 @@ "app_function": "kappa123.server.__init__.app", "aws_region": "us-west-2", "profile_name": "gdqdotmoe", - "s3_bucket": "zappa-n2am4xeny" + "s3_bucket": "zappa-n2am4xeny", + "extra_permissions": [ + { + "Effect": "Allow", + "Action": "lambda:GetFunction", + "Resource": "*" + } + ] } } From 83e743ca6592397babfc242288ee1174926c6062 Mon Sep 17 00:00:00 2001 From: Iliana Weller Date: Mon, 3 Jul 2017 20:31:27 -0500 Subject: [PATCH 2/2] Add intpack code --- kappa123/server/intpack.py | 92 +++++++++++++++++++++++++++++++++++ kappa123/server/main/views.py | 6 +-- 2 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 kappa123/server/intpack.py diff --git a/kappa123/server/intpack.py b/kappa123/server/intpack.py new file mode 100644 index 0000000..c36b3e0 --- /dev/null +++ b/kappa123/server/intpack.py @@ -0,0 +1,92 @@ +import base64 + + +def pad_count(n, b): + if n % b == 0: + return 0 + else: + return b - (n % b) + + +def pack_ints(l): + """ + Pack a set of ints into a URL-safe string that can be used in a URL path + component. + """ + + def do_pack(s, size): + bits = [] + for i in s: + b = '{:b}'.format(i) + b = '0' * pad_count(len(b), size - 1) + b + for j in range(0, len(b), size - 1): + bits.append(str(int(j == 0))) # lol + bits.extend(b[j:j+(size-1)]) + return bits + + diffs = [] + last = 0 + for i in sorted(set(l)): + diffs.append(i - last) + last = i + + best, size = do_pack(diffs, 8), 8 + for i in range(3, 8): + attempt = do_pack(diffs, i) + if len(attempt) < len(best): + best, size = attempt, i + + # Padding works by adding 0b1, then padding the rest of the byte with 0b0. + # In "UTF-N" (UTF-5 but with any surrogate length) the first surrogate in + # the padding must refer to the value 0, because 0b10... cannot have any + # following 0b0... surrogates, and a list of differences of an ordered set + # cannot contain 0, so it can be safely used as a "stop processing" marker. + pad_size = pad_count(3 + len(best), 8) + if pad_size == 0: + padding = '' + else: + padding = list('1' + '0' * (pad_size - 1)) + bits = list('{:03b}'.format(size - 1)) + best + padding + bytes = bytearray(int(''.join(bits[i:i+8]), 2) + for i in range(0, len(bits), 8)) + return base64.b64encode(bytes) + + +def unpack_ints(s): + """ + Unpack a set of ints generated by pack_ints. + """ + + bytes = base64.b64decode(s) + if len(bytes) == 0: + return [] + bits = ''.join(item for sublist in ('{:08b}'.format(b) for b in bytes) + for item in sublist) + size, bits = int(bits[:3], 2) + 1, bits[3:] + diffs = [] + for i in range(0, len(bits), size): + surr = bits[i:i+size] + if surr[0] == '1': + if len(surr) == 1 or int(surr[1:], 2) == 0: # stop marker + break + diffs.append(int(surr[1:], 2)) + else: + diffs[len(diffs)-1] <<= (size - 1) + diffs[len(diffs)-1] += int(surr[1:], 2) + + l = [] + last = 0 + for i in diffs: + last += i + l.append(last) + return l + + +if __name__ == '__main__': + with open('/home/ilianaw/rrix.txt') as f: + s = sorted(set(int(x) for x in f.readlines())) + print(s) + packed = pack_ints(s).decode('ascii') + print(packed) + unpacked = unpack_ints(packed) + print(unpacked) diff --git a/kappa123/server/main/views.py b/kappa123/server/main/views.py index e5a6156..1683214 100644 --- a/kappa123/server/main/views.py +++ b/kappa123/server/main/views.py @@ -7,13 +7,9 @@ import botocore.session from flask import render_template, Blueprint, request, redirect -#from aaaaaaa import pack_ints, unpack_ints +from kappa123.server.intpack import pack_ints, unpack_ints from kappa123.server.runs import inject_run_class, fetch_or_cache_runs -def pack_ints(s): - return "butts" -def unpack_ints(s): - return set() ################ #### config ####