alias.py 24 KB

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