Skip to content

Instantly share code, notes, and snippets.

View PedroArSp's full-sized avatar
🎯
Focusing

Pedro Riva PedroArSp

🎯
Focusing
View GitHub Profile
@polozhevets
polozhevets / clone_model.py
Created July 10, 2019 12:51
Clone sqlalchemy model
def clone_model(model):
"""Clone an arbitrary sqlalchemy model object without its primary key values."""
# Ensure the model’s data is loaded before copying.
model.id
table = model.__table__
non_pk_columns = [k for k in table.columns.keys() if k not in table.primary_key]
data = {c: getattr(model, c) for c in non_pk_columns}
data.pop('id')
return data
@bencord0
bencord0 / listeningsockethandler.py
Created December 12, 2012 23:36
ListeningSocketHandler ====================== A python logging handler. logging.handlers.SocketHandler is a TCP client that sends log records to a TCP server. This class is the opposite. When a TCP client connects (e.g. telnet or netcat), new log records are sent through the tcp connection.
#!/usr/bin/env python
"""
ListeningSocketHandler
======================
A python logging handler.
logging.handlers.SocketHandler is a TCP Socket client that sends log
records to a tcp server.
This class is the opposite.