This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from types import FunctionType | |
from typing import * | |
import textwrap | |
import dis # temporary debugging | |
# getvalue, raw, conv, formatspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Don't name this file html.py | |
from __future__ import annotations | |
from functools import cache | |
from types import CodeType | |
from typing import * | |
from html.parser import HTMLParser | |
from viewdom import VDOMNode, render |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Don't name this file html.py | |
from __future__ import annotations | |
from functools import cache | |
from types import CodeType | |
from typing import * | |
from html.parser import HTMLParser | |
from idom.core.vdom import vdom, VdomDict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fltag - lazy version of f-string eval | |
from __future__ import annotations | |
from dataclasses import dataclass | |
from functools import cached_property | |
from typing import * | |
Thunk = tuple[ | |
Callable[[], Any], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Extracted from @gvanrossum's gist https://gist.github.com/gvanrossum/a465d31d9402bae2c79e89b2f344c10c | |
# Demonstrates tag-string functionality, as tracked in https://jimbaker/tagstr | |
# Requires an implementating branch, as in https://github.com/jimbaker/tagstr/issues/1 | |
# Sample usage: | |
# from htmltag import html | |
# | |
# >>> user = "Bobby<table>s</table>" | |
# >>> print(html"<div>Hello {user}</div>") | |
# <div>Hello Bobby<table>s</table></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
import sys | |
from sqlalchemy import create_engine # change to oslo_db | |
from sqlalchemy.orm import sessionmaker | |
from sqlalchemy.sql.expression import tuple_ | |
from craton.db.sqlalchemy import models | |
engine = create_engine(sys.argv[1] if len(sys.argv) > 1 else 'mysql+pymysql://craton:craton@localhost/craton') #, echo=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example usage. Note that we simply pass through httpie conventions, | |
# such as nested JSON with := | |
# (https://github.com/jkbrzt/httpie#non-string-json-fields) | |
# | |
# $ craton-post v1/regions name=HKG | |
# $ craton-get v1/hosts | |
# $ craton-put v1/hosts/3 device_type=container | |
# $ craton-put v1/hosts/3/variables foo=47 bar:='["a", "b", "c"]' | |
# $ craton-delete v1/hosts/4 | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker rm -f craton-api || true | |
docker build --pull -t craton-api:latest . | |
docker run -t --name craton-api -p 127.0.0.1:8080:8080 -d craton-api:latest | |
# wait until API server is available by probing it | |
until curl http://127.0.0.1:8080/v1/regions -H "Content-Type: application/json" -H "X-Auth-Token: demo" -H "X-Auth-User: demo" -H "X-Auth-Project: b9f10eca66ac4c279c139d01e65f96b4" | |
do | |
echo "Waiting for API server"; sleep 1 | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from oslo_config import cfg | |
from oslo_policy import policy as common_policy | |
CONF = cfg.CONF # should just be an empty config file | |
ENFORCER = common_policy.Enforcer(CONF) | |
rules = { | |
"fleet:audit": "role:admin or (principal:%(principal)s and role_:%(role_)s and resource:%(resource)s)" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from sqlalchemy import create_engine # change to oslo_db | |
from sqlalchemy.orm import sessionmaker | |
from craton.db.sqlalchemy import models | |
engine = create_engine(sys.argv[1] if len(sys.argv) > 1 else 'mysql+pymysql://craton:craton@localhost/craton', echo=True) | |
Session = sessionmaker(bind=engine) | |
session = Session() |
NewerOlder