<commit_before># TODO: this file should be refactored to use a more thread-safe and
# race-condition-safe lockfile mechanism.

import os
import re
import socket
import sys
import stat
import datetime

from ...extern.six.moves.urllib.request import urlopen
from ...extern.six.moves import xmlrpc_client as xmlrpc
from ...extern import six

from ... import log

from .constants import SSL_SUPPORT

from ...utils.data import get_readable_fileobj

if SSL_SUPPORT:
    import ssl
    SSL_EXCEPTIONS = (ssl.SSLError,)
else:
    SSL_EXCEPTIONS = ()


def read_lockfile(lockfilename):
    """
    Read in the lockfile given by ``lockfilename`` into a dictionary.
    """
    # lockfilename may be a local file or a remote URL, but
    # get_readable_fileobj takes care of this.
    lockfiledict = {}
    with get_readable_fileobj(lockfilename) as f:
        for line in f:
            if not line.startswith(b"#"):
                kw, val = line.split(b"=")
                lockfiledict[kw.decode().strip()] = val.decode().strip()
    return lockfiledict
<commit_msg>Fixed read_lockfile for Python 3.x<commit_after># TODO: this file should be refactored to use a more thread-safe and
# race-condition-safe lockfile mechanism.

import os
import re
import socket
import sys
import stat
import datetime

from ...extern.six.moves.urllib.request import urlopen
from ...extern.six.moves import xmlrpc_client as xmlrpc
from ...extern import six

from ... import log

from .constants import SSL_SUPPORT

from ...utils.data import get_readable_fileobj

if SSL_SUPPORT:
    import ssl
    SSL_EXCEPTIONS = (ssl.SSLError,)
else:
    SSL_EXCEPTIONS = ()


def read_lockfile(lockfilename):
    """
    Read in the lockfile given by ``lockfilename`` into a dictionary.
    """
    # lockfilename may be a local file or a remote URL, but
    # get_readable_fileobj takes care of this.
    lockfiledict = {}
    with get_readable_fileobj(lockfilename) as f:
        for line in f:
            if not line.startswith("#"):
                kw, val = line.split("=")
                lockfiledict[kw.strip()] = val.strip()
    return lockfiledict

{'fraction_non_alphanumeric': 0.09013685700802265, 'fraction_numerical': 0.00047192071731949034, 'mean_word_length': 3.03041825095057, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '4494166', 'n_tokens_mistral': 662, 'n_tokens_neox': 630, 'n_words': 220}