<commit_before># encoding: utf-8
"""
server.py

Created by <NAME>  on 2011-11-30.
Copyright (c) 2011 Exa Networks. All rights reserved.
"""

from exaproxy.util.log import Logger
from .worker import Client

from exaproxy.http.proxy import ProxyProtocol

class ClientManager (object):
	unproxy = ProxyProtocol().parseRequest

	def __init__(self, poller, configuration):
		self.total_sent = 0L
		self.norequest = {}
		self.bysock = {}
		self.byname = {}
		self.buffered = []
		self._nextid = 0
		self.poller = poller
		self.log = Logger('client', configuration.log.client)
		self.proxied = configuration.http.proxied

	def __contains__(self, item):
		return item in self.byname

	def getnextid(self):
		self._nextid += 1
		return str(self._nextid)

	def newConnection(self, sock, peer, source):
		name = self.getnextid()
		client = Client(name, sock, peer, self.log)

		self.norequest[sock] = client, source
		self.byname[name] = client

		# watch for request data becoming available to read
		self.poller.addReadSocket('opening_client', client.sock)

		self.log.info('new id %s (socket %s) in clients : %s' % (name, sock, sock in self.bysock))
		return peer

	def readRequest(self, sock):
		"""Read only the initial HTTP headers sent by the client"""

		client, source = self.norequest.get(sock, (None, None))
		if client:
			name, peer, request, content = client.readData()
			if request:
				# headers can be read only once
				self.norequest.pop(sock, (None, None))

				# we don't care about new requests from the client
				self.poller.removeReadSocket('opening_client', client.sock)

			elif request is None:
				self.cleanup(sock, client.name)
		else:
			self.log.error('trying to read headers from a client that does not exist %s' % sock)<commit_msg>Reword comments<commit_after># encoding: utf-8
"""
server.py

Created by <NAME>  on 2011-11-30.
Copyright (c) 2011 Exa Networks. All rights reserved.
"""

from exaproxy.util.log import Logger
from .worker import Client

from exaproxy.http.proxy import ProxyProtocol

class ClientManager (object):
	unproxy = ProxyProtocol().parseRequest

	def __init__(self, poller, configuration):
		self.total_sent = 0L
		self.norequest = {}
		self.bysock = {}
		self.byname = {}
		self.buffered = []
		self._nextid = 0
		self.poller = poller
		self.log = Logger('client', configuration.log.client)
		self.proxied = configuration.http.proxied

	def __contains__(self, item):
		return item in self.byname

	def getnextid(self):
		self._nextid += 1
		return str(self._nextid)

	def newConnection(self, sock, peer, source):
		name = self.getnextid()
		client = Client(name, sock, peer, self.log)

		self.norequest[sock] = client, source
		self.byname[name] = client

		# watch for the opening request
		self.poller.addReadSocket('opening_client', client.sock)

		self.log.info('new id %s (socket %s) in clients : %s' % (name, sock, sock in self.bysock))
		return peer

	def readRequest(self, sock):
		"""Read only the initial HTTP headers sent by the client"""

		client, source = self.norequest.get(sock, (None, None))
		if client:
			name, peer, request, content = client.readData()
			if request:
				# headers can be read only once
				self.norequest.pop(sock, (None, None))

				# we have now read the client's opening request
				self.poller.removeReadSocket('opening_client', client.sock)

			elif request is None:
				self.cleanup(sock, client.name)
		else:
			self.log.error('trying to read headers from a client that does not exist %s' % sock)
{'fraction_non_alphanumeric': 0.1168719564594672, 'fraction_numerical': 0.00916642795760527, 'mean_word_length': 3.9183098591549297, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2542021', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1125, 'n_words': 346}