<commit_before># @author <NAME>
#
# Copyright (c) 2005-2006, <NAME>
# Copyright (c) 2007, Linden Research, Inc.
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import os
import select
import socket
import errno

def g_log(*args):
    import sys
    from eventlet.support import greenlets as greenlet
    g_id = id(greenlet.getcurrent())
    if g_id is None:
        if greenlet.getcurrent().parent is None:
            ident = 'greenlet-main'
        else:
            g_id = id(greenlet.getcurrent())
            if g_id < 0:
                g_id += 1 + ((sys.maxint + 1) << 1)
            ident = '%08X' % (g_id,)
    else:
        ident = 'greenlet-%d' % (g_id,)
    print >>sys.stderr, '[%s] %s' % (ident, ' '.join(map(str, args)))


__original_socket__ = socket.socket
__original_gethostbyname__ = socket.gethostbyname
__original_getaddrinfo__ = socket.getaddrinfo
__original_fromfd__ = socket.fromfd

def tcp_socket():
    s = __original_socket__(socket.AF_INET, socket.SOCK_STREAM)
    return s


try:
    __original_ssl__ = socket.ssl
except AttributeError:
    __original_ssl__ = None


def wrap_ssl(sock, certificate=None, private_key=None):
    from OpenSSL import SSL
    from eventlet import greenio
    context = SSL.Context(SSL.SSLv23_METHOD)
    if certificate is not None:
        context.use_certificate_file(certificate)
    if private_key is not None:
        context.use_privatekey_file(private_key)
    context.set_verify(SSL.VERIFY_NONE, lambda *x: True)

    ## TODO only do this on client sockets? how?
    connection = SSL.Connection(context, sock)
    connection.set_connect_state()
    return greenio.GreenSSL(connection)


def wrap_ssl_obj(sock, certificate=None, private_key=None):
    """ For 100% compatibility with the socket module, this wraps and handshakes an 
    open connection, returning a SSLObject."""
    from eventlet import greenio
    wrapped = wrap_ssl(sock, certificate, private_key)
    return greenio.GreenSSLObject(wrapped)

socket_already_wrapped = False
def wrap_socket_with_coroutine_socket(use_thread_pool=True):
    global socket_already_wrapped
    if socket_already_wrapped:
        return

    def new_socket(*args, **kw):
        from eventlet import greenio
        return greenio.GreenSocket(__original_socket__(*args, **kw))
    socket.socket = new_socket

    # for 100% compatibility, return a GreenSSLObject
    socket.ssl = wrap_ssl_obj

    if use_thread_pool:
        from eventlet import tpool
        def new_gethostbyname(*args, **kw):
            return tpool.execute(
                __original_gethostbyname__, *args, **kw)
        socket.gethostbyname = new_gethostbyname

        def new_getaddrinfo(*args, **kw):
            return tpool.execute(
                __original_getaddrinfo__, *args, **kw)
        socket.getaddrinfo = new_getaddrinfo

    def new_fromfd(*args, **kw):
        from eventlet import greenio
        return greenio.GreenSocket(__original_fromfd__(*args, **kw))
    socket.fromfd = new_fromfd
<commit_msg>Added except block around fromfd so that importing util works on windows.<commit_after># @author <NAME>
#
# Copyright (c) 2005-2006, <NAME>
# Copyright (c) 2007, Linden Research, Inc.
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import os
import select
import socket
import errno

def g_log(*args):
    import sys
    from eventlet.support import greenlets as greenlet
    g_id = id(greenlet.getcurrent())
    if g_id is None:
        if greenlet.getcurrent().parent is None:
            ident = 'greenlet-main'
        else:
            g_id = id(greenlet.getcurrent())
            if g_id < 0:
                g_id += 1 + ((sys.maxint + 1) << 1)
            ident = '%08X' % (g_id,)
    else:
        ident = 'greenlet-%d' % (g_id,)
    print >>sys.stderr, '[%s] %s' % (ident, ' '.join(map(str, args)))


__original_socket__ = socket.socket
__original_gethostbyname__ = socket.gethostbyname
__original_getaddrinfo__ = socket.getaddrinfo
try:
    __original_fromfd__ = socket.fromfd
except AttributeError:
    # Windows
    __original_fromfd__ = None

def tcp_socket():
    s = __original_socket__(socket.AF_INET, socket.SOCK_STREAM)
    return s


try:
    __original_ssl__ = socket.ssl
except AttributeError:
    __original_ssl__ = None


def wrap_ssl(sock, certificate=None, private_key=None):
    from OpenSSL import SSL
    from eventlet import greenio
    context = SSL.Context(SSL.SSLv23_METHOD)
    if certificate is not None:
        context.use_certificate_file(certificate)
    if private_key is not None:
        context.use_privatekey_file(private_key)
    context.set_verify(SSL.VERIFY_NONE, lambda *x: True)

    ## TODO only do this on client sockets? how?
    connection = SSL.Connection(context, sock)
    connection.set_connect_state()
    return greenio.GreenSSL(connection)


def wrap_ssl_obj(sock, certificate=None, private_key=None):
    """ For 100% compatibility with the socket module, this wraps and handshakes an 
    open connection, returning a SSLObject."""
    from eventlet import greenio
    wrapped = wrap_ssl(sock, certificate, private_key)
    return greenio.GreenSSLObject(wrapped)

socket_already_wrapped = False
def wrap_socket_with_coroutine_socket(use_thread_pool=True):
    global socket_already_wrapped
    if socket_already_wrapped:
        return

    def new_socket(*args, **kw):
        from eventlet import greenio
        return greenio.GreenSocket(__original_socket__(*args, **kw))
    socket.socket = new_socket

    # for 100% compatibility, return a GreenSSLObject
    socket.ssl = wrap_ssl_obj

    if use_thread_pool:
        from eventlet import tpool
        def new_gethostbyname(*args, **kw):
            return tpool.execute(
                __original_gethostbyname__, *args, **kw)
        socket.gethostbyname = new_gethostbyname

        def new_getaddrinfo(*args, **kw):
            return tpool.execute(
                __original_getaddrinfo__, *args, **kw)
        socket.getaddrinfo = new_getaddrinfo

    if __original_fromfd__ is not None:
        def new_fromfd(*args, **kw):
            from eventlet import greenio
            return greenio.GreenSocket(__original_fromfd__(*args, **kw))
        socket.fromfd = new_fromfd

{'fraction_non_alphanumeric': 0.07927051671732523, 'fraction_numerical': 0.006322188449848025, 'mean_word_length': 3.5, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '2174635', 'n_tokens_mistral': 2448, 'n_tokens_neox': 2350, 'n_words': 810}