def _get_package_name(module):
    """
    Gets the package name given a module object
    
    Returns:
        str: If the module belongs to a package, the package name.  
             if the module does not belong to a package, None or ''.
    """
    try:
        # if __package__ is defined, use it
        package_name = module.__package__
    except AttributeError:
        package_name = None  
        
    if package_name is None:
        # if __path__ is defined, the package name is the module name
        package_name = module.__name__
        if not hasattr(module, '__path__'):
            # if __path__ is not defined, the package name is the
            # string before the last "." of the fully-qualified module name
            package_name = package_name.rpartition('.')[0]
           
    return package_name