Adds a permission with given name.

        Args:
            code (str): Code name of the permission.
            save (bool): If False, does nothing.
761642
def add_permission_by_name(self, code, save=False):
        
        if not save:
            return ["%s | %s" % (p.name, p.code) for p in
                    Permission.objects.filter(code__contains=code)]
        for p in Permission.objects.filter(code__contains=code):
            if p not in self.Permissions:
                self.Permissions(permission=p)
        if p:
            self.save()
116683
def _create_permissions(**kwargs):
    
    from django.contrib.contenttypes.models import ContentType

    object_tools.autodiscover()
    tools = object_tools.tools._registry

    # This will hold the permissions we're looking for as
    # (content_type, (codename, name))
    searched_perms = list()
    # The codenames and ctypes that should exist.
    ctypes = set()
    for model, tools in tools.items():
        ctype = ContentType.objects.get_for_model(model)
        ctypes.add(ctype)
        for perm in _get_all_permissions(model._meta, tools):
            searched_perms.append((ctype, perm))

    # Find all the Permissions that have a context_type for a model we're
    # looking for.  We don't need to check for codenames since we already have
    # a list of the ones we're going to create.
    all_perms = set(auth_app.Permission.objects.filter(
        content_type__in=ctypes,
    ).values_list(
        "content_type", "codename"
    ))

    for ctype, (codename, name) in searched_perms:
        # If the permissions exists, move on.
        if (ctype.pk, codename) in all_perms:
            continue
        p = auth_app.Permission.objects.create(
            codename=codename,
            name=name,
            content_type=ctype
        )
        if kwargs.get("verbosity", 2) >= 2:
            print("Adding permission '%s'" % p)
222961
def set(self, name, permission):
        
        assert isinstance(permission, BasePermission), 'Only permission instances can be added to the set'

        self._permissions[name] = permission
951018
def set_permission(self, permission, value, parent=False, admin=False):
        
        try:
            if not getattr(self, 'parent_{}'.format(permission)) and not parent and not admin:
                return False
            level = 'parent' if parent else 'self'
            setattr(self, '{}_{}'.format(level, permission), value)

            # Set student permission to false if parent sets permission to false.
            if parent and not value:
                setattr(self, 'self_{}'.format(permission), False)

            self.save()
            return True
        except Exception as e:
            logger.error("Error occurred setting permission {} to {}: {}".format(permission, value, e))
            return False
23892
def add_permission_view_menu(self, permission_name, view_menu_name):
        
        if not (permission_name and view_menu_name):
            return None
        pv = self.find_permission_view_menu(
            permission_name,
            view_menu_name
        )
        if pv:
            return pv
        vm = self.add_view_menu(view_menu_name)
        perm = self.add_permission(permission_name)
        pv = self.permissionview_model()
        pv.view_menu_id, pv.permission_id = vm.id, perm.id
        try:
            self.get_session.add(pv)
            self.get_session.commit()
            log.info(c.LOGMSG_INF_SEC_ADD_PERMVIEW.format(str(pv)))
            return pv
        except Exception as e:
            log.error(c.LOGMSG_ERR_SEC_ADD_PERMVIEW.format(str(e)))
            self.get_session.rollback()
1038686
def code(self, value):
        
        if value not in list(defines.Codes.LIST.keys()) and value is not None:
            raise AttributeError
        self._code = value
1332796
def code(self, code):
        
        allowed_values = [400, 401, 404]
        if code not in allowed_values:
            raise ValueError(
                "Invalid value for `code` ({0}), must be one of {1}"
                .format(code, allowed_values)
            )

        self._code = code
260538
def fetch_by_code(self, code):
        
        code_data = self.read(code)

        if code_data is None:
            raise AuthCodeNotFound

        return AuthorizationCode(**code_data)
153366
public void addState(String name, String code)
    {
    	states.add(new State(this, name, code));
    }
746752
def set_permission(self, path, **kwargs):
        
        response = self._put(path, 'SETPERMISSION', **kwargs)
        assert not response.content
323385
def with_code(self, code):
        
        self.code = code if code != None else 'UNKNOWN'
        self.name = code
        return self
496539
def has_edit_permission(self, request, obj=None, version=None):
        
        # Has the edit permission for this object type
        permission_name = '{}.edit_{}'.format(self.opts.app_label, self.opts.model_name)
        has_permission = request.user.has_perm(permission_name)

        if obj is not None and has_permission is False:
            has_permission = request.user.has_perm(permission_name, obj=obj)

        if has_permission and version is not None:
            # Version must not be saved, and must belong to this user
            if version.version_number or version.owner != request.user:
                has_permission = False

        return has_permission
710236
def clean_code(self, name, forbidden):
        

        code = self.read_code(name)
        code = code.split('\n')
        new_code = []
        for line in code:
            if [bad for bad in forbidden if bad in line]:
                pass
            else:
                allowed = ['time','timeit'] # Magics where we want to keep the command
                line = self.strip_line_magic(line, allowed)
                if isinstance(line,list):
                    line = ' '.join(line)
                new_code.append(line)
        new_code = '\n'.join(new_code)
        self.write_code(name, new_code)
        return new_code
771432
def add_status_code(code):
    

    def class_decorator(cls):
        cls.status_code = code
        _sanic_exceptions[code] = cls
        return cls

    return class_decorator
35761
def safe_py_code(code):
    '''
    
    '''
    bads = (
            'import',
            ';',
            'subprocess',
            'eval',
            'open',
            'file',
            'exec',
            'input')
    for bad in bads:
        if code.count(bad):
            return False
    return True
1030699
def add_code( instruction )
      raise "Not an instruction:#{instruction.to_s}:#{instruction.class.name}" unless  instruction.is_a?(Risc::Instruction)
      raise instruction.to_s if( instruction.class.name.split("::").first == "Arm")
      new_current = instruction.last #after insertion this point is lost
      @current.insert(instruction) #insert after current
      @current = new_current
      self
    end
828195
def chmod(cls, path, permission_text):
        

        try:
            check_file_existence(path)
        except FileNotFoundError:
            _, e, _ = sys.exc_info()  # for python 2.5 compatibility
            logger.debug(e)
            return False

        logger.debug("chmod %s %s" % (path, permission_text))

        os.chmod(path, parseLsPermissionText(permission_text))