Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
From FastAPI Gitter: | |
dmontagu @dmontagu 00:14 | |
@wshayes @intrepidOlivia here is a fully self-contained working implementation of a wrapped response | |
https://gist.github.com/dmontagu/9abbeb86fd53556e2c3d9bf8908f81bb | |
you can set context data and errors on the starlette Request and they get added to the response at the end | |
(@intrepidOlivia if you save the contents of that gist to main.py it should be possible to run via uvicorn main:app --reload) | |
if the endpoint failed in an expected way and you want to return a StandardResponse with no data field, you provide the type of StandardResponse you want to return instead of an instance |
import asyncio | |
import json | |
import logging | |
from uuid import UUID | |
import aio_pika | |
import websockets.exceptions as ws_exc | |
from fastapi import APIRouter, Path | |
from starlette import status | |
from starlette.websockets import WebSocket |
import json | |
from parsimonious import Grammar, NodeVisitor | |
class JSONVisitor(NodeVisitor): | |
""" | |
A simple JSON serializer for Parsimonious parse trees. | |
""" | |
def generic_visit(self, node, children): |
Select | |
PREFIX belv: <http://www.openbel.org/vocabulary/> | |
PREFIX skos: <http://www.w3.org/2004/02/skos/core#> | |
PREFIX xsd: <http://www.w3.org/2001/XMLSchema/> | |
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> | |
PREFIX dc: <http://purl.org/dc/elements/1.1/> | |
PREFIX fn: <http://www.w3.org/2005/xpath-functions#> | |
# Bind ?namespaceConceptScheme to the URI of the namespace resource whose concepts you would like equivalenced via concept type and case-insensitive string match. |
// ES2015 classes | |
class MyClass { | |
// Would return: my-class | |
toFileCase() { | |
var className = this.constructor.name.toString(); | |
var normalised = className.replace(/((?!^)[A-Z])/g, '-$1').toLowerCase(); | |
return normalised; | |
} | |
} |
npm install selectize - save | |
npm install jquery -save | |
add this to the aurelia.json file in the dependencies section of the vendor bundle | |
"jquery", | |
{ | |
"name": "selectize", | |
"path": "../node_modules/selectize/dist", |
// Promise.all is good for executing many promises at once | |
Promise.all([ | |
promise1, | |
promise2 | |
]); | |
// Promise.resolve is good for wrapping synchronous code | |
Promise.resolve().then(function () { | |
if (somethingIsNotRight()) { | |
throw new Error("I will be rejected asynchronously!"); |
import requests | |
class HoverException(Exception): | |
pass | |
class HoverAPI(object): | |
def __init__(self, username, password): | |
params = {"username": username, "password": password} | |
r = requests.post("https://www.hover.com/api/login", params=params) |
__author__ = "Yasunobu OKAMURA" | |
__copyright__ = "Copyright (c) 2012 Y.Okamura" | |
__license__ = "GPL v3+" | |
import xml.parsers.expat | |
import networkx as nx | |
class XGMMLParserHelper(object): | |
""" | |
""" |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!