Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. # -*- test-case-name: twisted.mail.test.test_mail -*-
  2. #
  3. # Copyright (c) Twisted Matrix Laboratories.
  4. # See LICENSE for details.
  5. """
  6. Support for aliases(5) configuration files.
  7. @author: Jp Calderone
  8. """
  9. import os
  10. import tempfile
  11. from zope.interface import implementer
  12. from twisted.internet import defer, protocol, reactor
  13. from twisted.mail import smtp
  14. from twisted.mail.interfaces import IAlias
  15. from twisted.python import failure, log
  16. def handle(result, line, filename, lineNo):
  17. """
  18. Parse a line from an aliases file.
  19. @type result: L{dict} mapping L{bytes} to L{list} of L{bytes}
  20. @param result: A dictionary mapping username to aliases to which
  21. the results of parsing the line are added.
  22. @type line: L{bytes}
  23. @param line: A line from an aliases file.
  24. @type filename: L{bytes}
  25. @param filename: The full or relative path to the aliases file.
  26. @type lineNo: L{int}
  27. @param lineNo: The position of the line within the aliases file.
  28. """
  29. parts = [p.strip() for p in line.split(":", 1)]
  30. if len(parts) != 2:
  31. fmt = "Invalid format on line %d of alias file %s."
  32. arg = (lineNo, filename)
  33. log.err(fmt % arg)
  34. else:
  35. user, alias = parts
  36. result.setdefault(user.strip(), []).extend(map(str.strip, alias.split(",")))
  37. def loadAliasFile(domains, filename=None, fp=None):
  38. """
  39. Load a file containing email aliases.
  40. Lines in the file should be formatted like so::
  41. username: alias1, alias2, ..., aliasN
  42. Aliases beginning with a C{|} will be treated as programs, will be run, and
  43. the message will be written to their stdin.
  44. Aliases beginning with a C{:} will be treated as a file containing
  45. additional aliases for the username.
  46. Aliases beginning with a C{/} will be treated as the full pathname to a file
  47. to which the message will be appended.
  48. Aliases without a host part will be assumed to be addresses on localhost.
  49. If a username is specified multiple times, the aliases for each are joined
  50. together as if they had all been on one line.
  51. Lines beginning with a space or a tab are continuations of the previous
  52. line.
  53. Lines beginning with a C{#} are comments.
  54. @type domains: L{dict} mapping L{bytes} to L{IDomain} provider
  55. @param domains: A mapping of domain name to domain object.
  56. @type filename: L{bytes} or L{None}
  57. @param filename: The full or relative path to a file from which to load
  58. aliases. If omitted, the C{fp} parameter must be specified.
  59. @type fp: file-like object or L{None}
  60. @param fp: The file from which to load aliases. If specified,
  61. the C{filename} parameter is ignored.
  62. @rtype: L{dict} mapping L{bytes} to L{AliasGroup}
  63. @return: A mapping from username to group of aliases.
  64. """
  65. result = {}
  66. close = False
  67. if fp is None:
  68. fp = open(filename)
  69. close = True
  70. else:
  71. filename = getattr(fp, "name", "<unknown>")
  72. i = 0
  73. prev = ""
  74. try:
  75. for line in fp:
  76. i += 1
  77. line = line.rstrip()
  78. if line.lstrip().startswith("#"):
  79. continue
  80. elif line.startswith(" ") or line.startswith("\t"):
  81. prev = prev + line
  82. else:
  83. if prev:
  84. handle(result, prev, filename, i)
  85. prev = line
  86. finally:
  87. if close:
  88. fp.close()
  89. if prev:
  90. handle(result, prev, filename, i)
  91. for (u, a) in result.items():
  92. result[u] = AliasGroup(a, domains, u)
  93. return result
  94. class AliasBase:
  95. """
  96. The default base class for aliases.
  97. @ivar domains: See L{__init__}.
  98. @type original: L{Address}
  99. @ivar original: The original address being aliased.
  100. """
  101. def __init__(self, domains, original):
  102. """
  103. @type domains: L{dict} mapping L{bytes} to L{IDomain} provider
  104. @param domains: A mapping of domain name to domain object.
  105. @type original: L{bytes}
  106. @param original: The original address being aliased.
  107. """
  108. self.domains = domains
  109. self.original = smtp.Address(original)
  110. def domain(self):
  111. """
  112. Return the domain associated with original address.
  113. @rtype: L{IDomain} provider
  114. @return: The domain for the original address.
  115. """
  116. return self.domains[self.original.domain]
  117. def resolve(self, aliasmap, memo=None):
  118. """
  119. Map this alias to its ultimate destination.
  120. @type aliasmap: L{dict} mapping L{bytes} to L{AliasBase}
  121. @param aliasmap: A mapping of username to alias or group of aliases.
  122. @type memo: L{None} or L{dict} of L{AliasBase}
  123. @param memo: A record of the aliases already considered in the
  124. resolution process. If provided, C{memo} is modified to include
  125. this alias.
  126. @rtype: L{IMessage <smtp.IMessage>} or L{None}
  127. @return: A message receiver for the ultimate destination or None for
  128. an invalid destination.
  129. """
  130. if memo is None:
  131. memo = {}
  132. if str(self) in memo:
  133. return None
  134. memo[str(self)] = None
  135. return self.createMessageReceiver()
  136. @implementer(IAlias)
  137. class AddressAlias(AliasBase):
  138. """
  139. An alias which translates one email address into another.
  140. @type alias : L{Address}
  141. @ivar alias: The destination address.
  142. """
  143. def __init__(self, alias, *args):
  144. """
  145. @type alias: L{Address}, L{User}, L{bytes} or object which can be
  146. converted into L{bytes}
  147. @param alias: The destination address.
  148. @type args: 2-L{tuple} of (0) L{dict} mapping L{bytes} to L{IDomain}
  149. provider, (1) L{bytes}
  150. @param args: Arguments for L{AliasBase.__init__}.
  151. """
  152. AliasBase.__init__(self, *args)
  153. self.alias = smtp.Address(alias)
  154. def __str__(self) -> str:
  155. """
  156. Build a string representation of this L{AddressAlias} instance.
  157. @rtype: L{bytes}
  158. @return: A string containing the destination address.
  159. """
  160. return f"<Address {self.alias}>"
  161. def createMessageReceiver(self):
  162. """
  163. Create a message receiver which delivers a message to
  164. the destination address.
  165. @rtype: L{IMessage <smtp.IMessage>} provider
  166. @return: A message receiver.
  167. """
  168. return self.domain().exists(str(self.alias))
  169. def resolve(self, aliasmap, memo=None):
  170. """
  171. Map this alias to its ultimate destination.
  172. @type aliasmap: L{dict} mapping L{bytes} to L{AliasBase}
  173. @param aliasmap: A mapping of username to alias or group of aliases.
  174. @type memo: L{None} or L{dict} of L{AliasBase}
  175. @param memo: A record of the aliases already considered in the
  176. resolution process. If provided, C{memo} is modified to include
  177. this alias.
  178. @rtype: L{IMessage <smtp.IMessage>} or L{None}
  179. @return: A message receiver for the ultimate destination or None for
  180. an invalid destination.
  181. """
  182. if memo is None:
  183. memo = {}
  184. if str(self) in memo:
  185. return None
  186. memo[str(self)] = None
  187. try:
  188. return self.domain().exists(smtp.User(self.alias, None, None, None), memo)()
  189. except smtp.SMTPBadRcpt:
  190. pass
  191. if self.alias.local in aliasmap:
  192. return aliasmap[self.alias.local].resolve(aliasmap, memo)
  193. return None
  194. @implementer(smtp.IMessage)
  195. class FileWrapper:
  196. """
  197. A message receiver which delivers a message to a file.
  198. @type fp: file-like object
  199. @ivar fp: A file used for temporary storage of the message.
  200. @type finalname: L{bytes}
  201. @ivar finalname: The name of the file in which the message should be
  202. stored.
  203. """
  204. def __init__(self, filename):
  205. """
  206. @type filename: L{bytes}
  207. @param filename: The name of the file in which the message should be
  208. stored.
  209. """
  210. self.fp = tempfile.TemporaryFile()
  211. self.finalname = filename
  212. def lineReceived(self, line):
  213. """
  214. Write a received line to the temporary file.
  215. @type line: L{bytes}
  216. @param line: A received line of the message.
  217. """
  218. self.fp.write(line + "\n")
  219. def eomReceived(self):
  220. """
  221. Handle end of message by writing the message to the file.
  222. @rtype: L{Deferred <defer.Deferred>} which successfully results in
  223. L{bytes}
  224. @return: A deferred which succeeds with the name of the file to which
  225. the message has been stored or fails if the message cannot be
  226. saved to the file.
  227. """
  228. self.fp.seek(0, 0)
  229. try:
  230. f = open(self.finalname, "a")
  231. except BaseException:
  232. return defer.fail(failure.Failure())
  233. with f:
  234. f.write(self.fp.read())
  235. self.fp.close()
  236. return defer.succeed(self.finalname)
  237. def connectionLost(self):
  238. """
  239. Close the temporary file when the connection is lost.
  240. """
  241. self.fp.close()
  242. self.fp = None
  243. def __str__(self) -> str:
  244. """
  245. Build a string representation of this L{FileWrapper} instance.
  246. @rtype: L{bytes}
  247. @return: A string containing the file name of the message.
  248. """
  249. return f"<FileWrapper {self.finalname}>"
  250. @implementer(IAlias)
  251. class FileAlias(AliasBase):
  252. """
  253. An alias which translates an address to a file.
  254. @ivar filename: See L{__init__}.
  255. """
  256. def __init__(self, filename, *args):
  257. """
  258. @type filename: L{bytes}
  259. @param filename: The name of the file in which to store the message.
  260. @type args: 2-L{tuple} of (0) L{dict} mapping L{bytes} to L{IDomain}
  261. provider, (1) L{bytes}
  262. @param args: Arguments for L{AliasBase.__init__}.
  263. """
  264. AliasBase.__init__(self, *args)
  265. self.filename = filename
  266. def __str__(self) -> str:
  267. """
  268. Build a string representation of this L{FileAlias} instance.
  269. @rtype: L{bytes}
  270. @return: A string containing the name of the file.
  271. """
  272. return f"<File {self.filename}>"
  273. def createMessageReceiver(self):
  274. """
  275. Create a message receiver which delivers a message to the file.
  276. @rtype: L{FileWrapper}
  277. @return: A message receiver which writes a message to the file.
  278. """
  279. return FileWrapper(self.filename)
  280. class ProcessAliasTimeout(Exception):
  281. """
  282. An error indicating that a timeout occurred while waiting for a process
  283. to complete.
  284. """
  285. @implementer(smtp.IMessage)
  286. class MessageWrapper:
  287. """
  288. A message receiver which delivers a message to a child process.
  289. @type completionTimeout: L{int} or L{float}
  290. @ivar completionTimeout: The number of seconds to wait for the child
  291. process to exit before reporting the delivery as a failure.
  292. @type _timeoutCallID: L{None} or
  293. L{IDelayedCall <twisted.internet.interfaces.IDelayedCall>} provider
  294. @ivar _timeoutCallID: The call used to time out delivery, started when the
  295. connection to the child process is closed.
  296. @type done: L{bool}
  297. @ivar done: A flag indicating whether the child process has exited
  298. (C{True}) or not (C{False}).
  299. @type reactor: L{IReactorTime <twisted.internet.interfaces.IReactorTime>}
  300. provider
  301. @ivar reactor: A reactor which will be used to schedule timeouts.
  302. @ivar protocol: See L{__init__}.
  303. @type processName: L{bytes} or L{None}
  304. @ivar processName: The process name.
  305. @type completion: L{Deferred <defer.Deferred>}
  306. @ivar completion: The deferred which will be triggered by the protocol
  307. when the child process exits.
  308. """
  309. done = False
  310. completionTimeout = 60
  311. _timeoutCallID = None
  312. reactor = reactor
  313. def __init__(self, protocol, process=None, reactor=None):
  314. """
  315. @type protocol: L{ProcessAliasProtocol}
  316. @param protocol: The protocol associated with the child process.
  317. @type process: L{bytes} or L{None}
  318. @param process: The process name.
  319. @type reactor: L{None} or L{IReactorTime
  320. <twisted.internet.interfaces.IReactorTime>} provider
  321. @param reactor: A reactor which will be used to schedule timeouts.
  322. """
  323. self.processName = process
  324. self.protocol = protocol
  325. self.completion = defer.Deferred()
  326. self.protocol.onEnd = self.completion
  327. self.completion.addBoth(self._processEnded)
  328. if reactor is not None:
  329. self.reactor = reactor
  330. def _processEnded(self, result):
  331. """
  332. Record process termination and cancel the timeout call if it is active.
  333. @type result: L{Failure <failure.Failure>}
  334. @param result: The reason the child process terminated.
  335. @rtype: L{None} or L{Failure <failure.Failure>}
  336. @return: None, if the process end is expected, or the reason the child
  337. process terminated, if the process end is unexpected.
  338. """
  339. self.done = True
  340. if self._timeoutCallID is not None:
  341. # eomReceived was called, we're actually waiting for the process to
  342. # exit.
  343. self._timeoutCallID.cancel()
  344. self._timeoutCallID = None
  345. else:
  346. # eomReceived was not called, this is unexpected, propagate the
  347. # error.
  348. return result
  349. def lineReceived(self, line):
  350. """
  351. Write a received line to the child process.
  352. @type line: L{bytes}
  353. @param line: A received line of the message.
  354. """
  355. if self.done:
  356. return
  357. self.protocol.transport.write(line + "\n")
  358. def eomReceived(self):
  359. """
  360. Disconnect from the child process and set up a timeout to wait for it
  361. to exit.
  362. @rtype: L{Deferred <defer.Deferred>}
  363. @return: A deferred which will be called back when the child process
  364. exits.
  365. """
  366. if not self.done:
  367. self.protocol.transport.loseConnection()
  368. self._timeoutCallID = self.reactor.callLater(
  369. self.completionTimeout, self._completionCancel
  370. )
  371. return self.completion
  372. def _completionCancel(self):
  373. """
  374. Handle the expiration of the timeout for the child process to exit by
  375. terminating the child process forcefully and issuing a failure to the
  376. L{completion} deferred.
  377. """
  378. self._timeoutCallID = None
  379. self.protocol.transport.signalProcess("KILL")
  380. exc = ProcessAliasTimeout(f"No answer after {self.completionTimeout} seconds")
  381. self.protocol.onEnd = None
  382. self.completion.errback(failure.Failure(exc))
  383. def connectionLost(self):
  384. """
  385. Ignore notification of lost connection.
  386. """
  387. def __str__(self) -> str:
  388. """
  389. Build a string representation of this L{MessageWrapper} instance.
  390. @rtype: L{bytes}
  391. @return: A string containing the name of the process.
  392. """
  393. return f"<ProcessWrapper {self.processName}>"
  394. class ProcessAliasProtocol(protocol.ProcessProtocol):
  395. """
  396. A process protocol which errbacks a deferred when the associated
  397. process ends.
  398. @type onEnd: L{None} or L{Deferred <defer.Deferred>}
  399. @ivar onEnd: If set, a deferred on which to errback when the process ends.
  400. """
  401. onEnd = None
  402. def processEnded(self, reason):
  403. """
  404. Call an errback.
  405. @type reason: L{Failure <failure.Failure>}
  406. @param reason: The reason the child process terminated.
  407. """
  408. if self.onEnd is not None:
  409. self.onEnd.errback(reason)
  410. @implementer(IAlias)
  411. class ProcessAlias(AliasBase):
  412. """
  413. An alias which is handled by the execution of a program.
  414. @type path: L{list} of L{bytes}
  415. @ivar path: The arguments to pass to the process. The first string is
  416. the executable's name.
  417. @type program: L{bytes}
  418. @ivar program: The path of the program to be executed.
  419. @type reactor: L{IReactorTime <twisted.internet.interfaces.IReactorTime>}
  420. and L{IReactorProcess <twisted.internet.interfaces.IReactorProcess>}
  421. provider
  422. @ivar reactor: A reactor which will be used to create and timeout the
  423. child process.
  424. """
  425. reactor = reactor
  426. def __init__(self, path, *args):
  427. """
  428. @type path: L{bytes}
  429. @param path: The command to invoke the program consisting of the path
  430. to the executable followed by any arguments.
  431. @type args: 2-L{tuple} of (0) L{dict} mapping L{bytes} to L{IDomain}
  432. provider, (1) L{bytes}
  433. @param args: Arguments for L{AliasBase.__init__}.
  434. """
  435. AliasBase.__init__(self, *args)
  436. self.path = path.split()
  437. self.program = self.path[0]
  438. def __str__(self) -> str:
  439. """
  440. Build a string representation of this L{ProcessAlias} instance.
  441. @rtype: L{bytes}
  442. @return: A string containing the command used to invoke the process.
  443. """
  444. return f"<Process {self.path}>"
  445. def spawnProcess(self, proto, program, path):
  446. """
  447. Spawn a process.
  448. This wraps the L{spawnProcess
  449. <twisted.internet.interfaces.IReactorProcess.spawnProcess>} method on
  450. L{reactor} so that it can be customized for test purposes.
  451. @type proto: L{IProcessProtocol
  452. <twisted.internet.interfaces.IProcessProtocol>} provider
  453. @param proto: An object which will be notified of all events related to
  454. the created process.
  455. @type program: L{bytes}
  456. @param program: The full path name of the file to execute.
  457. @type path: L{list} of L{bytes}
  458. @param path: The arguments to pass to the process. The first string
  459. should be the executable's name.
  460. @rtype: L{IProcessTransport
  461. <twisted.internet.interfaces.IProcessTransport>} provider
  462. @return: A process transport.
  463. """
  464. return self.reactor.spawnProcess(proto, program, path)
  465. def createMessageReceiver(self):
  466. """
  467. Launch a process and create a message receiver to pass a message
  468. to the process.
  469. @rtype: L{MessageWrapper}
  470. @return: A message receiver which delivers a message to the process.
  471. """
  472. p = ProcessAliasProtocol()
  473. m = MessageWrapper(p, self.program, self.reactor)
  474. self.spawnProcess(p, self.program, self.path)
  475. return m
  476. @implementer(smtp.IMessage)
  477. class MultiWrapper:
  478. """
  479. A message receiver which delivers a single message to multiple other
  480. message receivers.
  481. @ivar objs: See L{__init__}.
  482. """
  483. def __init__(self, objs):
  484. """
  485. @type objs: L{list} of L{IMessage <smtp.IMessage>} provider
  486. @param objs: Message receivers to which the incoming message should be
  487. directed.
  488. """
  489. self.objs = objs
  490. def lineReceived(self, line):
  491. """
  492. Pass a received line to the message receivers.
  493. @type line: L{bytes}
  494. @param line: A line of the message.
  495. """
  496. for o in self.objs:
  497. o.lineReceived(line)
  498. def eomReceived(self):
  499. """
  500. Pass the end of message along to the message receivers.
  501. @rtype: L{DeferredList <defer.DeferredList>} whose successful results
  502. are L{bytes} or L{None}
  503. @return: A deferred list which triggers when all of the message
  504. receivers have finished handling their end of message.
  505. """
  506. return defer.DeferredList([o.eomReceived() for o in self.objs])
  507. def connectionLost(self):
  508. """
  509. Inform the message receivers that the connection has been lost.
  510. """
  511. for o in self.objs:
  512. o.connectionLost()
  513. def __str__(self) -> str:
  514. """
  515. Build a string representation of this L{MultiWrapper} instance.
  516. @rtype: L{bytes}
  517. @return: A string containing a list of the message receivers.
  518. """
  519. return f"<GroupWrapper {map(str, self.objs)!r}>"
  520. @implementer(IAlias)
  521. class AliasGroup(AliasBase):
  522. """
  523. An alias which points to multiple destination aliases.
  524. @type processAliasFactory: no-argument callable which returns
  525. L{ProcessAlias}
  526. @ivar processAliasFactory: A factory for process aliases.
  527. @type aliases: L{list} of L{AliasBase} which implements L{IAlias}
  528. @ivar aliases: The destination aliases.
  529. """
  530. processAliasFactory = ProcessAlias
  531. def __init__(self, items, *args):
  532. """
  533. Create a group of aliases.
  534. Parse a list of alias strings and, for each, create an appropriate
  535. alias object.
  536. @type items: L{list} of L{bytes}
  537. @param items: Aliases.
  538. @type args: n-L{tuple} of (0) L{dict} mapping L{bytes} to L{IDomain}
  539. provider, (1) L{bytes}
  540. @param args: Arguments for L{AliasBase.__init__}.
  541. """
  542. AliasBase.__init__(self, *args)
  543. self.aliases = []
  544. while items:
  545. addr = items.pop().strip()
  546. if addr.startswith(":"):
  547. try:
  548. f = open(addr[1:])
  549. except BaseException:
  550. log.err(f"Invalid filename in alias file {addr[1:]!r}")
  551. else:
  552. with f:
  553. addr = " ".join([l.strip() for l in f])
  554. items.extend(addr.split(","))
  555. elif addr.startswith("|"):
  556. self.aliases.append(self.processAliasFactory(addr[1:], *args))
  557. elif addr.startswith("/"):
  558. if os.path.isdir(addr):
  559. log.err("Directory delivery not supported")
  560. else:
  561. self.aliases.append(FileAlias(addr, *args))
  562. else:
  563. self.aliases.append(AddressAlias(addr, *args))
  564. def __len__(self):
  565. """
  566. Return the number of aliases in the group.
  567. @rtype: L{int}
  568. @return: The number of aliases in the group.
  569. """
  570. return len(self.aliases)
  571. def __str__(self) -> str:
  572. """
  573. Build a string representation of this L{AliasGroup} instance.
  574. @rtype: L{bytes}
  575. @return: A string containing the aliases in the group.
  576. """
  577. return "<AliasGroup [%s]>" % (", ".join(map(str, self.aliases)))
  578. def createMessageReceiver(self):
  579. """
  580. Create a message receiver for each alias and return a message receiver
  581. which will pass on a message to each of those.
  582. @rtype: L{MultiWrapper}
  583. @return: A message receiver which passes a message on to message
  584. receivers for each alias in the group.
  585. """
  586. return MultiWrapper([a.createMessageReceiver() for a in self.aliases])
  587. def resolve(self, aliasmap, memo=None):
  588. """
  589. Map each of the aliases in the group to its ultimate destination.
  590. @type aliasmap: L{dict} mapping L{bytes} to L{AliasBase}
  591. @param aliasmap: A mapping of username to alias or group of aliases.
  592. @type memo: L{None} or L{dict} of L{AliasBase}
  593. @param memo: A record of the aliases already considered in the
  594. resolution process. If provided, C{memo} is modified to include
  595. this alias.
  596. @rtype: L{MultiWrapper}
  597. @return: A message receiver which passes the message on to message
  598. receivers for the ultimate destination of each alias in the group.
  599. """
  600. if memo is None:
  601. memo = {}
  602. r = []
  603. for a in self.aliases:
  604. r.append(a.resolve(aliasmap, memo))
  605. return MultiWrapper(filter(None, r))