goutput.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. """
  2. @package goutput
  3. @brief Command output log widget
  4. Classes:
  5. - GMConsole
  6. - GMStc
  7. - GMStdout
  8. - GMStderr
  9. (C) 2007-2008 by the GRASS Development Team
  10. This program is free software under the GNU General Public
  11. License (>=v2). Read the file COPYING that comes with GRASS
  12. for details.
  13. @author Michael Barton (Arizona State University)
  14. @author Martin Landa <landa.martin gmail.com>
  15. """
  16. import os
  17. import sys
  18. import textwrap
  19. import time
  20. import threading
  21. import Queue
  22. import wx
  23. import wx.stc
  24. from wx.lib.newevent import NewEvent
  25. import globalvar
  26. import gcmd
  27. from debug import Debug as Debug
  28. wxCmdOutput, EVT_CMD_OUTPUT = NewEvent()
  29. wxCmdProgress, EVT_CMD_PROGRESS = NewEvent()
  30. wxCmdDone, EVT_CMD_DONE = NewEvent()
  31. wxCmdAbort, EVT_CMD_ABORT = NewEvent()
  32. def GrassCmd(cmd, stdout, stderr):
  33. """Run GRASS command on background"""
  34. return gcmd.RunCommand(cmd=cmd,
  35. stdout=stdout, stderr=stderr)
  36. class CmdThread(threading.Thread):
  37. """Thread for GRASS commands"""
  38. requestId = 0
  39. def __init__(self, parent, requestQ, resultQ, **kwds):
  40. threading.Thread.__init__(self, **kwds)
  41. self.setDaemon(True)
  42. self.parent = parent # GMConsole
  43. self.requestQ = requestQ
  44. self.resultQ = resultQ
  45. self.start()
  46. def RunCmd(self, callable, *args, **kwds):
  47. CmdThread.requestId += 1
  48. self.requestTime = time.time()
  49. self.requestQ.put((CmdThread.requestId, callable, args, kwds))
  50. return CmdThread.requestId
  51. def run(self):
  52. while True:
  53. requestId, callable, args, kwds = self.requestQ.get()
  54. self.resultQ.put((requestId, callable(*args, **kwds)))
  55. event = wxCmdDone(aborted=False,
  56. time=self.requestTime,
  57. pid=requestId)
  58. wx.PostEvent(self.parent, event)
  59. def abort(self):
  60. # TODO
  61. print self.resultQ.get_()
  62. class GMConsole(wx.Panel):
  63. """
  64. Create and manage output console for commands entered on the
  65. GIS Manager command line.
  66. """
  67. def __init__(self, parent, id=wx.ID_ANY, margin=False, pageid=0,
  68. pos=wx.DefaultPosition, size=wx.DefaultSize,
  69. style=wx.TAB_TRAVERSAL | wx.FULL_REPAINT_ON_RESIZE):
  70. wx.Panel.__init__(self, parent, id, pos, size, style)
  71. # initialize variables
  72. self.Map = None
  73. self.parent = parent # GMFrame
  74. self.lineWidth = 80
  75. self.pageid = pageid
  76. #
  77. # create queues
  78. #
  79. self.requestQ = Queue.Queue()
  80. self.resultQ = Queue.Queue()
  81. #
  82. # progress bar
  83. #
  84. self.console_progressbar = wx.Gauge(parent=self, id=wx.ID_ANY,
  85. range=100, pos=(110, 50), size=(-1, 25),
  86. style=wx.GA_HORIZONTAL)
  87. self.console_progressbar.Bind(EVT_CMD_PROGRESS, self.OnCmdProgress)
  88. #
  89. # text control for command output
  90. #
  91. self.cmd_output = GMStc(parent=self, id=wx.ID_ANY, margin=margin,
  92. wrap=None)
  93. self.cmd_output_timer = wx.Timer(self.cmd_output, id=wx.ID_ANY)
  94. self.cmd_output.Bind(EVT_CMD_OUTPUT, self.OnCmdOutput)
  95. self.cmd_output.Bind(wx.EVT_TIMER, self.OnProcessPendingOutputWindowEvents)
  96. self.Bind(EVT_CMD_DONE, self.OnCmdDone)
  97. #
  98. # stream redirection
  99. #
  100. self.cmd_stdout = GMStdout(self)
  101. self.cmd_stderr = GMStderr(self)
  102. #
  103. # thread
  104. #
  105. self.cmdThread = CmdThread(self, self.requestQ, self.resultQ)
  106. #
  107. # buttons
  108. #
  109. self.console_clear = wx.Button(parent=self, id=wx.ID_CLEAR)
  110. self.console_save = wx.Button(parent=self, id=wx.ID_SAVE)
  111. self.Bind(wx.EVT_BUTTON, self.ClearHistory, self.console_clear)
  112. self.Bind(wx.EVT_BUTTON, self.SaveHistory, self.console_save)
  113. self.Bind(EVT_CMD_ABORT, self.OnCmdDone)
  114. self.__layout()
  115. def __layout(self):
  116. """Do layout"""
  117. boxsizer1 = wx.BoxSizer(wx.VERTICAL)
  118. gridsizer1 = wx.GridSizer(rows=1, cols=2, vgap=0, hgap=0)
  119. boxsizer1.Add(item=self.cmd_output, proportion=1,
  120. flag=wx.EXPAND | wx.ADJUST_MINSIZE, border=0)
  121. gridsizer1.Add(item=self.console_clear, proportion=0,
  122. flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, border=0)
  123. gridsizer1.Add(item=self.console_save, proportion=0,
  124. flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ADJUST_MINSIZE, border=0)
  125. boxsizer1.Add(item=gridsizer1, proportion=0,
  126. flag=wx.EXPAND | wx.ALIGN_CENTRE_VERTICAL | wx.TOP | wx.BOTTOM,
  127. border=5)
  128. boxsizer1.Add(item=self.console_progressbar, proportion=0,
  129. flag=wx.EXPAND | wx.ADJUST_MINSIZE | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
  130. boxsizer1.Fit(self)
  131. boxsizer1.SetSizeHints(self)
  132. # layout
  133. self.SetAutoLayout(True)
  134. self.SetSizer(boxsizer1)
  135. def Redirect(self):
  136. """Redirect stderr
  137. @return True redirected
  138. @return False failed
  139. """
  140. if Debug.get_level() == 0:
  141. # don't redirect when debugging is enabled
  142. #sys.stdout = self.cmd_stdout
  143. #sys.stderr = self.cmd_stderr
  144. pass
  145. return True
  146. return False
  147. def WriteLog(self, line, style=None, wrap=None):
  148. """Generic method for writing log message in
  149. given style
  150. @param line text line
  151. @param style text style (see GMStc)
  152. @param stdout write to stdout or stderr
  153. """
  154. if not style:
  155. style = self.cmd_output.StyleDefault
  156. self.cmd_output.GotoPos(self.cmd_output.GetLength())
  157. p1 = self.cmd_output.GetCurrentPos()
  158. # fill space
  159. if len(line) < self.lineWidth:
  160. diff = 80 - len(line)
  161. line += diff * ' '
  162. self.cmd_output.AddTextWrapped(line, wrap=wrap) # adds os.linesep
  163. p2 = self.cmd_output.GetCurrentPos()
  164. self.cmd_output.StartStyling(p1, 0xff)
  165. self.cmd_output.SetStyling(p2 - p1, style)
  166. self.cmd_output.EnsureCaretVisible()
  167. def WriteCmdLog(self, line, pid=None):
  168. """Write out line in selected style"""
  169. if pid:
  170. line = '(' + str(pid) + ') ' + line
  171. self.WriteLog(line, self.cmd_output.StyleCommand)
  172. def RunCmd(self, command):
  173. """
  174. Run in GUI GRASS (or other) commands typed into
  175. console command text widget, and send stdout output to output
  176. text widget.
  177. Command is transformed into a list for processing.
  178. TODO: Display commands (*.d) are captured and
  179. processed separately by mapdisp.py. Display commands are
  180. rendered in map display widget that currently has
  181. the focus (as indicted by mdidx).
  182. """
  183. # map display window available ?
  184. try:
  185. curr_disp = self.parent.curr_page.maptree.mapdisplay
  186. self.Map = curr_disp.GetRender()
  187. except:
  188. curr_disp = None
  189. if not self.requestQ.empty():
  190. # only one running command enabled (per GMConsole instance)
  191. busy = wx.BusyInfo(message=_("Unable to run the command, another command is running..."),
  192. parent=self)
  193. wx.Yield()
  194. time.sleep(3)
  195. busy.Destroy()
  196. return None
  197. # command given as a string ?
  198. try:
  199. cmdlist = command.strip().split(' ')
  200. except:
  201. cmdlist = command
  202. if cmdlist[0] in globalvar.grassCmd['all']:
  203. # send GRASS command without arguments to GUI command interface
  204. # except display commands (they are handled differently)
  205. if cmdlist[0][0:2] == "d.":
  206. #
  207. # display GRASS commands
  208. #
  209. try:
  210. layertype = {'d.rast' : 'raster',
  211. 'd.rgb' : 'rgb',
  212. 'd.his' : 'his',
  213. 'd.shaded' : 'shaded',
  214. 'd.legend' : 'rastleg',
  215. 'd.rast.arrow' : 'rastarrow',
  216. 'd.rast.num' : 'rastnum',
  217. 'd.vect' : 'vector',
  218. 'd.vect.thematic': 'thememap',
  219. 'd.vect.chart' : 'themechart',
  220. 'd.grid' : 'grid',
  221. 'd.geodesic' : 'geodesic',
  222. 'd.rhumbline' : 'rhumb',
  223. 'd.labels' : 'labels'}[cmdlist[0]]
  224. except KeyError:
  225. wx.MessageBox(message=_("Command '%s' not yet implemented.") % cmdlist[0])
  226. return None
  227. # add layer into layer tree
  228. self.parent.curr_page.maptree.AddLayer(ltype=layertype,
  229. lcmd=cmdlist)
  230. else:
  231. #
  232. # other GRASS commands (r|v|g|...)
  233. #
  234. if hasattr(self.parent, "curr_page"):
  235. # change notebook page only for Layer Manager
  236. if self.parent.notebook.GetSelection() != 1:
  237. self.parent.notebook.SetSelection(1)
  238. # activate computational region (set with g.region)
  239. # for all non-display commands.
  240. tmpreg = os.getenv("GRASS_REGION")
  241. os.unsetenv("GRASS_REGION")
  242. if len(cmdlist) == 1:
  243. import menuform
  244. # process GRASS command without argument
  245. menuform.GUI().ParseCommand(cmdlist, parentframe=self)
  246. else:
  247. # process GRASS command with argument
  248. cmdPID = self.cmdThread.requestId + 1
  249. self.WriteCmdLog('%s' % ' '.join(cmdlist), pid=cmdPID)
  250. self.cmdThread.RunCmd(GrassCmd,
  251. cmdlist, self.cmd_stdout, self.cmd_stderr)
  252. self.cmd_output_timer.Start(50)
  253. return None
  254. # deactivate computational region and return to display settings
  255. if tmpreg:
  256. os.environ["GRASS_REGION"] = tmpreg
  257. else:
  258. # Send any other command to the shell. Send output to
  259. # console output window
  260. if hasattr(self.parent, "curr_page"):
  261. # change notebook page only for Layer Manager
  262. if self.parent.notebook.GetSelection() != 1:
  263. self.parent.notebook.SetSelection(1)
  264. # if command is not a GRASS command, treat it like a shell command
  265. try:
  266. generalCmd = gcmd.Command(cmdlist,
  267. stdout=self.cmd_stdout,
  268. stderr=self.cmd_stderr)
  269. except gcmd.CmdError, e:
  270. print >> sys.stderr, e
  271. return None
  272. def ClearHistory(self, event):
  273. """Clear history of commands"""
  274. self.cmd_output.ClearAll()
  275. self.console_progressbar.SetValue(0)
  276. def SaveHistory(self, event):
  277. """Save history of commands"""
  278. self.history = self.cmd_output.GetSelectedText()
  279. if self.history == '':
  280. self.history = self.cmd_output.GetText()
  281. # add newline if needed
  282. if len(self.history) > 0 and self.history[-1] != os.linesep:
  283. self.history += os.linesep
  284. wildcard = "Text file (*.txt)|*.txt"
  285. dlg = wx.FileDialog(
  286. self, message=_("Save file as..."), defaultDir=os.getcwd(),
  287. defaultFile="grass_cmd_history.txt", wildcard=wildcard,
  288. style=wx.SAVE|wx.FD_OVERWRITE_PROMPT)
  289. # Show the dialog and retrieve the user response. If it is the OK response,
  290. # process the data.
  291. if dlg.ShowModal() == wx.ID_OK:
  292. path = dlg.GetPath()
  293. output = open(path, "w")
  294. output.write(self.history)
  295. output.close()
  296. dlg.Destroy()
  297. def GetCmd(self):
  298. """Get running command or None"""
  299. return self.requestQ.get()
  300. def OnCmdOutput(self, event):
  301. """Print command output"""
  302. message = event.text
  303. type = event.type
  304. # message prefix
  305. if type == 'warning':
  306. messege = 'WARNING: ' + message
  307. elif type == 'error':
  308. message = 'ERROR: ' + message
  309. p1 = self.cmd_output.GetCurrentPos()
  310. if os.linesep not in message:
  311. self.cmd_output.AddTextWrapped(message, wrap=60)
  312. else:
  313. self.cmd_output.AppendText(message)
  314. p2 = self.cmd_output.GetCurrentPos()
  315. self.cmd_output.StartStyling(p1, 0xff)
  316. if type == 'error':
  317. self.cmd_output.SetStyling(p2 - p1 + 1, self.cmd_output.StyleError)
  318. elif type == 'warning':
  319. self.cmd_output.SetStyling(p2 - p1 + 1, self.cmd_output.StyleWarning)
  320. elif type == 'message':
  321. self.cmd_output.SetStyling(p2 - p1 + 1, self.cmd_output.StyleMessage)
  322. else: # unknown
  323. self.cmd_output.SetStyling(p2 - p1 + 1, self.cmd_output.StyleUnknown)
  324. self.cmd_output.EnsureCaretVisible()
  325. def OnCmdProgress(self, event):
  326. """Update progress message info"""
  327. self.console_progressbar.SetValue(event.value)
  328. def OnCmdDone(self, event):
  329. """Command done (or aborted)"""
  330. if event.aborted:
  331. self.cmdThread.abort()
  332. # Thread aborted (using our convention of None return)
  333. self.WriteLog(_('Please note that the data are left in incosistent stage '
  334. 'and can be corrupted'), self.cmd_output.StyleWarning)
  335. self.WriteCmdLog(_('Command aborted'),
  336. pid=self.cmdThread.requestId)
  337. else:
  338. try:
  339. # Process results here
  340. self.WriteCmdLog(_('Command finished (%d sec)') % (time.time() - event.time),
  341. pid=event.pid)
  342. except KeyError:
  343. # stopped deamon
  344. pass
  345. self.console_progressbar.SetValue(0) # reset progress bar on '0%'
  346. self.cmd_output_timer.Stop()
  347. # updated command dialog
  348. if hasattr(self.parent.parent, "btn_run"):
  349. dialog = self.parent.parent
  350. if hasattr(self.parent.parent, "btn_abort"):
  351. dialog.btn_abort.Enable(False)
  352. if hasattr(self.parent.parent, "btn_cancel"):
  353. dialog.btn_cancel.Enable(True)
  354. if hasattr(self.parent.parent, "btn_clipboard"):
  355. dialog.btn_clipboard.Enable(True)
  356. if hasattr(self.parent.parent, "btn_help"):
  357. dialog.btn_help.Enable(True)
  358. dialog.btn_run.Enable(True)
  359. if dialog.get_dcmd is None and \
  360. dialog.closebox.IsChecked():
  361. time.sleep(1)
  362. dialog.Close()
  363. event.Skip()
  364. def OnProcessPendingOutputWindowEvents(self, event):
  365. self.ProcessPendingEvents()
  366. class GMStdout:
  367. """GMConsole standard output
  368. Based on FrameOutErr.py
  369. Name: FrameOutErr.py
  370. Purpose: Redirecting stdout / stderr
  371. Author: Jean-Michel Fauth, Switzerland
  372. Copyright: (c) 2005-2007 Jean-Michel Fauth
  373. Licence: GPL
  374. """
  375. def __init__(self, parent):
  376. self.parent = parent # GMConsole
  377. def write(self, s):
  378. if len(s) == 0 or s == '\n':
  379. return
  380. s = s.replace('\n', os.linesep)
  381. for line in s.split(os.linesep):
  382. evt = wxCmdOutput(text=line + os.linesep,
  383. type='')
  384. wx.PostEvent(self.parent.cmd_output, evt)
  385. class GMStderr:
  386. """GMConsole standard error output
  387. Based on FrameOutErr.py
  388. Name: FrameOutErr.py
  389. Purpose: Redirecting stdout / stderr
  390. Author: Jean-Michel Fauth, Switzerland
  391. Copyright: (c) 2005-2007 Jean-Michel Fauth
  392. Licence: GPL
  393. """
  394. def __init__(self, parent):
  395. self.parent = parent # GMConsole
  396. self.type = ''
  397. self.message = ''
  398. self.printMessage = False
  399. def write(self, s):
  400. s = s.replace('\n', os.linesep)
  401. # remove/replace escape sequences '\b' or '\r' from stream
  402. s = s.replace('\b', '').replace('\r', '%s' % os.linesep)
  403. progressValue = -1
  404. for line in s.split(os.linesep):
  405. if len(line) == 0:
  406. continue
  407. if 'GRASS_INFO_PERCENT' in line:
  408. value = int(line.rsplit(':', 1)[1].strip())
  409. if value >= 0 and value < 100:
  410. progressValue = value
  411. else:
  412. progressValue = 0
  413. elif 'GRASS_INFO_MESSAGE' in line:
  414. self.type = 'message'
  415. self.message = line.split(':', 1)[1].strip()
  416. elif 'GRASS_INFO_WARNING' in line:
  417. self.type = 'warning'
  418. self.message = line.split(':', 1)[1].strip()
  419. elif 'GRASS_INFO_ERROR' in line:
  420. self.type = 'error'
  421. self.message = line.split(':', 1)[1].strip()
  422. elif 'GRASS_INFO_END' in line:
  423. self.printMessage = True
  424. elif not self.type:
  425. if len(line) > 0:
  426. continue
  427. evt = wxCmdOutput(text=line,
  428. type='')
  429. wx.PostEvent(self.parent.cmd_output, evt)
  430. elif len(line) > 0:
  431. self.message += line.strip() + os.linesep
  432. if self.printMessage and len(self.message) > 0:
  433. evt = wxCmdOutput(text=self.message,
  434. type=self.type)
  435. wx.PostEvent(self.parent.cmd_output, evt)
  436. self.type = ''
  437. self.message = ''
  438. self.printMessage = False
  439. # update progress message
  440. if progressValue > -1:
  441. # self.gmgauge.SetValue(progressValue)
  442. evt = wxCmdProgress(value=progressValue)
  443. wx.PostEvent(self.parent.console_progressbar, evt)
  444. class GMStc(wx.stc.StyledTextCtrl):
  445. """Styled GMConsole
  446. Based on FrameOutErr.py
  447. Name: FrameOutErr.py
  448. Purpose: Redirecting stdout / stderr
  449. Author: Jean-Michel Fauth, Switzerland
  450. Copyright: (c) 2005-2007 Jean-Michel Fauth
  451. Licence: GPL
  452. """
  453. def __init__(self, parent, id, margin=False, wrap=None):
  454. wx.stc.StyledTextCtrl.__init__(self, parent, id)
  455. self.parent = parent
  456. self.wrap = wrap
  457. #
  458. # styles
  459. #
  460. self.StyleDefault = 0
  461. self.StyleDefaultSpec = "face:Courier New,size:10,fore:#000000,back:#FFFFFF"
  462. self.StyleCommand = 1
  463. self.StyleCommandSpec = "face:Courier New,size:10,fore:#000000,back:#bcbcbc"
  464. self.StyleOutput = 2
  465. self.StyleOutputSpec = "face:Courier New,size:10,fore:#000000,back:#FFFFFF"
  466. # fatal error
  467. self.StyleError = 3
  468. self.StyleErrorSpec = "face:Courier New,size:10,fore:#7F0000,back:#FFFFFF"
  469. # warning
  470. self.StyleWarning = 4
  471. self.StyleWarningSpec = "face:Courier New,size:10,fore:#0000FF,back:#FFFFFF"
  472. # message
  473. self.StyleMessage = 5
  474. self.StyleMessageSpec = "face:Courier New,size:10,fore:#000000,back:#FFFFFF"
  475. # unknown
  476. self.StyleUnknown = 6
  477. self.StyleUnknownSpec = "face:Courier New,size:10,fore:#7F0000,back:#FFFFFF"
  478. # default and clear => init
  479. self.StyleSetSpec(wx.stc.STC_STYLE_DEFAULT, self.StyleDefaultSpec)
  480. self.StyleClearAll()
  481. self.StyleSetSpec(self.StyleCommand, self.StyleCommandSpec)
  482. self.StyleSetSpec(self.StyleOutput, self.StyleOutputSpec)
  483. self.StyleSetSpec(self.StyleError, self.StyleErrorSpec)
  484. self.StyleSetSpec(self.StyleWarning, self.StyleWarningSpec)
  485. self.StyleSetSpec(self.StyleMessage, self.StyleMessageSpec)
  486. self.StyleSetSpec(self.StyleUnknown, self.StyleUnknownSpec)
  487. #
  488. # line margins
  489. #
  490. # TODO print number only from cmdlog
  491. self.SetMarginWidth(1, 0)
  492. self.SetMarginWidth(2, 0)
  493. if margin:
  494. self.SetMarginType(0, wx.stc.STC_MARGIN_NUMBER)
  495. self.SetMarginWidth(0, 30)
  496. else:
  497. self.SetMarginWidth(0, 0)
  498. #
  499. # miscellaneous
  500. #
  501. self.SetViewWhiteSpace(False)
  502. self.SetTabWidth(4)
  503. self.SetUseTabs(False)
  504. self.UsePopUp(True)
  505. self.SetSelBackground(True, "#FFFF00")
  506. self.SetUseHorizontalScrollBar(True)
  507. #
  508. # bindins
  509. #
  510. self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
  511. def OnDestroy(self, evt):
  512. """The clipboard contents can be preserved after
  513. the app has exited"""
  514. wx.TheClipboard.Flush()
  515. evt.Skip()
  516. def AddTextWrapped(self, txt, wrap=None):
  517. """Add string to text area.
  518. String is wrapped and linesep is also added to the end
  519. of the string"""
  520. if wrap is None and self.wrap:
  521. wrap = self.wrap
  522. if wrap is not None:
  523. txt = textwrap.fill(txt, wrap) + os.linesep
  524. else:
  525. txt += os.linesep
  526. self.AddText(txt)
  527. def SetWrap(self, wrap):
  528. """Set wrapping value
  529. @param wrap wrapping value
  530. @return current wrapping value
  531. """
  532. if wrap > 0:
  533. self.wrap = wrap
  534. return self.wrap