

def get_permission_and_content_type(self, permission, obj=None):
    "\n        Given a permission string and (optionally) an object, returns a tuple\n        of an AppPermission instance and a ContentType instance corresponding\n        to that string (and object, if given).\n        \n        The permission string is given in the dotted form, either\n        `'app_label.codename'` or\n        `'app_label.codename.target_app.target_model'`.\n        \n        If the correct AppPermission and ContentType cannot be determined for\n        the passed parameters, a `PermissionLookupError` is raised.\n        "
    perm_ct = None
    bits = permission.split('.')
    app_label = bits.pop(0)
    if (len(bits) >= 3):
        try:
            perm_ct = ContentType.objects.get(app_label=bits[(- 2)], model=bits[(- 1)])
        except ContentType.DoesNotExist:
            codename = '.'.join(bits)
        else:
            codename = '.'.join(bits[:(- 2)])
    else:
        codename = '.'.join(bits)
    obj_ct = None
    if obj:
        obj_ct = ContentType.objects.get_for_model(app_label)
    content_type = (perm_ct or obj_ct)
    if (not content_type):
        raise PermissionLookupError('ContentType must be given in permission, or object must be passed.')
    if (perm_ct and obj_ct and (perm_ct != obj_ct)):
        raise PermissionLookupError('ContentType in permission and passed object mismatched.')
    try:
        return (self.get(app_label=app_label, content_types=content_type, codename=codename), content_type)
    except self.model.DoesNotExist:
        raise PermissionLookupError('AppPermission not found.')

dataset/ETHPy150Open jlecker/django-rubberstamp/rubberstamp/models.py AppPermissionManager.get_permission_and_content_type/VarMisuse@156/365 `obj`->`app_label`