Skip to content

Instantly share code, notes, and snippets.

Request handling models

Abstraction layer

  • What is wsgi

PEP3333, a web server gateway interface, specifies how web server should communicate with web applications and how web applications can be chained together to process one request

  • Benefit?

MySQL demystified

How does MySQL execute queries?

  • SQL => Parse Tree => Execution plan
  • The execution plan is a data structure, not byte-code
  • The executor makes storage engine calls

Execution plan

"Deep left tree" -- always

Explain output columns

from pretenders.server.server import run
import multiprocessing
ml = multiprocessing.Process(name='ml', target=run)
ml.start()
def _init():
from pretenders.client.http import HTTPMock
verisign,PayPal Payflow Pro,Lucre
paypaldirect,PayPal direct,lucre
paypalexpress,PayPal Express,offsite
paypaladaptive,PayPal,asynchronous
paypaladaptiveb2b,PayPal,asynchronous
class AppendOnlyModelMeta(DeclarativeMeta):
@staticmethod
def _get_append_only_attributes(cls):
'''A helper method to get a list of append-only attributes
declared on the class.'''
[...]
def __init__(cls, classname, bases, dict_):
if hasattr(cls, '__history_class__'):
cls._history_fields = cls._get_append_only_attributes(cls)
class Transaction:
class History:
id
transaction_id
status
_history = relation(
History,
and_(History.transaction_id == Transaction.transaction_id))
class _AppendOnlyAttribute(object):
def __init__(self, name):
self.name = name
def __get__(self, instance, owner):
if instance:
return getattr(instance._history[0], self.name)
else:
return getattr(owner.__history_class__, self.name)
class AgeAttr(object):
def __get__(self, instance, owner):
return instance.value
def __set__(self, instance, value):
if value < 0:
raise ValueError('Age cannot be negative')
instance.value = value
class User(object):
class Transaction(AppendOnlyModel):
__tablename__ = 'transaction'
__history_class__ = make_history_class(
'transaction',
status=HistoryStateColumn(
sa.Enum(*constants.TRANSACTION_STATUSES),
nullable=False)
)
source_id = ...
transaction = create_transaction()
transaction.status = 'unverified'
transaction = get_transaction()
print(transaction.status)