def encode_key(self, key): # number if isinstance(key, (int, float)): return '[' + str(key) + ']' # string return '["' + escape(key) + '"]'
def listen(): print("Going to", str(w)) d = wifiRW(wifi, (lat, lon, alt)) print(d) if d is not None: e = escape((lat, lon, alt), (d[1], d[3], d[5])) if e is not None: return LocationGlobalRelative(e[0], e[1], 5) return None
def encode_value(self, value): # boolean if isinstance(value, bool) and value == True: return 'true' if isinstance(value, bool) and value == False: return 'false' # nil if value == None: return 'nil' # number if isinstance(value, (int, float)): return str(value) # string return '"' + escape(value) + '"'
def change_view(self, request, object_id, extra_context=None, **kwargs): "The 'change' admin view for this model." model = self.model opts = model._meta obj = self.get_object(request, unquote(object_id)) if not self.has_change_permission(request, obj): raise PermissionDenied if obj is None: raise Http404(_('%(name)s object with primary key %(key)r does not exist.') % {'name': force_unicode(opts.verbose_name), 'key': escape(object_id)}) if request.method == 'POST' and "_saveasnew" in request.POST: return self.add_view(request, form_url='../add/') ModelForm = self.get_form(request, obj) formsets = [] if request.method == 'POST': form = ModelForm(request.POST, request.FILES, instance=obj) if form.is_valid(): form_validated = True new_object = self.save_form(request, form, change=True) else: form_validated = False new_object = obj prefixes = {} for FormSet, inline in zip(self.get_formsets(request, new_object), self.get_inline_instances(request)): prefix = FormSet.get_default_prefix() prefixes[prefix] = prefixes.get(prefix, 0) + 1 if prefixes[prefix] != 1: prefix = "{0}-{1}".format(prefix, prefixes[prefix]) formset = FormSet(request.POST, request.FILES, instance=new_object, prefix=prefix, queryset=inline.queryset(request)) formsets.append(formset) for inline in self.get_inline_instances(request): # If this is the inline that matches this formset, and # we have some nested inlines to deal with, then we need # to get the relevant formset for each of the forms in # the current formset. if inline.inlines and inline.model == formset.model: for nested in inline.inline_instances: for the_form in formset.forms: InlineFormSet = nested.get_formset(request, the_form.instance) prefix = "{0}-{1}".format(the_form.prefix, InlineFormSet.get_default_prefix()) formsets.append(InlineFormSet(request.POST, request.FILES, instance=the_form.instance, prefix=prefix)) if all_valid(formsets) and form_validated: self.save_model(request, new_object, form, change=True) form.save_m2m() for formset in formsets: self.save_formset(request, form, formset, change=True) change_message = self.construct_change_message(request, form, formsets) self.log_change(request, new_object, change_message) return self.response_change(request, new_object) else: form = ModelForm(instance=obj) prefixes = {} for FormSet, inline in zip(self.get_formsets(request, obj), self.get_inline_instances(request)): prefix = FormSet.get_default_prefix() prefixes[prefix] = prefixes.get(prefix, 0) + 1 if prefixes[prefix] != 1: prefix = "{0}-{1}".format(prefix, prefixes[prefix]) formset = FormSet(instance=obj, prefix=prefix, queryset=inline.queryset(request)) formsets.append(formset) adminForm = helpers.AdminForm(form, self.get_fieldsets(request, obj), self.prepopulated_fields, self.get_readonly_fields(request, obj), model_admin=self) media = self.media + adminForm.media inline_admin_formsets = [] for inline, formset in zip(self.get_inline_instances(request), formsets): fieldsets = list(inline.get_fieldsets(request, obj)) readonly = list(inline.get_readonly_fields(request, obj)) inline_admin_formset = helpers.InlineAdminFormSet(inline, formset, fieldsets, readonly, model_admin=self) if inline.inlines: for form in formset.forms: if form.instance.pk: instance = form.instance else: instance = None form.inlines = inline.get_inlines(request, instance, prefix=form.prefix) inline_admin_formset.inlines = inline.get_inlines(request) inline_admin_formsets.append(inline_admin_formset) media = media + inline_admin_formset.media context = { 'title': _('Change %s') % force_unicode(opts.verbose_name), 'adminform': adminForm, 'object_id': object_id, 'original': obj, 'is_popup': "_popup" in request.REQUEST, 'media': mark_safe(media), 'inline_admin_formsets': inline_admin_formsets, 'errors': helpers.AdminErrorList(form, formsets), 'app_label': opts.app_label, } context.update(extra_context or {}) return self.render_change_form(request, context, change=True, obj=obj)
def __repr__(self): return '<Xml: "Element: {0}">'.format(str(self._element)) def __unicode__(self): return (u'<?xml version="1.0" encoding="{0}"?>\n{1}' u''.format(Xml.encoding, self._element.render())) @staticmethod def set_encoding(encoding): Xml.encoding = encoding def render(self, writer=None): if writer is None: return unicode(self) writer.write(unicode(self)) def write(self, filename): writer = codecs.open(filename, 'w', Xml.encoding) self.render(writer) writer.close() class Element(object): """ Element element class Usage: Element creation: >>> root = Element('root') >>> records = Element('blog', 'http://mariz.org', \ dict(author='Nuno Mariz', title='Nuno Mariz Weblog')) Append a child element: >>> root.append(records) or inline: >>> root.append_as_element('blog', 'http://mariz.org', \ dict(author='Nuno Mariz', title='Nuno Mariz Weblog')) """ def __init__(self, name, contents=None, attributes=None, cdata=False): self._name = name self._contents = contents self._attributes = attributes or dict() self._cdata = cdata self._elements = [] def __repr__(self): return '<Element: "%s">' % self._name def __str__(self): return self._name def __unicode__(self): attributes = u''.join([' {0}="{1}"'.format(key, Element.escape(value)) for key, value in self._attributes.items()]) contents = None if self._contents is not None: contents = Element.escape(self._contents, self._cdata) elif self._elements: contents = u''.join( [unicode(element) for element in self._elements] ) if contents is not None: return u'<{0}{1}>{2}</{3}>'.format(self._name, attributes, contents, self._name) return u'<{0}{1} />'.format(self._name, attributes) def __len__(self): return len(self._elements) def __getitem__(self, key): return self._attributes.get(key) def __setitem__(self, key, value): self._attributes[key] = value def __delitem__(self, key): del self._attributes[key] @property def elements(self): return self._elements @property def contents(self): return self._contents @property def has_contents(self): return self._contents is None @property def has_elements(self): return bool(self._elements) @property def is_cdata(self): return self._cdata @staticmethod def escape(value, cdata=False): if isinstance(value, NoneType): return u'' if isinstance(value, (bool, int, long, datetime, date, time, float, Decimal)): return value if cdata: value = u'<![CDATA[%s]]>' % value else: value = escape(value) if isinstance(value, basestring): if not isinstance(value, unicode): value = unicode(value, Xml.encoding) return value def append(self, element): assert isinstance(element, Element), \ '"element" is not a Element instance' self._elements.append(element) def append_as_element(self, *args, **kargs): self._elements.append(Element(*args, **kargs)) def render(self): return unicode(self) class Node(Element): """ Element class clone for back compatibility """ @property def nodes(self): return self._elements @property def has_nodes(self): return bool(self._elements) def append_as_node(self, *args, **kargs): self._elements.append(Node(*args, **kargs)) if __name__ == "__main__": import doctest doctest.testmod()
+ if instruction_located == False: + + sameclass = (DVMBasicMethodBlock.method.class_name == LinkedBlock.bb.method.class_name) + samemethod = (DVMBasicMethodBlock.method.name == LinkedBlock.bb.method.name) + sameblock = (DVMBasicMethodBlock.name == LinkedBlock.bb.name) + # the instruction is tagged as new instruction ? + if (sameclass and samemethod and sameblock): + + # loop over added elements + for AddedInstruction in ddm.eld.filters[ 'added elements' ][ LinkedBlock ]: + sameinstruction = (DVMBasicMethodBlockInstruction.get_raw() == AddedInstruction.ins.get_raw()) + sameoffset = (ins_idx == (AddedInstruction.bb.bb.start + AddedInstruction.offset)) + + # "to add" instruction equal to method instruction + if (sameinstruction and sameoffset): + content += label_tpl % ('GREEN', ins_idx, escape(vm.dotbuff(DVMBasicMethodBlockInstruction, ins_idx)) ) + instruction_located = True + break + + sameclass = (DVMBasicMethodBlock.method.class_name == alterLinkedBlock.bb.method.class_name) + samemethod = (DVMBasicMethodBlock.method.name == alterLinkedBlock.bb.method.name) + sameblock = (DVMBasicMethodBlock.name == alterLinkedBlock.bb.name) + # the instruction is tagged as deleted instruction ? + if (sameclass and samemethod and sameblock): + + # loop over deleted elements + for DeletedInstruction in ddm.eld.filters[ 'deleted elements' ][ alterLinkedBlock ] : + # deleted instruction equal to method instruction + sameinstruction = (DVMBasicMethodBlockInstruction.get_raw() == DeletedInstruction.ins.get_raw()) + sameoffset = (ins_idx == (DeletedInstruction.bb.bb.start + DeletedInstruction.offset)) +
def show_subpath(subpath): '''show the subpath after /path/''' return 'Subpath %s' % escape(subpath)
def show_user_profile(username): '''show the user profile for that user''' return 'User %s' % escape(username)