spacepaste

traditional

  1.  
  2. import domain_specific
  3. class Generator(object):
  4. def load(self, value):
  5. if isinstance(value, (int, long)):
  6. self.push_int(self.value)
  7. elif isinstance(value, (basestring,)):
  8. self.push_string(self.value)
  9. elif isinstance(value, (domain_specific.Namespace,)):
  10. self.push_namespace(self.value)
  11. elif isinstance(value, (domain_specific.QName,)):
  12. self.push_qname(self.value)
  13.  

zope

  1.  
  2. from zope.interface import Interface
  3. from magic import adapt, Adapter
  4. import domain_specific
  5. class IArgument(Interface):
  6. def generate(bytecodes):
  7. pass
  8. @adapt([int, long], IArgument)
  9. class IntAdapter(Adapter):
  10. def generate(self, bytecodes):
  11. bytecodes.push_int(self.value)
  12. @adapt([basestring], IArgument)
  13. class StringAdapter(Adapter):
  14. def generate(self, bytecodes):
  15. bytecodes.push_string(self.value)
  16. @adapt([domain_specific.Namespace], IArgument)
  17. class NamespaceAdapter(Adapter):
  18. def generate(bytecodes):
  19. bytecodes.push_namespace(self.value)
  20. @adapt([domain_specific.QName], IArgument)
  21. class QNameAdapter(Adapter):
  22. def generate(bytecodes):
  23. bytecodes.push_qname(self.value)
  24. class Generator(object):
  25. def load(self, value):
  26. IArgument(value).generate(self)
  27.