fix_buffer.py 590 B

12345678910111213141516171819202122
  1. # Copyright 2007 Google, Inc. All Rights Reserved.
  2. # Licensed to PSF under a Contributor Agreement.
  3. """Fixer that changes buffer(...) into memoryview(...)."""
  4. # Local imports
  5. from .. import fixer_base
  6. from ..fixer_util import Name
  7. class FixBuffer(fixer_base.BaseFix):
  8. BM_compatible = True
  9. explicit = True # The user must ask for this fixer
  10. PATTERN = """
  11. power< name='buffer' trailer< '(' [any] ')' > any* >
  12. """
  13. def transform(self, node, results):
  14. name = results["name"]
  15. name.replace(Name("memoryview", prefix=name.prefix))