TestCythonScope.pyx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ########## TestClass ##########
  2. # These utilities are for testing purposes
  3. cdef extern from *:
  4. cdef object __pyx_test_dep(object)
  5. @cname('__pyx_TestClass')
  6. cdef class TestClass(object):
  7. cdef public int value
  8. def __init__(self, int value):
  9. self.value = value
  10. def __str__(self):
  11. return 'TestClass(%d)' % self.value
  12. cdef cdef_method(self, int value):
  13. print 'Hello from cdef_method', value
  14. cpdef cpdef_method(self, int value):
  15. print 'Hello from cpdef_method', value
  16. def def_method(self, int value):
  17. print 'Hello from def_method', value
  18. @cname('cdef_cname')
  19. cdef cdef_cname_method(self, int value):
  20. print "Hello from cdef_cname_method", value
  21. @cname('cpdef_cname')
  22. cpdef cpdef_cname_method(self, int value):
  23. print "Hello from cpdef_cname_method", value
  24. @cname('def_cname')
  25. def def_cname_method(self, int value):
  26. print "Hello from def_cname_method", value
  27. @cname('__pyx_test_call_other_cy_util')
  28. cdef test_call(obj):
  29. print 'test_call'
  30. __pyx_test_dep(obj)
  31. @cname('__pyx_TestClass_New')
  32. cdef _testclass_new(int value):
  33. return TestClass(value)
  34. ########### TestDep ##########
  35. @cname('__pyx_test_dep')
  36. cdef test_dep(obj):
  37. print 'test_dep', obj
  38. ########## TestScope ##########
  39. @cname('__pyx_testscope')
  40. cdef object _testscope(int value):
  41. return "hello from cython scope, value=%d" % value
  42. ########## View.TestScope ##########
  43. @cname('__pyx_view_testscope')
  44. cdef object _testscope(int value):
  45. return "hello from cython.view scope, value=%d" % value