<commit_before>#
# client.py - <NAME> <<EMAIL>>
#             <NAME> <<EMAIL>>
#             <NAME> <<EMAIL>>
#

import os
import tarfile
import httplib
from urlparse import urlparse
from xml.etree import cElementTree

from utils import tar_file_size
from data_format import DataFormat


# Avoid delays caused by Nagle's algorithm.
# http://www.cmlenz.net/archives/2008/03/python-httplib-performance-problems

import socket
realsocket = socket.socket
def socketwrap(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
    sockobj = realsocket(family, type, proto)
    sockobj.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
    return sockobj
socket.socket = socketwrap


# Buffer the response socket.
# http://mail.python.org/pipermail/python-bugs-list/2006-September/035156.html

#class HTTPResponse(httplib.HTTPResponse):
               
#    def __init__(self, sock, **kw):
#        httplib.HTTPResponse.__init__(self, sock, **kw)
#        self.fp = sock.makefile('rb') # Was unbuffered: sock.makefile('rb', 0)


#httplib.HTTPConnection.response_class = HTTPResponse


class SyncError(Exception):
    pass


class Client(object):
    
    program_name = "unknown-SRS-app"
    program_version = "unknown"
    capabilities = None  # TODO: list possibilies.
    
    def __init__(self, database, ui):
        self.database = database
        self.ui = ui
        self.data_format = DataFormat()
        self.id = "TODO"
        self.server_info = {}

    def sync(self, url, username, password):       
        try:
            self.url = url           
            self.ui.status_bar_message("Creating backup...")
            backup_file = self.database.backup()
            # We let the client check if files were updated outside of the
            # program. This can generate MEDIA_UPDATED log entries, so it
            # should be done first.
            self.database.check_for_updated_media_files()
            self.login(username, password)
            self.put_client_log_entries()<commit_msg>Extra buffering on the response socket.<commit_after>#
# client.py - <NAME> <<EMAIL>>
#             <NAME> <<EMAIL>>
#             <NAME> <<EMAIL>>
#

import os
import tarfile
import httplib
from urlparse import urlparse
from xml.etree import cElementTree

from utils import tar_file_size
from data_format import DataFormat


# Avoid delays caused by Nagle's algorithm.
# http://www.cmlenz.net/archives/2008/03/python-httplib-performance-problems

import socket
realsocket = socket.socket
def socketwrap(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
    sockobj = realsocket(family, type, proto)
    sockobj.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
    return sockobj
socket.socket = socketwrap

# Buffer the response socket.
# http://mail.python.org/pipermail/python-bugs-list/2006-September/035156.html

class HTTPResponse(httplib.HTTPResponse):
               
    def __init__(self, sock, **kw):
        httplib.HTTPResponse.__init__(self, sock, **kw)
        self.fp = sock.makefile('rb') # Was unbuffered: sock.makefile('rb', 0)

httplib.HTTPConnection.response_class = HTTPResponse

class SyncError(Exception):
    pass


class Client(object):
    
    program_name = "unknown-SRS-app"
    program_version = "unknown"
    capabilities = None  # TODO: list possibilies.
    
    def __init__(self, database, ui):
        self.database = database
        self.ui = ui
        self.data_format = DataFormat()
        self.id = "TODO"
        self.server_info = {}

    def sync(self, url, username, password):       
        try:
            self.url = url           
            self.ui.status_bar_message("Creating backup...")
            backup_file = self.database.backup()
            # We let the client check if files were updated outside of the
            # program. This can generate MEDIA_UPDATED log entries, so it
            # should be done first.
            self.database.check_for_updated_media_files()
            self.login(username, password)
            self.put_client_log_entries()
{'fraction_non_alphanumeric': 0.1017283950617284, 'fraction_numerical': 0.009382716049382716, 'mean_word_length': 2.7648698884758365, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '7035341', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1205, 'n_words': 296}