예제 #1
0
def aiohttp_request_meta(request, post):
    yield "Method", request.method
    yield "Scheme", request.url.scheme
    yield "Domain", request.url.host
    yield "Port", force_text(request.url.port)
    yield "PathString", request.url.path
    yield "QueryString", request.url.query_string
    yield "Headers", tuple(wl.Rule(k, v) for k, v in request.headers.items())
    yield "MultipartElements", tuple(
        wl.Rule(k, to_multipart(v)) for k, v in post.items())
예제 #2
0
def django_request_meta(request):
    yield "Method", request.method
    yield "Scheme", request.is_secure() and "https" or "http"
    yield "Domain", request.get_host()
    yield "Port", request.get_port()
    yield "PathString", request.path
    yield "QueryString", request.META["QUERY_STRING"]
    yield "Headers", tuple(wl.Rule(k, v) for k, v in request.headers.items())
    yield "MultipartElements", tuple(
        iterate(
            (wl.Rule(k, to_multipart(v)) for k in request.POST.keys()
             for v in request.POST.getlist(k)),
            (wl.Rule(k, to_multipart(v)) for k in request.FILES.keys()
             for v in request.FILES.getlist(k)),
        ))
    def test_export(self):

        for value in (
                1,
                2,
                "aaaa",
                2.0,
            {
                1: 2
            },
            [1, 2, 3],
            ["hello", decimal.Decimal("1.23")],
                wl.Foo,
                wl.Foo(2, wl.Context.Internal),
        ):
            self.serialize_compare(value, export(value, target_format="wxf"))

        self.assertEqual(
            export(Association(enumerate("abc")), target_format="wxf"),
            export(
                wl.Association(*(wl.Rule(i, v) for i, v in enumerate("abc"))),
                target_format="wxf",
            ),
        )

        self.assertEqual(
            export(wlexpr("2+2"), target_format="wxf"),
            export(wl.ToExpression("2+2"), target_format="wxf"),
        )

        self.assertEqual(
            export(wl.Foo(wlexpr("2+2"), 1, 2), target_format="wxf"),
            export(wl.Foo(wl.ToExpression("2+2"), 1, 2), target_format="wxf"),
        )
예제 #4
0
def process_generate_httpresponse_expression(response):
    if isinstance(response, dict):
        if not response.get("BodyByteArray", None):
            # empty byte array is returning a an empty list, we need an empty byte array
            response["BodyByteArray"] = b""
        return response
    return {
        "BodyByteArray": export(response, target_format="wl"),
        "Headers": (wl.Rule("content-type", "text/plain;charset=utf-8"), ),
        "StatusCode": 500,
    }
예제 #5
0
파일: wolfpy.py 프로젝트: mgroth0/mlib
 def push(self, permissions=PERMISSIONS.PRIVATE):
     if self.file.isdir:
         if weval(wl.DirectoryQ(CloudObject(self.file.abspath))):
             weval(
                 wl.DeleteDirectory(CloudObject(self.file.abspath),
                                    Rule(wl.DeleteContents, True)))
         return weval(
             wl.CopyDirectory(
                 self.file.abspath,
                 CloudObject(self.file.abspath,
                             Rule(wl.Permissions, permissions))))
     else:
         if weval(wl.FileExistsQ(wl.CloudObject(self.file.abspath))):
             weval(wl.DeleteFile(wl.CloudObject(self.file.abspath)))
         return weval(
             wl.CopyFile(
                 self.file.abspath,
                 wl.CloudObject(self.file.abspath,
                                wl.Rule(wl.Permissions, permissions))))
예제 #6
0
def bar(fd):
    from mlib.wolf.wolf_figs import defaultPlotOptions
    x = fd.x
    y = fd.y
    maxY = wl.All if fd.maxY is None or fd.maxY == -np.inf else fd.maxY
    minY = wl.All if fd.minY is None or fd.maxY == np.inf else fd.minY
    maxX = wl.All if fd.maxX is None or fd.maxY == -np.inf else fd.maxX
    minX = wl.All if fd.minX is None or fd.maxY == np.inf else fd.minX

    if maxY != wl.All and minY != wl.All:
        diff = maxY - minY
        pad = diff * 100 / fd.y_pad_percent
        maxY = maxY + pad
        minY = minY - pad

    rotate = wlexpr('90 Degree') if fd.bar_sideways_labels else wlexpr(
        '0 Degree')
    err = fd.err
    rotate = '90 Degree' if fd.bar_sideways_labels else '0 Degree'
    vstring = '\n\n\n' if fd.bar_sideways_labels else ''
    labs = [wl.Text(xx) for xx in x]
    map_expr = wlexpr('Around[#1, #2] &')

    labs = str(fd.x).replace('[', '{').replace(']', '}').replace("'", '"')

    firstarg = wl.MapThread(map_expr, [y, err])
    origarg = firstarg
    if fd.delta_bar_idx is not None:
        # thing[]
        firstarg = weval(firstarg)
        firstarg = list(firstarg)
        firstarg[fd.delta_bar_idx] = wl.Callout(
            firstarg[fd.delta_bar_idx], "p=" + str(fd.delta_val), wl.Above,
            wl.Rule(wl.LabelStyle, [10, wl.Bold, wl.White]),
            wl.Rule(wl.LeaderSize, 25))

    return weval(
        wl.BarChart(
            firstarg, defaultPlotOptions(fd),
            wl.Rule(wl.ChartStyle,
                    [wl.RGBColor(color) for color in fd.item_colors]),
            wl.Rule(
                wl.LabelingFunction,
                wlexpr('(Placed[Rotate[' + labs + '[[#2[[2]]]], ' + rotate +
                       '], Below]&)')),
            wl.Rule(wl.FrameTicks,
                    [[True, wlexpr('None')], [wlexpr('None'),
                                              wlexpr('None')]]),
            wl.Rule(wl.FrameLabel, [vstring + fd.x_label, fd.y_label])))
예제 #7
0
파일: wolf_lang.py 프로젝트: mgroth0/mlib
def Rule(one, two):
    return wl.Rule(one, two)
예제 #8
0
파일: wolf_lang.py 프로젝트: mgroth0/mlib
def TicksStyle(c):
    return wl.Rule(wl.TicksStyle, c)
예제 #9
0
파일: wolf_lang.py 프로젝트: mgroth0/mlib
def Ticks(t):
    return wl.Rule(wl.Ticks, t)
예제 #10
0
파일: wolf_lang.py 프로젝트: mgroth0/mlib
def Alignment(a):
    return wl.Rule(wl.Alignment, a)