addressbook.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. # -*- coding: utf-8 -*-
  2. """This file is a demo for what the dynamiclly generated code would be like.
  3. """
  4. from thriftpy2.thrift import (
  5. TPayload,
  6. TException,
  7. TType,
  8. )
  9. from container import MixItem
  10. DEFAULT_LIST_SIZE = 10
  11. class PhoneType(object):
  12. MOBILE = 0
  13. HOME = 1
  14. WORK = 2
  15. class PhoneNumber(TPayload):
  16. thrift_spec = {
  17. 1: (TType.I32, "type", PhoneType, False),
  18. 2: (TType.STRING, "number", False),
  19. 3: (TType.STRUCT, "mix_item", MixItem, False),
  20. }
  21. default_spec = [("type", None), ("number", None), ("mix_item", None)]
  22. class Person(TPayload):
  23. thrift_spec = {
  24. 1: (TType.STRING, "name", False),
  25. 2: (TType.LIST, "phones", (TType.STRUCT, PhoneNumber)),
  26. 4: (TType.I32, "created_at", False),
  27. }
  28. default_spec = [("name", None), ("phones", None), ("created_at", None)]
  29. class AddressBook(TPayload):
  30. thrift_spec = {
  31. 1: (TType.MAP, "people",
  32. (TType.STRING, (TType.STRUCT, Person)))
  33. }
  34. default_spec = [("people", None)]
  35. class PersonNotExistsError(TException):
  36. thrift_spec = {
  37. 1: (TType.STRING, "message", False)
  38. }
  39. default_spec = [("message", None)]
  40. class AddressBookService(object):
  41. thrift_services = [
  42. "ping",
  43. "hello",
  44. "add",
  45. "remove",
  46. "get",
  47. "book",
  48. "get_phonenumbers",
  49. "get_phones",
  50. "sleep",
  51. ]
  52. class ping_args(TPayload):
  53. thrift_spec = {}
  54. default_spec = []
  55. class ping_result(TPayload):
  56. thrift_spec = {}
  57. default_spec = []
  58. class hello_args(TPayload):
  59. thrift_spec = {
  60. 1: (TType.STRING, "name"),
  61. }
  62. default_spec = [("name", None)]
  63. class hello_result(TPayload):
  64. thrift_spec = {
  65. 0: (TType.STRING, "success"),
  66. }
  67. default_spec = [("success", None)]
  68. class add_args(TPayload):
  69. thrift_spec = {
  70. 1: (TType.STRUCT, "person", Person),
  71. }
  72. default_spec = [("person", None)]
  73. class add_result(TPayload):
  74. thrift_spec = {
  75. 0: (TType.BOOL, "success"),
  76. }
  77. default_spec = [("success", None)]
  78. class remove_args(TPayload):
  79. thrift_spec = {
  80. 1: (TType.STRING, "name"),
  81. }
  82. default_spec = [("name", None)]
  83. class remove_result(TPayload):
  84. thrift_spec = {
  85. 0: (TType.BOOL, "success"),
  86. 1: (TType.STRUCT, "not_exists", PersonNotExistsError)
  87. }
  88. default_spec = [("success", None), ("not_exists", None)]
  89. class get_args(TPayload):
  90. thrift_spec = {
  91. 1: (TType.STRING, "name"),
  92. }
  93. default_spec = [("name", None)]
  94. class get_result(TPayload):
  95. thrift_spec = {
  96. 0: (TType.STRUCT, "success", Person),
  97. 1: (TType.STRUCT, "not_exists", PersonNotExistsError)
  98. }
  99. default_spec = [("success", None), ("not_exists", None)]
  100. class book_args(TPayload):
  101. thrift_spec = {}
  102. default_spec = []
  103. class book_result(TPayload):
  104. thrift_spec = {
  105. 0: (TType.STRUCT, "success", AddressBook),
  106. }
  107. default_spec = [("success", None)]
  108. class get_phonenumbers_args(TPayload):
  109. thrift_spec = {
  110. 1: (TType.STRING, "name"),
  111. 2: (TType.I32, "count"),
  112. }
  113. default_spec = [("name", None), ("count", None)]
  114. class get_phonenumbers_result(TPayload):
  115. thrift_spec = {
  116. 0: (TType.LIST, "success", (TType.STRUCT)),
  117. }
  118. default_spec = [("success", None)]
  119. class get_phones_args(TPayload):
  120. thrift_spec = {
  121. 1: (TType.STRING, "name"),
  122. }
  123. default_spec = [("name", None)]
  124. class get_phones_result(TPayload):
  125. thrift_spec = {
  126. 0: (TType.MAP, "success", (TType.I32, TType.STRING)),
  127. }
  128. default_spec = [("success", None)]
  129. class sleep_args(TPayload):
  130. thrift_spec = {
  131. 1: (TType.I16, "ms"),
  132. }
  133. default_spec = []
  134. class sleep_result(TPayload):
  135. thrift_spec = {
  136. 0: (TType.BOOL, "success"),
  137. }
  138. default_spec = [("success", None)]