char buf[1024] strcpy(buf, user_data)
buf = user_data[:1024] if len(user_data) > 1024: security_hole(user_data[1024:])
(c) Twisted Quotes
I'll share some bits of IT knowledge here: CScience, WEB, Networking, Python, C++, Unix, Linux, Ubuntu, etc.
from logging.handlers import SysLogHandler, SYSLOG_UDP_PORT
from logging import Handler
import socket
class UdpSysLogHandler(SysLogHandler):
def createLock(self): pass
def acquire(self): pass
def release(self): pass
def __init__(self, address=('127.0.0.1', SYSLOG_UDP_PORT), facility=SysLogHandler.LOG_USER):
Handler.__init__(self)
assert type(address) == tuple
self.address = address
self.facility = facility
self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.formatter = None
def emit(self, record):
msg = self.format(record)
msg = self.log_format_string % (
self.encodePriority(self.facility,
self.mapPriority(record.levelname)),
msg)
try:
self.socket.sendto(msg, self.address)
except (KeyboardInterrupt, SystemExit):
raise
except:
self.handleError(record)
def close(self):
Handler.close(self)
self.socket.close()
def createLock(self): pass
def acquire(self): pass
def release(self): pass
location @s3 {
internal;
proxy_pass http://your-bucket-name.s3.amazonaws.com;
proxy_store on;
proxy_store_access user:rw group:rw all:r;
proxy_temp_path /var/static_data/tmp;
root /var/static_data;
}
location ~* \.(jpg|jpeg|gif|png|ico|css|bmp|js|swf|mp3)$ {
access_log off;
error_log /var/log/nginx/static_cache_miss.log;
expires max;
root /var/static_data;
error_page 404 = @s3;
}
logging/__init__.py
class Handler(Filterer):
.................
def acquire(self):
"""
Acquire the I/O thread lock.
"""
if self.lock:
self.lock.acquire()
..................
def handle(self, record):
"""
Conditionally emit the specified logging record.
Emission depends on filters which may have been added to the handler.
Wrap the actual emission of the record with acquisition/release of
the I/O thread lock. Returns whether the filter passed the record for
emission.
"""
rv = self.filter(record)
if rv:
self.acquire()
try:
self.emit(record)
finally:
self.release()
return rv
................
from logging import Formatter
class Utf8LogFormatter(Formatter):
def format(self, record):
return Formatter.format(self, record).encode('utf8')