human
Complete this python program:
def has_permission(doctype, ptype=u'read', doc=None, verbose=False, user=None):
assistant
#Here is the Python code you requested.

    """Returns True if user has permission `ptype` for given `doctype`.
    If `doc` is passed, it also checks user, share and owner permissions.
    Note: if Table DocType is passed, it always returns True.
    """
    if (not user):
        user = frappe.session.user
    if verbose:
        print(u'---    Checking    for    {0}    {1}    ---'.format(doctype, (doc.name if doc else u'-')))
    if frappe.is_table(doctype):
        if verbose:
            print(u'Table    type,    always    true')
        return True
    meta = frappe.get_meta(doctype)
    if ((ptype == u'submit') and (not cint(meta.is_submittable))):
        if verbose:
            print(u'Not    submittable')
        return False
    if ((ptype == u'import') and (not cint(meta.allow_import))):
        if verbose:
            print(u'Not    importable')
        return False
    if (user == u'Administrator'):
        if verbose:
            print(u'Allowing    Administrator')
        return True
    def false_if_not_shared():
        if (ptype in (u'read', u'write', u'share', u'email', u'print')):
            shared = frappe.share.get_shared(doctype, user, [(u'read' if (ptype in (u'email', u'print')) else ptype)])
            if doc:
                doc_name = (doc if isinstance(doc, basestring) else doc.name)
                if (doc_name in shared):
                    if verbose:
                        print(u'Shared')
                    if ((ptype in (u'read', u'write', u'share')) or meta.permissions[0].get(ptype)):
                        if verbose:
                            print(u'Is    shared')
                        return True
            elif shared:
                if verbose:
                    print(u'Has    a    shared    document')
                return True
        if verbose:
            print(u'Not    Shared')
        return False
    role_permissions = get_role_permissions(meta, user=user, verbose=verbose)
    if (not role_permissions.get(ptype)):
        return false_if_not_shared()
    perm = True
    if doc:
        if isinstance(doc, basestring):
            doc = frappe.get_doc(meta.name, doc)
        owner_perm = user_perm = controller_perm = None
        if (role_permissions[u'if_owner'].get(ptype) and (ptype !=...