# $Id$ # # Copyright (C) 2013--2014 Dragon Research Labs ("DRL") # Portions copyright (C) 2009--2012 Internet Systems Consortium ("ISC") # Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN") # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notices and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND DRL, ISC, AND ARIN DISCLAIM ALL # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DRL, # ISC, OR ARIN BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS # OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ HTTP utilities, both client and server. """ import time import socket import asyncore import asynchat import urlparse import sys import random import rpki.async import rpki.sundial import rpki.x509 import rpki.exceptions import rpki.log import rpki.POW ## @var rpki_content_type # HTTP content type used for all RPKI messages. rpki_content_type = "application/x-rpki" ## @var debug_http # Verbose chatter about HTTP streams. debug_http = False ## @var want_persistent_client # Whether we want persistent HTTP client streams, when server also supports them. want_persistent_client = False ## @var want_persistent_server # Whether we want persistent HTTP server streams, when client also supports them. want_persistent_server = False ## @var default_client_timeout # Default HTTP client connection timeout. default_client_timeout = rpki.sundial.timedelta(minutes = 5) ## @var default_server_timeout # Default HTTP server connection timeouts. Given our druthers, we'd # prefer that the client close the connection, as this avoids the # problem of client starting to reuse connection just as server closes # it, so this should be longer than the client timeout. default_server_timeout = rpki.sundial.timedelta(minutes = 10) ## @var default_http_version # Preferred HTTP version. default_http_version = (1, 0) ## @var default_tcp_port # Default port for clients and servers that don't specify one. default_tcp_port = 80 ## @var enable_ipv6_servers # Whether to enable IPv6 listeners. Enabled by default, as it should # be harmless. Has no effect if kernel doesn't support IPv6. enable_ipv6_servers = True ## @var enable_ipv6_clients # Whether to consider IPv6 addresses when making connections. # Disabled by default, as IPv6 connectivity is still a bad joke in # far too much of the world. enable_ipv6_clients = False ## @var have_ipv6 # Whether the current machine claims to support IPv6. Note that just # because the kernel supports it doesn't mean that the machine has # usable IPv6 connectivity. I don't know of a simple portable way to # probe for connectivity at runtime (the old test of "can you ping # SRI-NIC.ARPA?" seems a bit dated...). Don't set this, it's set # automatically by probing using the socket() system call at runtime. try: # pylint: disable=W0702,W0104 socket.socket(socket.AF_INET6).close() socket.IPPROTO_IPV6 socket.IPV6_V6ONLY except: have_ipv6 = False else: have_ipv6 = True ## @var
# $Id$
"""Trivial wrapper around lxml.etree.RelaxNG."""
import lxml.etree
class RelaxNG(lxml.etree.RelaxNG):
"""Minor customizations of lxml.etreeRelaxNG."""
def __init__(self, filename):
"""
Initialize a RelaxNG validator from a file.
"""
lxml.etree.RelaxNG.__init__(self, lxml.etree.parse(filename))