<commit_before># $Id$

## System modules
try:
    from cStringIO import StringIO
except ImportError:
    from StringIO import StringIO
import urllib, mimetools

## PycURL module
import pycurl


class Curl:

    def __init__(self, url, filename=None, data=None):
        self.h = []
        self.status = None
        self.server_reply = StringIO()
        self.c = pycurl.init()
        self.url = url
        self.data = data
        self.c.setopt(pycurl.URL, self.url)
        self.c.setopt(pycurl.HEADERFUNCTION, self.server_reply.write)

        if filename == None:
            self.fp = StringIO()
            self.c.setopt(pycurl.WRITEFUNCTION, self.fp.write)
        else:
            self.fp = open(filename, 'w')
            self.c.setopt(pycurl.WRITEDATA, self.fp)
        if self.data != None:
            self.c.setopt(pycurl.POST, 1)
            self.c.setopt(pycurl.POSTFIELDS, urllib.urlencode(self.data))

    def set_url(self, url):
        self.c.setopt(pycurl.URL, url)

    def add_header(self, *args):<commit_msg>use file objects instead of file names to the constructor to allow writing to things like sys.stdout or sockets.<commit_after># $Id$

## System modules
try:
    from cStringIO import StringIO
except ImportError:
    from StringIO import StringIO
import urllib, mimetools

## PycURL module
import pycurl


class Curl:

    def __init__(self, url, file=None, data=None):
        self.h = []
        self.status = None
        self.server_reply = StringIO()
        self.c = pycurl.init()
        self.url = url
        self.data = data
        self.c.setopt(pycurl.URL, self.url)
        self.c.setopt(pycurl.HEADERFUNCTION, self.server_reply.write)

        if file == None:
            self.fp = StringIO()
            self.c.setopt(pycurl.WRITEFUNCTION, self.fp.write)
        else:
            self.fp = file
            self.c.setopt(pycurl.WRITEDATA, self.fp)
        if self.data != None:
            self.c.setopt(pycurl.POST, 1)
            self.c.setopt(pycurl.POSTFIELDS, urllib.urlencode(self.data))

    def set_url(self, url):
        self.c.setopt(pycurl.URL, url)

    def add_header(self, *args):
{'fraction_non_alphanumeric': 0.11136999068033551, 'fraction_numerical': 0.0009319664492078285, 'mean_word_length': 2.262917933130699, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2702825', 'n_tokens_mistral': 734, 'n_tokens_neox': 700, 'n_words': 160}