Take a node and return allowed attributes and check values
1438
private function wash_attribs($node)
    {
        $result = '';
        $washed = array();

        foreach ($node->attributes as $name => $attr) {
            $key   = strtolower($name);
            $value = $attr->nodeValue;

            if ($key == 'style' && ($style = $this->wash_style($value))) {
                // replace double quotes to prevent syntax error and XSS issues (#1490227)
                $result .= ' style="' . str_replace('"', '&quot;', $style) . '"';
            }
            else if (isset($this->_html_attribs[$key])) {
                $value = trim($value);
                $out   = null;

                // in SVG to/from attribs may contain anything, including URIs
                if ($key == 'to' || $key == 'from') {
                    $key = strtolower($node->getAttribute('attributeName'));
                    if ($key && !isset($this->_html_attribs[$key])) {
                        $key = null;
                    }
                }

                if ($this->is_image_attribute($node->nodeName, $key)) {
                    $out = $this->wash_uri($value, true);
                }
                else if ($this->is_link_attribute($node->nodeName, $key)) {
                    if (!preg_match('!^(javascript|vbscript|data:text)!i', $value)
                        && preg_match('!^([a-z][a-z0-9.+-]+:|//|#).+!i', $value)
                    ) {
                        $out = $value;
                    }
                }
                else if ($this->is_funciri_attribute($node->nodeName, $key)) {
                    if (preg_match('/^[a-z:]*url\(/i', $val)) {
                        if (preg_match('/^([a-z:]*url)\(\s*[\'"]?([^\'"\)]*)[\'"]?\s*\)/iu', $value, $match)) {
                            if ($url = $this->wash_uri($match[2])) {
                                $result .= ' ' . $attr->nodeName . '="' . $match[1] . '(' . htmlspecialchars($url, ENT_QUOTES) . ')'
                                     . substr($val, strlen($match[0])) . '"';
                                continue;
                            }
                        }
                        else {
                            $out = $value;
                        }
                    }
                    else {
                        $out = $value;
                    }
                }
                else if ($key) {
                   $out = $value;
                }

                if ($out !== null && $out !== '') {
                    $result .= ' ' . $attr->nodeName . '="' . htmlspecialchars($out, ENT_QUOTES) . '"';
                }
                else if ($value) {
                    $washed[] = htmlspecialchars($attr->nodeName, ENT_QUOTES);
                }
            }
            else {
                $washed[] = htmlspecialchars($attr->nodeName, ENT_QUOTES);
            }
        }

        if (!empty($washed) && $this->config['show_washed']) {
            $result .= ' x-washed="' . implode(' ', $washed) . '"';
        }

        return $result;
    }
1211930
function(node, tagNames, attributeName) {
			var i = tagNames.length;

			while(i--) {
				if(node.tagName.toLowerCase() === tagNames[i]) {
					var attrValue = this.getAttribute(node, attributeName);
					if(attrValue && attrValue !== '') {
						return attrValue;
					}
				}
			}
			return null;
		}
846233
def get_accessed(node):
    '''
    '''
    if isinstance(node, ast.Assign):
        return get_accessed(node.value)
    elif isinstance(node, ast.Name):
        return {node.id}
    names = set()
    if isinstance(node, list):
        for x in node:
            names |= get_accessed(x)
    else:
        for x in ast.iter_child_nodes(node):
            names |= get_accessed(x)
    return names
514385
def sanitize_allow(value, args=''):
    '''
    
    '''
    if isinstance(value, basestring):
        allowed_tags = []
        allowed_attributes = []
        allowed_styles = []
        
        args = args.strip().split(';')
        if len(args) > 0:
            allowed_tags = [tag.strip() for tag in args[0].split(',')]
        if len(args) > 1:
            allowed_attributes = [attr.strip() for attr in args[1].split(',')]
            
        value = bleach.clean(value, tags=allowed_tags,
                             attributes=allowed_attributes, strip=True)
    return value
