2
0

apirequest_sm.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. # DO NOT EDIT.
  2. # generated by smc (http://smc.sourceforge.net/)
  3. # from file : apirequest.sm
  4. import statemap
  5. class ApiRequestState(statemap.State):
  6. def Entry(self, fsm):
  7. pass
  8. def Exit(self, fsm):
  9. pass
  10. def ApiResponse(self, fsm):
  11. self.Default(fsm)
  12. def BlankLine(self, fsm):
  13. self.Default(fsm)
  14. def ContentFinished(self, fsm):
  15. self.Default(fsm)
  16. def ContentLength(self, fsm):
  17. self.Default(fsm)
  18. def ProcessLine(self, fsm, line):
  19. self.Default(fsm)
  20. def Default(self, fsm):
  21. if fsm.getDebugFlag() == True:
  22. fsm.getDebugStream().write('TRANSITION : Default\n')
  23. msg = "\n\tState: %s\n\tTransition: %s" % (
  24. fsm.getState().getName(), fsm.getTransition())
  25. raise statemap.TransitionUndefinedException, msg
  26. class MainMap_Default(ApiRequestState):
  27. def BlankLine(self, fsm):
  28. ctxt = fsm.getOwner()
  29. if fsm.getDebugFlag() == True:
  30. fsm.getDebugStream().write("TRANSITION : MainMap.Default.BlankLine()\n")
  31. endState = fsm.getState()
  32. fsm.clearState()
  33. try:
  34. ctxt.setRequestFinished()
  35. ctxt.errbackDeferred("Protocol failure - was not expecting blank line")
  36. finally:
  37. fsm.setState(endState)
  38. def ContentFinished(self, fsm):
  39. ctxt = fsm.getOwner()
  40. if fsm.getDebugFlag() == True:
  41. fsm.getDebugStream().write("TRANSITION : MainMap.Default.ContentFinished()\n")
  42. endState = fsm.getState()
  43. fsm.clearState()
  44. try:
  45. ctxt.setRequestFinished()
  46. ctxt.errbackDeferred("Protocol failure - was not expecting content to be finished")
  47. finally:
  48. fsm.setState(endState)
  49. def ContentLength(self, fsm):
  50. ctxt = fsm.getOwner()
  51. if fsm.getDebugFlag() == True:
  52. fsm.getDebugStream().write("TRANSITION : MainMap.Default.ContentLength()\n")
  53. endState = fsm.getState()
  54. fsm.clearState()
  55. try:
  56. ctxt.setRequestFinished()
  57. ctxt.errbackDeferred("Protocol failure - was not expecting content-length header")
  58. finally:
  59. fsm.setState(endState)
  60. def ApiResponse(self, fsm):
  61. ctxt = fsm.getOwner()
  62. if fsm.getDebugFlag() == True:
  63. fsm.getDebugStream().write("TRANSITION : MainMap.Default.ApiResponse()\n")
  64. endState = fsm.getState()
  65. fsm.clearState()
  66. try:
  67. ctxt.setRequestFinished()
  68. ctxt.errbackDeferred("Protocol failure - was not expecting api response")
  69. finally:
  70. fsm.setState(endState)
  71. def ProcessLine(self, fsm, line):
  72. ctxt = fsm.getOwner()
  73. if fsm.getDebugFlag() == True:
  74. fsm.getDebugStream().write("TRANSITION : MainMap.Default.ProcessLine(line)\n")
  75. endState = fsm.getState()
  76. fsm.clearState()
  77. try:
  78. ctxt.setRequestFinished()
  79. ctxt.errbackDeferred("Protocol failure - was not expecting needing to process a line")
  80. finally:
  81. fsm.setState(endState)
  82. class MainMap_Startup(MainMap_Default):
  83. def ApiResponse(self, fsm):
  84. if fsm.getDebugFlag() == True:
  85. fsm.getDebugStream().write("TRANSITION : MainMap.Startup.ApiResponse()\n")
  86. fsm.getState().Exit(fsm)
  87. fsm.setState(MainMap.ApiResponseStarted)
  88. fsm.getState().Entry(fsm)
  89. class MainMap_ApiResponseStarted(MainMap_Default):
  90. def ContentLength(self, fsm):
  91. if fsm.getDebugFlag() == True:
  92. fsm.getDebugStream().write("TRANSITION : MainMap.ApiResponseStarted.ContentLength()\n")
  93. fsm.getState().Exit(fsm)
  94. fsm.setState(MainMap.ContentPreStarted)
  95. fsm.getState().Entry(fsm)
  96. class MainMap_ContentPreStarted(MainMap_Default):
  97. def BlankLine(self, fsm):
  98. if fsm.getDebugFlag() == True:
  99. fsm.getDebugStream().write("TRANSITION : MainMap.ContentPreStarted.BlankLine()\n")
  100. fsm.getState().Exit(fsm)
  101. fsm.setState(MainMap.ContentStarted)
  102. fsm.getState().Entry(fsm)
  103. class MainMap_ContentStarted(MainMap_Default):
  104. def ProcessLine(self, fsm, line):
  105. ctxt = fsm.getOwner()
  106. if fsm.getDebugFlag() == True:
  107. fsm.getDebugStream().write("TRANSITION : MainMap.ContentStarted.ProcessLine(line)\n")
  108. if ctxt.add_content(line) == True :
  109. fsm.getState().Exit(fsm)
  110. fsm.clearState()
  111. try:
  112. ctxt.setRequestFinished()
  113. ctxt.callbackDeferred(ctxt.getResponse())
  114. finally:
  115. fsm.setState(MainMap.Startup)
  116. fsm.getState().Entry(fsm)
  117. else:
  118. endState = fsm.getState()
  119. fsm.clearState()
  120. try:
  121. ctxt.doNothing()
  122. finally:
  123. fsm.setState(endState)
  124. class MainMap:
  125. Startup = MainMap_Startup('MainMap.Startup', 0)
  126. ApiResponseStarted = MainMap_ApiResponseStarted('MainMap.ApiResponseStarted', 1)
  127. ContentPreStarted = MainMap_ContentPreStarted('MainMap.ContentPreStarted', 2)
  128. ContentStarted = MainMap_ContentStarted('MainMap.ContentStarted', 3)
  129. Default = MainMap_Default('MainMap.Default', -1)
  130. class ApiRequest_sm(statemap.FSMContext):
  131. def __init__(self, owner):
  132. statemap.FSMContext.__init__(self)
  133. self._owner = owner
  134. self.setState(MainMap.Startup)
  135. MainMap.Startup.Entry(self)
  136. def ApiResponse(self):
  137. self._transition = 'ApiResponse'
  138. self.getState().ApiResponse(self)
  139. self._transition = None
  140. def BlankLine(self):
  141. self._transition = 'BlankLine'
  142. self.getState().BlankLine(self)
  143. self._transition = None
  144. def ContentFinished(self):
  145. self._transition = 'ContentFinished'
  146. self.getState().ContentFinished(self)
  147. self._transition = None
  148. def ContentLength(self):
  149. self._transition = 'ContentLength'
  150. self.getState().ContentLength(self)
  151. self._transition = None
  152. def ProcessLine(self, *arglist):
  153. self._transition = 'ProcessLine'
  154. self.getState().ProcessLine(self, *arglist)
  155. self._transition = None
  156. def getState(self):
  157. if self._state == None:
  158. raise statemap.StateUndefinedException
  159. return self._state
  160. def getOwner(self):
  161. return self._owner