本文整理汇总了Python中topaz.error.error_for_oserror函数的典型用法代码示例。如果您正苦于以下问题:Python error_for_oserror函数的具体用法?Python error_for_oserror怎么用?Python error_for_oserror使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了error_for_oserror函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: method_kill
def method_kill(self, space, w_signal, args_w):
if not args_w:
raise space.error(space.w_ArgumentError,
"wrong number of arguments (%d for at least 2)" % (len(args_w) + 1)
)
if space.is_kind_of(w_signal, space.w_fixnum):
sig = space.int_w(w_signal)
else:
s = Coerce.str(space, w_signal)
if s.startswith("SIG"):
s = s[len("SIG"):]
try:
sig = SIGNALS[s]
except KeyError:
raise space.error(space.w_ArgumentError,
"unsupported name `SIG%s'" % s
)
if sig < 0:
for w_arg in args_w:
pid = Coerce.int(space, w_arg)
try:
killpg(pid, -sig)
except OSError as e:
raise error_for_oserror(space, e)
else:
for w_arg in args_w:
pid = Coerce.int(space, w_arg)
try:
kill(pid, sig)
except OSError as e:
raise error_for_oserror(space, e)
return space.newint(len(args_w))
开发者ID:babelsberg,项目名称:babelsberg-r,代码行数:33,代码来源:process.py
示例2: method_exec
def method_exec(self, space, args_w):
if len(args_w) > 1 and space.respond_to(args_w[0], "to_hash"):
raise space.error(space.w_NotImplementedError, "exec with environment")
if len(args_w) > 1 and space.respond_to(args_w[-1], "to_hash"):
raise space.error(space.w_NotImplementedError, "exec with options")
if space.respond_to(args_w[0], "to_ary"):
w_cmd = space.convert_type(args_w[0], space.w_array, "to_ary")
cmd_w = space.listview(w_cmd)
if len(cmd_w) != 2:
raise space.error(space.w_ArgumentError, "wrong first argument")
cmd, argv0 = [
space.str0_w(space.convert_type(
w_e, space.w_string, "to_str"
)) for w_e in cmd_w
]
else:
w_cmd = space.convert_type(args_w[0], space.w_string, "to_str")
cmd = space.str0_w(w_cmd)
argv0 = None
if len(args_w) > 1 or argv0 is not None:
if argv0 is None:
sepidx = cmd.rfind(os.sep) + 1
if sepidx > 0:
argv0 = cmd[sepidx:]
else:
argv0 = cmd
args = [argv0]
args += [
space.str0_w(space.convert_type(
w_arg, space.w_string, "to_str"
)) for w_arg in args_w[1:]
]
try:
os.execv(cmd, args)
except OSError as e:
raise error_for_oserror(space, e)
else:
if not cmd:
raise error_for_errno(space, errno.ENOENT)
shell = os.environ.get("RUBYSHELL") or os.environ.get("COMSPEC") or "/bin/sh"
sepidx = shell.rfind(os.sep) + 1
if sepidx > 0:
argv0 = shell[sepidx:]
else:
argv0 = shell
try:
os.execv(shell, [argv0, "-c", cmd])
except OSError as e:
raise error_for_oserror(space, e)
开发者ID:Fleurer,项目名称:topaz,代码行数:52,代码来源:kernel.py
示例3: method_initialize
def method_initialize(self, space, path):
self.path = path
try:
self.dirp = opendir(path)
except OSError as e:
raise error_for_oserror(space, e)
self.open = True
开发者ID:evansd,项目名称:topaz,代码行数:7,代码来源:dirobject.py
示例4: method_truncate
def method_truncate(self, space, length):
self.ensure_not_closed(space)
try:
ftruncate(self.fd, length)
except OSError as e:
raise error_for_oserror(space, e)
return space.newint(0)
开发者ID:topazproject,项目名称:topaz,代码行数:7,代码来源:fileobject.py
示例5: method_read
def method_read(self, space, w_length=None, w_str=None):
self.ensure_not_closed(space)
if w_length:
length = space.int_w(w_length)
if length < 0:
raise space.error(space.w_ArgumentError,
"negative length %d given" % length
)
else:
length = -1
read_bytes = 0
read_chunks = []
while length < 0 or read_bytes < length:
if length > 0:
max_read = int(length - read_bytes)
else:
max_read = 8192
try:
current_read = os.read(self.fd, max_read)
except OSError as e:
raise error_for_oserror(space, e)
if len(current_read) == 0:
break
read_bytes += len(current_read)
read_chunks += current_read
# Return nil on EOF if length is given
if read_bytes == 0:
return space.w_nil
w_read_str = space.newstr_fromchars(read_chunks)
if w_str is not None:
w_str.clear(space)
w_str.extend(space, w_read_str)
return w_str
else:
return w_read_str
开发者ID:jeffhsu3,项目名称:topaz,代码行数:35,代码来源:ioobject.py
示例6: method_write
def method_write(self, space, w_str):
self.ensure_not_closed(space)
string = space.str_w(space.send(w_str, "to_s"))
try:
bytes_written = os.write(self.fd, string)
except OSError as e:
raise error_for_oserror(space, e)
return space.newint(bytes_written)
开发者ID:jeffhsu3,项目名称:topaz,代码行数:8,代码来源:ioobject.py
示例7: singleton_method_chmod
def singleton_method_chmod(self, space, mode, args_w):
for arg_w in args_w:
path = Coerce.path(space, arg_w)
try:
os.chmod(path, mode)
except OSError as e:
raise error_for_oserror(space, e)
return space.newint(len(args_w))
开发者ID:topazproject,项目名称:topaz,代码行数:8,代码来源:fileobject.py
示例8: singleton_method_lstat
def singleton_method_lstat(self, space, filename):
try:
stat_val = os.lstat(filename)
except OSError as e:
raise error_for_oserror(space, e)
stat_obj = W_FileStatObject(space)
stat_obj.set_stat(stat_val)
return stat_obj
开发者ID:topazproject,项目名称:topaz,代码行数:8,代码来源:fileobject.py
示例9: singleton_method_delete
def singleton_method_delete(self, space, args_w):
for w_path in args_w:
path = Coerce.path(space, w_path)
try:
os.unlink(path)
except OSError as e:
raise error_for_oserror(space, e)
return space.newint(len(args_w))
开发者ID:topazproject,项目名称:topaz,代码行数:8,代码来源:fileobject.py
示例10: method_stat
def method_stat(self, space):
try:
stat_val = os.fstat(self.fd)
except OSError as e:
raise error_for_oserror(space, e)
stat_obj = W_FileStatObject(space)
stat_obj.set_stat(stat_val)
return stat_obj
开发者ID:jstepien,项目名称:topaz,代码行数:8,代码来源:fileobject.py
示例11: method_chdir
def method_chdir(self, space, path=None, block=None):
if path is None:
path = os.environ["HOME"]
current_dir = os.getcwd()
try:
os.chdir(path)
except OSError as e:
raise error_for_oserror(space, e)
if block is not None:
try:
return space.invoke_block(block, [space.newstr_fromstr(path)])
finally:
try:
os.chdir(current_dir)
except OSError as e:
raise error_for_oserror(space, e)
else:
return space.newint(0)
开发者ID:flaper87,项目名称:topaz,代码行数:18,代码来源:dirobject.py
示例12: method_getc
def method_getc(self, space):
self.ensure_not_closed(space)
try:
c = os.read(self.fd, 1)
except OSError as e:
raise error_for_oserror(space, e)
if not c:
return space.w_nil
return space.newstr_fromstr(c)
开发者ID:jeffhsu3,项目名称:topaz,代码行数:9,代码来源:ioobject.py
示例13: method_clock_gettime
def method_clock_gettime(self, space, clockid, args_w):
if len(args_w) > 1:
raise space.error(space.w_ArgumentError,
"wrong number of arguments (given %d, expected 1..2)"
)
if len(args_w) == 1:
unit = Coerce.symbol(space, args_w[0])
else:
unit = "float_second"
if rtime.HAS_CLOCK_GETTIME:
with lltype.scoped_alloc(rtime.TIMESPEC) as a:
if rtime.c_clock_gettime(clockid, a) == 0:
sec = rffi.getintfield(a, 'c_tv_sec')
nsec = rffi.getintfield(a, 'c_tv_nsec')
else:
raise error_for_oserror(space, OSError(
errno.EINVAL, "clock_gettime")
)
elif clockid == CLOCK_PROCESS_CPUTIME_ID:
r = rtime.clock()
sec = int(r)
nsec = r * 1000000000
else:
raise error_for_oserror(space, OSError(
errno.EINVAL, "clock_gettime")
)
if unit == "float_second":
return space.newfloat(sec + nsec * 0.000000001)
elif unit == "float_millisecond":
return space.newfloat(sec * 1000 + nsec * 0.000001)
elif unit == "float_microsecond":
return space.newfloat(sec * 1000000 + nsec * 0.001)
elif unit == "second":
return space.newint(int(sec))
elif unit == "millisecond":
return space.newint(int(sec) * 1000)
elif unit == "microsecond":
return space.newint(sec * 1000000)
elif unit == "nanosecond":
return space.newint(sec * 1000000000 + int(nsec))
else:
raise space.error(space.w_ArgumentError,
"unexpected unit: %s" % unit
)
开发者ID:topazproject,项目名称:topaz,代码行数:44,代码来源:process.py
示例14: method_read
def method_read(self, space, args_w):
self.ensure_open(space)
try:
filename = readdir(self.dirp)
except OSError as e:
raise error_for_oserror(space, e)
if filename is None:
return space.w_nil
else:
return space.newstr_fromstr(filename)
开发者ID:evansd,项目名称:topaz,代码行数:10,代码来源:dirobject.py
示例15: method_waitpid
def method_waitpid(self, space, pid=-1):
try:
pid, status = os.waitpid(pid, 0)
except OSError as e:
raise error_for_oserror(space, e)
status = WEXITSTATUS(status)
w_status = space.send(
space.find_const(self, "Status"),
"new",
[space.newint(pid), space.newint(status)]
)
space.globals.set(space, "$?", w_status)
return space.newint(pid)
开发者ID:babelsberg,项目名称:babelsberg-r,代码行数:13,代码来源:process.py
示例16: method_sysopen
def method_sysopen(self, space, w_path, w_mode_str_or_int=None, w_perm=None):
perm = 0666
mode = os.O_RDONLY
if w_mode_str_or_int is not None:
mode = map_filemode(space, w_mode_str_or_int)
if w_perm is not None and w_perm is not space.w_nil:
perm = space.int_w(w_perm)
path = Coerce.path(space, w_path)
try:
fd = os.open(path, mode, perm)
except OSError as e:
raise error_for_oserror(space, e)
else:
return space.newint(fd)
开发者ID:jeffhsu3,项目名称:topaz,代码行数:14,代码来源:ioobject.py
示例17: load_feature
def load_feature(space, path, orig_path):
if not os.path.exists(path):
raise space.error(space.w_LoadError, orig_path)
try:
f = open_file_as_stream(path, buffering=0)
try:
contents = f.readall()
finally:
f.close()
except OSError as e:
raise error_for_oserror(space, e)
space.execute(contents, filepath=path)
开发者ID:steveklabnik,项目名称:topaz,代码行数:14,代码来源:kernel.py
示例18: method_tcgetattr
def method_tcgetattr(self, space, fd):
try:
mode = tcgetattr(fd)
except OSError as e:
raise error_for_oserror(space, e)
mode_w = [
space.newint(mode[0]), # iflag
space.newint(mode[1]), # oflag
space.newint(mode[2]), # cflag
space.newint(mode[3]), # lflag
space.newint(mode[4]), # ispeed
space.newint(mode[5]), # ospeed
space.newarray([space.newstr_fromstr(cc) for cc in mode[6]])
]
return space.newarray(mode_w)
开发者ID:topazproject,项目名称:topaz,代码行数:15,代码来源:topaz.py
示例19: method_tcsetattr
def method_tcsetattr(self, space, fd, when, mode_w):
cc = [space.str_w(w_char) for w_char in space.listview(mode_w[6])]
mode = (
space.int_w(mode_w[0]), # iflag
space.int_w(mode_w[1]), # oflag
space.int_w(mode_w[2]), # cflag
space.int_w(mode_w[3]), # lflag
space.int_w(mode_w[4]), # ispeed
space.int_w(mode_w[5]), # ospeed
cc
)
try:
tcsetattr(fd, when, mode)
except OSError as e:
raise error_for_oserror(space, e)
return self
开发者ID:topazproject,项目名称:topaz,代码行数:16,代码来源:topaz.py
示例20: load_feature
def load_feature(space, path, orig_path, wrap=False):
if not os.path.exists(path):
raise space.error(space.w_LoadError, orig_path)
try:
f = open_file_as_stream(path, buffering=0)
try:
contents = f.readall()
finally:
f.close()
except OSError as e:
raise error_for_oserror(space, e)
if wrap:
lexical_scope = StaticScope(space.newmodule("Anonymous"), None)
else:
lexical_scope = None
space.execute(contents, filepath=path, lexical_scope=lexical_scope)
开发者ID:topazproject,项目名称:topaz,代码行数:18,代码来源:kernel.py
注:本文中的topaz.error.error_for_oserror函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论