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
# coding: utf-8 | |
"""PPSP: Pure Python Server Pages | |
(c) 2016 Yasushi Masuda. | |
""" | |
from collections import OrderedDict | |
from re import compile, M, S | |
# State symbols |
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
# coding: utf-8 | |
"""memoserv | |
使い方 | |
起動すると、ローカルホストのポート8000で待ち受けます。 | |
POST すると、サーバに値が保存されます。 | |
GET すると、保存されていた値を返し、消去します。 | |
""" |
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
# coding: utf-8 | |
import sys | |
from inspect import getinnerframes | |
from functools import wraps | |
from pprint import pprint | |
def inspect_on_failure(msg_fmt): | |
def decorator(func): | |
@wraps(func) |
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
# coding: utf-8 | |
from reportlab.lib.pagesizes import A4 | |
from reportlab.platypus import BaseDocTemplate, Frame, PageTemplate | |
from reportlab.lib.units import mm | |
from reportlab.platypus.flowables import PageBreak, Spacer | |
from reportlab.platypus.paragraph import Paragraph | |
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle | |
from reportlab.lib import colors |
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
# coding: utf-8 | |
import re | |
# いろいろなパターンを作るためのフォーマット | |
text_fmt = u""" | |
... | |
お客様の%(id_label)s/%(pw_label)sをご入力ください。 | |
... | |
%(id_label_prefix)s%(id_label)s%(label_suffix)s%(sep)s%(value_prefix)s%(id)s | |
%(pw_label_prefix)s%(pw_label)s%(label_suffix)s%(sep)s%(value_prefix)s%(pw)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
# common logic for *session_request. | |
sub _session_request { | |
my ($res, $path) = @_; | |
my $req = Catalyst::Utils::request($path); | |
$req->header('Cookie'=>$res->headers->{'set-cookie'}); | |
return $req; | |
} | |
# build request with session, using given response. | |
sub session_request { |
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
# do HTTP digest login | |
sub digest_login_request { | |
my ($schema, $username, $pw_override) = @_; | |
my $res = request('/login'); | |
my %digest_hdr = map { | |
my @key_val = split /=/, $_, 2; # / | |
$key_val[0] = lc $key_val[0]; | |
$key_val[1] =~ s{"}{}g; # remove the quotes | |
@key_val; | |
} split /,\s?/, substr( $res->header('WWW-Authenticate'), 7 ); #/; |
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
# coding: utf-8 | |
""" | |
To parse XML with namespaces using ElementTree, keeping namespace prefix, you will need register_namespace. | |
>>> from xml.etree.ElementTree import register_namespace, fromstring, tostring | |
>>> base_ns = { | |
... 'http://example.com/article': 'article', | |
... 'http://example.com/report': 'report', | |
... 'http://example.com/book': 'book', |
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
# coding: utf-8 | |
"""とこちゃんはどこ | |
""" | |
from random import choice, randrange | |
import random, sys | |
s = ["と", "こ", "ち", "ゃ", "ん"] | |
def tokochan(width, height): |