678696
def in_tree(self, name):
        
        """
        if self._validate_node_name(name):
            raise RuntimeError("Argument `name` is not valid")
        return name in self._db
121860
def _is_allowed(attr, *args):
    
    for backend in _get_backends():
        try:
            if getattr(backend, attr)(*args):
                return True
        except AttributeError:
            raise NotImplementedError("%s.%s.%s() not implemented" % (
                backend.__class__.__module__, backend.__class__.__name__, attr)
            )
    return False
1071323
def visit_attribute(self, node):
        """"""
        return "%s.%s" % (self._precedence_parens(node, node.expr), node.attrname)
1238955
def node_validate(node_dict, node_num, cmd_name):
    """"""
    # cmd: [required-state, action-to-displayed, error-statement]
    req_lu = {"run": ["stopped", "Already Running"],
              "stop": ["running", "Already Stopped"],
              "connect": ["running", "Can't Connect, Node Not Running"],
              "details": [node_dict[node_num].state, ""]}
    tm = {True: ("Node {1}{2}{0} ({5}{3}{0} on {1}{4}{0})".
                 format(C_NORM, C_WARN, node_num,
                        node_dict[node_num].name,
                        node_dict[node_num].cloud_disp, C_TI)),
          False: req_lu[cmd_name][1]}
    node_valid = bool(req_lu[cmd_name][0] == node_dict[node_num].state)
    node_info = tm[node_valid]
    return node_valid, node_info
1263543
function( value, allowed_values ) {
			var error;

			// Convert the allowed_values to an array:
			allowed_values = allowed_values.split( ',' );

			if ( allowed_values.indexOf( value ) === -1 ) {
				error = {
					"rule": "matches",
					"message": "ERROR:provided value does not match an allowed value: " + allowed_values
				};
				return [ error ];
			}
			return;
		}
468371
function parseAttributes(attributes) {
  for (const prop in attributes) {
    // Parse boolean values
    if (attributes[prop] === '') {
      attributes[prop] = true;
    }
  }

  return attributes;
}
1032743
def parse_properties(node):
    
    d = dict()
    for child in node.findall('properties'):
        for subnode in child.findall('property'):
            cls = None
            try:
                if "type" in subnode.keys():
                    module = importlib.import_module('builtins')
                    cls = getattr(module, subnode.get("type"))
            except AttributeError:
                logger.info("Type [} Not a built-in type. Defaulting to string-cast.")
            d[subnode.get('name')] = cls(subnode.get('value')) if cls is not None else subnode.get('value')
    return d
1023609
def get_node_attributes(G, name):
    
    return {n: d[name] for n, d in G.node.items() if name in d}
323162
function getRangesFromHTMLNode(node) {
	if (node.type !== 'tag') {
		return [];
	}

	let ranges = [ getRange(node.open.name) ];

	if (node.attributes) {
		node.attributes.forEach(attr => {
			ranges.push(getRange(attr));
			if (!attr.boolean) {
				// add attribute value (unquoted) range for non-boolean attributes
				ranges.push(getRange(attr.value));

				if (attr.name.value.toLowerCase() === 'class') {
					// In case of `class` attribute, add each class item
					// as selection range, but only if this value is not
					// an expression (for example, React expression like
					// `class={items.join(' ')}`)
					ranges = ranges.concat(attributeValueTokens(attr.value));
				}
			}
		});
	}

	return uniqueRanges(ranges.filter(Boolean));
}
1338120
def _check_node(self, obj):
        """"""
        if not issubclass(type(obj), self.definition['node_class']):
            raise ValueError("Expected node of class " + self.definition['node_class'].__name__)
        if not hasattr(obj, 'id'):
            raise ValueError("Can't perform operation on unsaved node " + repr(obj))
240330
def getAttr(self, node, name, nsuri=None, default=join):
        """"""
        if nsuri is None:
            result = node._attrs.get(name, None)
            if result is None:
                for item in node._attrsNS.keys():
                    if item[1] == name:
                        result = node._attrsNS[item]
                        break
        else:
            result = node._attrsNS.get((nsuri, name), None)
        if result is not None:
            return result.value
        if default is not join:
            return default
        return ''
827514
def _checkAttribs(self, strict):
        """"""
        if self.min:
            warning("Minimum value not allowed for boolean-type parameter " +
                    self.name, strict)
            self.min = None
        if self.max:
            if not self.prompt:
                warning("Maximum value not allowed for boolean-type parameter " +
                                self.name + " (probably missing comma)",
                                strict)
                # try to recover by assuming max string is prompt
                self.prompt = self.max
            else:
                warning("Maximum value not allowed for boolean-type parameter " +
                        self.name, strict)
            self.max = None
        if self.choice:
            warning("Choice values not allowed for boolean-type parameter " +
                    self.name, strict)
            self.choice = None
499905
function validateAttrs(attrs) {
            const attributes = groupByName(attrs)
            attributes.forEach((nodes, name) => {
                validateNameGroup(nodes, name)
            })
        }