import hashlib

def sha256sum(filename):
    """Returns sha256sum for file"""

    f = file(filename, 'rb')
    m = hashlib.sha256()
    while True:
        b = f.read(8096)
        if not b:
            break
        m.update(b)
    f.close()
    return m.hexdigest()

import hashlib

def sha256sum(filename=None, filehandle=None):
    """Returns sha256sum for file"""

    if filename is not None:
        f = file(filename, 'rb')
    else:
        f = filehandle
    m = hashlib.sha256()
    while True:
        b = f.read(8096)
        if not b:
            break
        m.update(b)
    if filename is not None:
        f.close()
    return m.hexdigest()

Make sha256sum work with open filehandles too
Make sha256sum work with open filehandles too

  import hashlib
  
- def sha256sum(filename):
+ def sha256sum(filename=None, filehandle=None):
      """Returns sha256sum for file"""
  
+     if filename is not None:
-     f = file(filename, 'rb')
+         f = file(filename, 'rb')
+     else:
+         f = filehandle
      m = hashlib.sha256()
      while True:
          b = f.read(8096)
          if not b:
              break
          m.update(b)
+     if filename is not None:
-     f.close()
+         f.close()
      return m.hexdigest()
  
Make sha256sum work with open filehandles too
## Code Before:
import hashlib

def sha256sum(filename):
    """Returns sha256sum for file"""

    f = file(filename, 'rb')
    m = hashlib.sha256()
    while True:
        b = f.read(8096)
        if not b:
            break
        m.update(b)
    f.close()
    return m.hexdigest()

## Instruction:
Make sha256sum work with open filehandles too
## Code After:
import hashlib

def sha256sum(filename=None, filehandle=None):
    """Returns sha256sum for file"""

    if filename is not None:
        f = file(filename, 'rb')
    else:
        f = filehandle
    m = hashlib.sha256()
    while True:
        b = f.read(8096)
        if not b:
            break
        m.update(b)
    if filename is not None:
        f.close()
    return m.hexdigest()
