<commit_before>#!/usr/bin/env python
# encoding: utf-8
"""
server.py

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

import socket
import errno

from exaproxy.network.poller import errno_block
from exaproxy.util.logger import logger



class Client(object):
	eor = '\r\n\r\n'

	def __init__(self, name, sock, peer):
		self.name = name
		self.sock = sock
		self.peer = peer
		self.reader = self._read(sock)
		self.writer = self._write(sock)

		self.blockupload = None

		# start the _read coroutine
		self.reader.next()


	def _read(self, sock, read_size=64*1024):
		"""Coroutine managing data read from the client"""
		r_buffer = ''
		request = ''
		r_size = yield ''

		while True:
			try:
				while True:
					data = sock.recv(r_size or read_size)
					if not data:   # read failed - abort
						break

					if request:
						r_size = yield '', data                
						continue

					r_buffer += data

					if self.eor in r_buffer:       # we have a complete request
						request, r_buffer = r_buffer.split(self.eor, 1)

						r_size = yield request + self.eor, ''  # yield to manager.readRequest
						r_size = yield '', r_buffer            # yield to manager.startData
						r_buffer = ''
					else:
						r_size = yield '', ''                  # nothing seen yet

				# break out of the outer loop as soon as we leave the inner loop
				# through normal execution
				break

			except socket.error, e:
				if e.args[0] in errno_block:
					yield '', ''
				else:
					break

		yield None<commit_msg>Request headers can be terminated with newline/newline<commit_after>#!/usr/bin/env python
# encoding: utf-8
"""
server.py

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

import socket
import errno

from exaproxy.network.poller import errno_block
from exaproxy.util.logger import logger



class Client(object):
	eor = '\r\n\r\n'
	eorn = '\n\n'

	def __init__(self, name, sock, peer):
		self.name = name
		self.sock = sock
		self.peer = peer
		self.reader = self._read(sock)
		self.writer = self._write(sock)

		self.blockupload = None

		# start the _read coroutine
		self.reader.next()


	def _read(self, sock, read_size=64*1024):
		"""Coroutine managing data read from the client"""
		r_buffer = ''
		request = ''
		r_size = yield ''

		while True:
			try:
				while True:
					data = sock.recv(r_size or read_size)
					if not data:   # read failed - abort
						break

					if request:
						r_size = yield '', data                
						continue

					r_buffer += data

					for eor in (self.eor, self.eorn):
						if eor in r_buffer:       # we have a complete request
							request, r_buffer = r_buffer.split(eor, 1)

							r_size = yield request + eor, ''  # yield to manager.readRequest
							r_size = yield '', r_buffer        # yield to manager.startData
							r_buffer = ''
							break
					else:
						r_size = yield '', ''                  # nothing seen yet

				# break out of the outer loop as soon as we leave the inner loop
				# through normal execution
				break

			except socket.error, e:
				if e.args[0] in errno_block:
					yield '', ''
				else:
					break

		yield None
{'fraction_non_alphanumeric': 0.10212367270455965, 'fraction_numerical': 0.01311680199875078, 'mean_word_length': 2.371578947368421, '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': '7634709', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1017, 'n_words': 329}