我们从Python开源项目中,提取了以下25个代码示例,用于说明如何使用htmlentitydefs.name2codepoint.iteritems()。
def confirm(text='OK', buttons=None, hidden=None): if not buttons: buttons = {} if not hidden: hidden = {} inputs = [INPUT(_type='button', _value=name, _onclick=FORM.REDIRECT_JS % link) for name, link in buttons.iteritems()] inputs += [INPUT(_type='hidden', _name=name, _value=value) for name, value in hidden.iteritems()] form = FORM(INPUT(_type='submit', _value=text), *inputs) form.process() return form
def update(self, **kargs): """ dictionary like updating of the tag attributes """ for (key, value) in kargs.iteritems(): self[key] = value return self
def _xml(self): """ Helper for xml generation. Returns separately: - the component attributes - the generated xml of the inner components Component attributes start with an underscore ('_') and do not have a False or None value. The underscore is removed. A value of True is replaced with the attribute name. Returns: tuple: (attributes, components) """ # get the attributes for this component # (they start with '_', others may have special meanings) attr = [] for key, value in self.attributes.iteritems(): if key[:1] != '_': continue name = key[1:] if value is True: value = name elif value is False or value is None: continue attr.append((name, value)) data = self.attributes.get('data', {}) for key, value in data.iteritems(): name = 'data-' + key value = data[key] attr.append((name, value)) attr.sort() fa = '' for name, value in attr: fa += ' %s="%s"' % (name, xmlescape(value, True)) # get the xml for the inner components co = join([xmlescape(component) for component in self.components]) return (fa, co)
def siblings(self, *args, **kargs): """ Finds all sibling components that match the supplied argument list and attribute dictionary, or None if nothing could be found """ sibs = [s for s in self.parent.components if not s == self] matches = [] first_only = False if 'first_only' in kargs: first_only = kargs.pop('first_only') for c in sibs: try: check = True tag = getattr(c, 'tag').replace("/", "") if args and tag not in args: check = False for (key, value) in kargs.iteritems(): if c[key] != value: check = False if check: matches.append(c) if first_only: break except: pass return matches
def hidden_fields(self): c = [] attr = self.attributes.get('hidden', {}) if 'hidden' in self.attributes: c = [INPUT(_type='hidden', _name=key, _value=value) for (key, value) in attr.iteritems()] if hasattr(self, 'formkey') and self.formkey: c.append(INPUT(_type='hidden', _name='_formkey', _value=self.formkey)) if hasattr(self, 'formname') and self.formname: c.append(INPUT(_type='hidden', _name='_formname', _value=self.formname)) return DIV(c, _style="display:none;")
def _xml(self): """ helper for xml generation. Returns separately: - the component attributes - the generated xml of the inner components Component attributes start with an underscore ('_') and do not have a False or None value. The underscore is removed. A value of True is replaced with the attribute name. :returns: tuple: (attributes, components) """ # get the attributes for this component # (they start with '_', others may have special meanings) attr = [] for key, value in self.attributes.iteritems(): if key[:1] != '_': continue name = key[1:] if value is True: value = name elif value is False or value is None: continue attr.append((name, value)) data = self.attributes.get('data',{}) for key, value in data.iteritems(): name = 'data-' + key value = data[key] attr.append((name,value)) attr.sort() fa = '' for name,value in attr: fa += ' %s="%s"' % (name, xmlescape(value, True)) # get the xml for the inner components co = join([xmlescape(component) for component in self.components]) return (fa, co)
def siblings(self, *args, **kargs): """ find all sibling components that match the supplied argument list and attribute dictionary, or None if nothing could be found """ sibs = [s for s in self.parent.components if not s == self] matches = [] first_only = False if 'first_only' in kargs: first_only = kargs.pop('first_only') for c in sibs: try: check = True tag = getattr(c, 'tag').replace("/", "") if args and tag not in args: check = False for (key, value) in kargs.iteritems(): if c[key] != value: check = False if check: matches.append(c) if first_only: break except: pass return matches
def _xml(self): """ Helper for xml generation. Returns separately: - the component attributes - the generated xml of the inner components Component attributes start with an underscore ('_') and do not have a False or None value. The underscore is removed. A value of True is replaced with the attribute name. Returns: tuple: (attributes, components) """ # get the attributes for this component # (they start with '_', others may have special meanings) attr = [] for key, value in self.attributes.iteritems(): if key[:1] != '_': continue name = key[1:] if value is True: value = name elif value is False or value is None: continue attr.append((name, value)) data = self.attributes.get('data',{}) for key, value in data.iteritems(): name = 'data-' + key value = data[key] attr.append((name,value)) attr.sort() fa = '' for name,value in attr: fa += ' %s="%s"' % (name, xmlescape(value, True)) # get the xml for the inner components co = join([xmlescape(component) for component in self.components]) return (fa, co)