<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def discover(app, module_name=None):
 """ Automatically apply the permission logics written in the specified module. Examples -------- Assume if you have a ``perms.py`` in ``your_app`` as:: from permission.logics import AuthorPermissionLogic PERMISSION_LOGICS = ( ('your_app.your_model', AuthorPermissionLogic), ) Use this method to apply the permission logics enumerated in ``PERMISSION_LOGICS`` variable like: """

    from permission.compat import import_module
    from permission.compat import get_model
    from permission.conf import settings
    from permission.utils.logics import add_permission_logic

    variable_name = settings.PERMISSION_AUTODISCOVER_VARIABLE_NAME
    module_name = module_name or settings.PERMISSION_AUTODISCOVER_MODULE_NAME

    # import the module
    m = import_module('%s.%s' % (app, module_name))

    # check if the module have PERMISSION_LOGICS variable
    if hasattr(m, variable_name):
        # apply permission logics automatically
        permission_logic_set = getattr(m, variable_name)
        for model, permission_logic in permission_logic_set:
            if isinstance(model, six.string_types):
                # convert model string to model instance
                model = get_model(*model.split('.', 1))
            add_permission_logic(model, permission_logic)