from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

import os
import sys
import unicodedata
import idlk.base41

if sys.version_info[0] == 3:
    _get_byte = lambda c: c
else:
    _get_byte = ord

def hash_macroman(data):
    h = 0
    for c in data:
        h = ((h << 8) + h) + _get_byte(c)

    return h % 0xFFFEECED

def idlk(filename):
    # Normalize to NFC.
    filename = unicodedata.normalize('NFC', filename)

    # Convert to lowercase first.
    filename = filename.lower()

    # The original algorithm seems to prefer Mac Roman encoding as long as
    # there are no non-mappable characters in the file name.
    try:
        macroman_name = filename.encode("macroman")
    except UnicodeEncodeError:
        pass
    else:
        hashed = base41.encode(hash_macroman(macroman_name))
        base, ext = os.path.splitext(macroman_name)
        return "~{:s}~{:s}.idlk".format(base[0:18].decode("macroman"), hashed)

    # Regrettably the encoding / hashing algorithm for unicode filenames is
    # not currently known. Please file a feature request/patch if you
    # discover a working implementation.
    return False

from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

import os
import sys
import unicodedata
from idlk import base41

if sys.version_info[0] == 3:
    _get_byte = lambda c: c
else:
    _get_byte = ord

def hash_macroman(data):
    """
    Compute the hash for the given byte string.
    """
    result = 0
    for char in data:
        result = ((result << 8) + result) + _get_byte(char)

    return result % 0xFFFEECED

def idlk(filename):
    """
    Generate the lock file name for the given file.
    """

    # Normalize to NFC.
    filename = unicodedata.normalize('NFC', filename)

    # Convert to lowercase first.
    filename = filename.lower()

    # The original algorithm seems to prefer Mac Roman encoding as long as
    # there are no non-mappable characters in the file name.
    try:
        macroman_name = filename.encode("macroman")
    except UnicodeEncodeError:
        pass
    else:
        hashed = base41.encode(hash_macroman(macroman_name))
        base = os.path.splitext(macroman_name)[0]
        return "~{:s}~{:s}.idlk".format(base[0:18].decode("macroman"), hashed)

    # Regrettably the encoding / hashing algorithm for unicode filenames is
    # not currently known. Please file a feature request/patch if you
    # discover a working implementation.
    return False

Fix issues reported by pylint
Fix issues reported by pylint

  from __future__ import absolute_import
  from __future__ import division
  from __future__ import unicode_literals
  
  import os
  import sys
  import unicodedata
- import idlk.base41
+ from idlk import base41
  
  if sys.version_info[0] == 3:
      _get_byte = lambda c: c
  else:
      _get_byte = ord
  
  def hash_macroman(data):
-     h = 0
+     """
+     Compute the hash for the given byte string.
+     """
+     result = 0
-     for c in data:
+     for char in data:
-         h = ((h << 8) + h) + _get_byte(c)
+         result = ((result << 8) + result) + _get_byte(char)
  
-     return h % 0xFFFEECED
+     return result % 0xFFFEECED
  
  def idlk(filename):
+     """
+     Generate the lock file name for the given file.
+     """
+ 
      # Normalize to NFC.
      filename = unicodedata.normalize('NFC', filename)
  
      # Convert to lowercase first.
      filename = filename.lower()
  
      # The original algorithm seems to prefer Mac Roman encoding as long as
      # there are no non-mappable characters in the file name.
      try:
          macroman_name = filename.encode("macroman")
      except UnicodeEncodeError:
          pass
      else:
          hashed = base41.encode(hash_macroman(macroman_name))
-         base, ext = os.path.splitext(macroman_name)
+         base = os.path.splitext(macroman_name)[0]
          return "~{:s}~{:s}.idlk".format(base[0:18].decode("macroman"), hashed)
  
      # Regrettably the encoding / hashing algorithm for unicode filenames is
      # not currently known. Please file a feature request/patch if you
      # discover a working implementation.
      return False
  
Fix issues reported by pylint
## Code Before:
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

import os
import sys
import unicodedata
import idlk.base41

if sys.version_info[0] == 3:
    _get_byte = lambda c: c
else:
    _get_byte = ord

def hash_macroman(data):
    h = 0
    for c in data:
        h = ((h << 8) + h) + _get_byte(c)

    return h % 0xFFFEECED

def idlk(filename):
    # Normalize to NFC.
    filename = unicodedata.normalize('NFC', filename)

    # Convert to lowercase first.
    filename = filename.lower()

    # The original algorithm seems to prefer Mac Roman encoding as long as
    # there are no non-mappable characters in the file name.
    try:
        macroman_name = filename.encode("macroman")
    except UnicodeEncodeError:
        pass
    else:
        hashed = base41.encode(hash_macroman(macroman_name))
        base, ext = os.path.splitext(macroman_name)
        return "~{:s}~{:s}.idlk".format(base[0:18].decode("macroman"), hashed)

    # Regrettably the encoding / hashing algorithm for unicode filenames is
    # not currently known. Please file a feature request/patch if you
    # discover a working implementation.
    return False

## Instruction:
Fix issues reported by pylint
## Code After:
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals

import os
import sys
import unicodedata
from idlk import base41

if sys.version_info[0] == 3:
    _get_byte = lambda c: c
else:
    _get_byte = ord

def hash_macroman(data):
    """
    Compute the hash for the given byte string.
    """
    result = 0
    for char in data:
        result = ((result << 8) + result) + _get_byte(char)

    return result % 0xFFFEECED

def idlk(filename):
    """
    Generate the lock file name for the given file.
    """

    # Normalize to NFC.
    filename = unicodedata.normalize('NFC', filename)

    # Convert to lowercase first.
    filename = filename.lower()

    # The original algorithm seems to prefer Mac Roman encoding as long as
    # there are no non-mappable characters in the file name.
    try:
        macroman_name = filename.encode("macroman")
    except UnicodeEncodeError:
        pass
    else:
        hashed = base41.encode(hash_macroman(macroman_name))
        base = os.path.splitext(macroman_name)[0]
        return "~{:s}~{:s}.idlk".format(base[0:18].decode("macroman"), hashed)

    # Regrettably the encoding / hashing algorithm for unicode filenames is
    # not currently known. Please file a feature request/patch if you
    # discover a working implementation.
    return False
