<commit_before>#!/usr/bin/env python
"""
================================================================================
:mod:`uid` -- Generate unique identifier id
================================================================================

.. module:: uid
   :synopsis: Generate unique identifier id

.. inheritance-diagram:: pyhmsa.uid

"""

# Script information for the file.
__author__ = "<NAME>"
__email__ = "<EMAIL>"
__version__ = "0.1"
__copyright__ = "Copyright (c) 2013 <NAME>"
__license__ = "GPL v3"

# Standard library modules.
import hashlib
import time
import uuid
import getpass
import socket

try:
    import winreg
except ImportError: # pragma: no cover
    try:
        import _winreg as winreg
    except ImportError:
        winreg = None

# Third party modules.

# Local modules.

# Globals and constants variables.

_REG_KEY = 'SOFTWARE\\HmsaUID'

def generate_uid():
    """
    Generates a unique identifier id.
    The method to generate the id was taken from the C implementation of the 
    HMSA lib.
    """
    sha1 = hashlib.sha1()

    # Current date/time
    sha1.update(str(time.time()).encode('ascii'))
    
    # Tick count
    # Note: GetTickCount() not available in Python
    sha1.update(str(time.clock()).encode('ascii'))
    
    # Counter from registry (incremented here)
    # Only on Windows
    if winreg: # pragma: no cover
        key = winreg.CreateKeyEx(winreg.HKEY_CURRENT_USER, _REG_KEY,
                                 0, winreg.KEY_READ | winreg.KEY_WRITE)
        with key:
            lastuid, _ = winreg.QueryValueEx(key, "Counter")
            lastuid += 1
            winreg.SetValueEx(key, 'Counter', 0, winreg.REG_DWORD, lastuid)

        sha1.update(str(lastuid).encode('ascii'))

    # MAC address
    sha1.update(str(uuid.getnode()).encode('ascii'))

    # User name
    sha1.update(getpass.getuser().encode('ascii'))

    # Computer name
    sha1.update(socket.gethostname().encode('ascii'))

    uid = sha1.hexdigest()
    uid = uid[:16] # Take only the first 16 characters

    return uid<commit_msg>Ensure UID is returned as bytes using only uppercase characters<commit_after>#!/usr/bin/env python
"""
================================================================================
:mod:`uid` -- Generate unique identifier id
================================================================================

.. module:: uid
   :synopsis: Generate unique identifier id

.. inheritance-diagram:: pyhmsa.uid

"""

# Script information for the file.
__author__ = "<NAME>"
__email__ = "<EMAIL>"
__version__ = "0.1"
__copyright__ = "Copyright (c) 2013 <NAME>"
__license__ = "GPL v3"

# Standard library modules.
import hashlib
import time
import uuid
import getpass
import socket

try:
    import winreg
except ImportError: # pragma: no cover
    try:
        import _winreg as winreg
    except ImportError:
        winreg = None

# Third party modules.

# Local modules.

# Globals and constants variables.

_REG_KEY = 'SOFTWARE\\HmsaUID'

def generate_uid():
    """
    Generates a unique identifier id.
    The method to generate the id was taken from the C implementation of the
    HMSA lib.
    """
    sha1 = hashlib.sha1()

    # Current date/time
    sha1.update(str(time.time()).encode('ascii'))

    # Tick count
    # Note: GetTickCount() not available in Python
    sha1.update(str(time.clock()).encode('ascii'))

    # Counter from registry (incremented here)
    # Only on Windows
    if winreg: # pragma: no cover
        key = winreg.CreateKeyEx(winreg.HKEY_CURRENT_USER, _REG_KEY,
                                 0, winreg.KEY_READ | winreg.KEY_WRITE)
        with key:
            lastuid, _ = winreg.QueryValueEx(key, "Counter")
            lastuid += 1
            winreg.SetValueEx(key, 'Counter', 0, winreg.REG_DWORD, lastuid)

        sha1.update(str(lastuid).encode('ascii'))

    # MAC address
    sha1.update(str(uuid.getnode()).encode('ascii'))

    # User name
    sha1.update(getpass.getuser().encode('ascii'))

    # Computer name
    sha1.update(socket.gethostname().encode('ascii'))

    uid = sha1.hexdigest()
    uid = uid[:16] # Take only the first 16 characters

    return uid.encode('ascii').upper()
{'fraction_non_alphanumeric': 0.18341648847707293, 'fraction_numerical': 0.01092896174863388, 'mean_word_length': 3.214214214214214, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2722238', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1218, 'n_words': 340}