本文整理汇总了Python中setuptools.compat.builtins.open方法的典型用法代码示例。如果您正苦于以下问题:Python builtins.open方法的具体用法?Python builtins.open怎么用?Python builtins.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类setuptools.compat.builtins
的用法示例。
在下文中一共展示了builtins.open方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from setuptools.compat import builtins [as 别名]
# 或者: from setuptools.compat.builtins import open [as 别名]
def run(self, func):
"""Run 'func' under os sandboxing"""
try:
self._copy(self)
if _file:
builtins.file = self._file
builtins.open = self._open
self._active = True
return func()
finally:
self._active = False
if _file:
builtins.file = _file
builtins.open = _open
self._copy(_os)
示例2: _open
# 需要导入模块: from setuptools.compat import builtins [as 别名]
# 或者: from setuptools.compat.builtins import open [as 别名]
def _open(self, path, mode='r', *args, **kw):
if mode not in ('r', 'rt', 'rb', 'rU', 'U') and not self._ok(path):
self._violation("open", path, mode, *args, **kw)
return _open(path,mode,*args,**kw)
示例3: open
# 需要导入模块: from setuptools.compat import builtins [as 别名]
# 或者: from setuptools.compat.builtins import open [as 别名]
def open(self, file, flags, mode=0x1FF, *args, **kw): # 0777
"""Called for low-level os.open()"""
if flags & WRITE_FLAGS and not self._ok(file):
self._violation("os.open", file, flags, mode, *args, **kw)
return _os.open(file,flags,mode, *args, **kw)
示例4: _execfile
# 需要导入模块: from setuptools.compat import builtins [as 别名]
# 或者: from setuptools.compat.builtins import open [as 别名]
def _execfile(filename, globals, locals=None):
"""
Python 3 implementation of execfile.
"""
mode = 'rb'
with open(filename, mode) as stream:
script = stream.read()
# compile() function in Python 2.6 and 3.1 requires LF line endings.
if sys.version_info[:2] < (2, 7) or sys.version_info[:2] >= (3, 0) and sys.version_info[:2] < (3, 2):
script = script.replace(b'\r\n', b'\n')
script = script.replace(b'\r', b'\n')
if locals is None:
locals = globals
code = compile(script, filename, 'exec')
exec(code, globals, locals)
示例5: open
# 需要导入模块: from setuptools.compat import builtins [as 别名]
# 或者: from setuptools.compat.builtins import open [as 别名]
def open(self, file, flags, mode=0o777, *args, **kw):
"""Called for low-level os.open()"""
if flags & WRITE_FLAGS and not self._ok(file):
self._violation("os.open", file, flags, mode, *args, **kw)
return _os.open(file,flags,mode, *args, **kw)