Show More
@@ -1,21 +1,23 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """Being removed |
|
2 | """Being removed | |
3 | """ |
|
3 | """ | |
4 |
|
4 | |||
|
5 | ||||
5 | class LazyEvaluate(object): |
|
6 | class LazyEvaluate(object): | |
6 | """This is used for formatting strings with values that need to be updated |
|
7 | """This is used for formatting strings with values that need to be updated | |
7 | at that time, such as the current time or working directory.""" |
|
8 | at that time, such as the current time or working directory.""" | |
|
9 | ||||
8 | def __init__(self, func, *args, **kwargs): |
|
10 | def __init__(self, func, *args, **kwargs): | |
9 | self.func = func |
|
11 | self.func = func | |
10 | self.args = args |
|
12 | self.args = args | |
11 | self.kwargs = kwargs |
|
13 | self.kwargs = kwargs | |
12 |
|
14 | |||
13 | def __call__(self, **kwargs): |
|
15 | def __call__(self, **kwargs): | |
14 | self.kwargs.update(kwargs) |
|
16 | self.kwargs.update(kwargs) | |
15 | return self.func(*self.args, **self.kwargs) |
|
17 | return self.func(*self.args, **self.kwargs) | |
16 |
|
18 | |||
17 | def __str__(self): |
|
19 | def __str__(self): | |
18 | return str(self()) |
|
20 | return str(self()) | |
19 |
|
21 | |||
20 | def __format__(self, format_spec): |
|
22 | def __format__(self, format_spec): | |
21 | return format(self(), format_spec) |
|
23 | return format(self(), format_spec) |
@@ -1,4 +1,4 b'' | |||||
1 | # coding: iso-8859-5 |
|
1 | # coding: iso-8859-5 | |
2 | # (Unlikely to be the default encoding for most testers.) |
|
2 | # (Unlikely to be the default encoding for most testers.) | |
3 | # ΠΠΡΡΡΡΡΡΡ ΡΡΡΡΡΡΡΡΡΡ <- Cyrillic characters |
|
3 | # ΠΠΡΡΡΡΡΡΡ ΡΡΡΡΡΡΡΡΡΡ <- Cyrillic characters | |
4 |
|
|
4 | "ΠΡβΠ€" |
@@ -1,11 +1,11 b'' | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | """ |
|
2 | """ | |
3 | Extra capabilities for IPython |
|
3 | Extra capabilities for IPython | |
4 | """ |
|
4 | """ | |
5 |
|
5 | |||
6 | #----------------------------------------------------------------------------- |
|
6 | # ----------------------------------------------------------------------------- | |
7 | # Copyright (C) 2008-2011 The IPython Development Team |
|
7 | # Copyright (C) 2008-2011 The IPython Development Team | |
8 | # |
|
8 | # | |
9 | # Distributed under the terms of the BSD License. The full license is in |
|
9 | # Distributed under the terms of the BSD License. The full license is in | |
10 | # the file COPYING, distributed as part of this software. |
|
10 | # the file COPYING, distributed as part of this software. | |
11 | #----------------------------------------------------------------------------- |
|
11 | # ----------------------------------------------------------------------------- |
@@ -1,10 +1,10 b'' | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | __docformat__ = "restructuredtext en" |
|
2 | __docformat__ = "restructuredtext en" | |
3 | #------------------------------------------------------------------------------- |
|
3 | # ------------------------------------------------------------------------------- | |
4 | # Copyright (C) 2005 Fernando Perez <fperez@colorado.edu> |
|
4 | # Copyright (C) 2005 Fernando Perez <fperez@colorado.edu> | |
5 | # Brian E Granger <ellisonbg@gmail.com> |
|
5 | # Brian E Granger <ellisonbg@gmail.com> | |
6 | # Benjamin Ragan-Kelley <benjaminrk@gmail.com> |
|
6 | # Benjamin Ragan-Kelley <benjaminrk@gmail.com> | |
7 | # |
|
7 | # | |
8 | # Distributed under the terms of the BSD License. The full license is in |
|
8 | # Distributed under the terms of the BSD License. The full license is in | |
9 | # the file COPYING, distributed as part of this software. |
|
9 | # the file COPYING, distributed as part of this software. | |
10 | #------------------------------------------------------------------------------- |
|
10 | # ------------------------------------------------------------------------------- |
@@ -1,69 +1,71 b'' | |||||
1 | """cli-specific implementation of process utilities. |
|
1 | """cli-specific implementation of process utilities. | |
2 |
|
2 | |||
3 | cli - Common Language Infrastructure for IronPython. Code |
|
3 | cli - Common Language Infrastructure for IronPython. Code | |
4 | can run on any operating system. Check os.name for os- |
|
4 | can run on any operating system. Check os.name for os- | |
5 | specific settings. |
|
5 | specific settings. | |
6 |
|
6 | |||
7 | This file is only meant to be imported by process.py, not by end-users. |
|
7 | This file is only meant to be imported by process.py, not by end-users. | |
8 |
|
8 | |||
9 | This file is largely untested. To become a full drop-in process |
|
9 | This file is largely untested. To become a full drop-in process | |
10 | interface for IronPython will probably require you to help fill |
|
10 | interface for IronPython will probably require you to help fill | |
11 | in the details. |
|
11 | in the details. | |
12 | """ |
|
12 | """ | |
13 |
|
13 | |||
14 | # Import cli libraries: |
|
14 | # Import cli libraries: | |
15 | import clr |
|
15 | import clr | |
16 | import System |
|
16 | import System | |
17 |
|
17 | |||
18 | # Import Python libraries: |
|
18 | # Import Python libraries: | |
19 | import os |
|
19 | import os | |
20 |
|
20 | |||
21 | # Import IPython libraries: |
|
21 | # Import IPython libraries: | |
22 | from ._process_common import arg_split |
|
22 | from ._process_common import arg_split | |
23 |
|
23 | |||
24 |
|
24 | |||
25 | def system(cmd): |
|
25 | def system(cmd): | |
26 | """ |
|
26 | """ | |
27 | system(cmd) should work in a cli environment on Mac OSX, Linux, |
|
27 | system(cmd) should work in a cli environment on Mac OSX, Linux, | |
28 | and Windows |
|
28 | and Windows | |
29 | """ |
|
29 | """ | |
30 | psi = System.Diagnostics.ProcessStartInfo(cmd) |
|
30 | psi = System.Diagnostics.ProcessStartInfo(cmd) | |
31 | psi.RedirectStandardOutput = True |
|
31 | psi.RedirectStandardOutput = True | |
32 | psi.RedirectStandardError = True |
|
32 | psi.RedirectStandardError = True | |
33 | psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal |
|
33 | psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal | |
34 | psi.UseShellExecute = False |
|
34 | psi.UseShellExecute = False | |
35 | # Start up process: |
|
35 | # Start up process: | |
36 | reg = System.Diagnostics.Process.Start(psi) |
|
36 | reg = System.Diagnostics.Process.Start(psi) | |
37 |
|
37 | |||
|
38 | ||||
38 | def getoutput(cmd): |
|
39 | def getoutput(cmd): | |
39 | """ |
|
40 | """ | |
40 | getoutput(cmd) should work in a cli environment on Mac OSX, Linux, |
|
41 | getoutput(cmd) should work in a cli environment on Mac OSX, Linux, | |
41 | and Windows |
|
42 | and Windows | |
42 | """ |
|
43 | """ | |
43 | psi = System.Diagnostics.ProcessStartInfo(cmd) |
|
44 | psi = System.Diagnostics.ProcessStartInfo(cmd) | |
44 | psi.RedirectStandardOutput = True |
|
45 | psi.RedirectStandardOutput = True | |
45 | psi.RedirectStandardError = True |
|
46 | psi.RedirectStandardError = True | |
46 | psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal |
|
47 | psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal | |
47 | psi.UseShellExecute = False |
|
48 | psi.UseShellExecute = False | |
48 | # Start up process: |
|
49 | # Start up process: | |
49 | reg = System.Diagnostics.Process.Start(psi) |
|
50 | reg = System.Diagnostics.Process.Start(psi) | |
50 | myOutput = reg.StandardOutput |
|
51 | myOutput = reg.StandardOutput | |
51 | output = myOutput.ReadToEnd() |
|
52 | output = myOutput.ReadToEnd() | |
52 | myError = reg.StandardError |
|
53 | myError = reg.StandardError | |
53 | error = myError.ReadToEnd() |
|
54 | error = myError.ReadToEnd() | |
54 | return output |
|
55 | return output | |
55 |
|
56 | |||
|
57 | ||||
56 | def check_pid(pid): |
|
58 | def check_pid(pid): | |
57 | """ |
|
59 | """ | |
58 | Check if a process with the given PID (pid) exists |
|
60 | Check if a process with the given PID (pid) exists | |
59 | """ |
|
61 | """ | |
60 | try: |
|
62 | try: | |
61 | System.Diagnostics.Process.GetProcessById(pid) |
|
63 | System.Diagnostics.Process.GetProcessById(pid) | |
62 | # process with given pid is running |
|
64 | # process with given pid is running | |
63 | return True |
|
65 | return True | |
64 | except System.InvalidOperationException: |
|
66 | except System.InvalidOperationException: | |
65 | # process wasn't started by this object (but is running) |
|
67 | # process wasn't started by this object (but is running) | |
66 | return True |
|
68 | return True | |
67 | except System.ArgumentException: |
|
69 | except System.ArgumentException: | |
68 | # process with given pid isn't running |
|
70 | # process with given pid isn't running | |
69 |
return False |
|
71 | return False |
@@ -1,84 +1,84 b'' | |||||
1 | # encoding: utf-8 |
|
1 | # encoding: utf-8 | |
2 | """A fancy version of Python's builtin :func:`dir` function. |
|
2 | """A fancy version of Python's builtin :func:`dir` function. | |
3 | """ |
|
3 | """ | |
4 |
|
4 | |||
5 | # Copyright (c) IPython Development Team. |
|
5 | # Copyright (c) IPython Development Team. | |
6 | # Distributed under the terms of the Modified BSD License. |
|
6 | # Distributed under the terms of the Modified BSD License. | |
7 |
|
7 | |||
8 | import inspect |
|
8 | import inspect | |
9 | import types |
|
9 | import types | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | def safe_hasattr(obj, attr): |
|
12 | def safe_hasattr(obj, attr): | |
13 | """In recent versions of Python, hasattr() only catches AttributeError. |
|
13 | """In recent versions of Python, hasattr() only catches AttributeError. | |
14 | This catches all errors. |
|
14 | This catches all errors. | |
15 | """ |
|
15 | """ | |
16 | try: |
|
16 | try: | |
17 | getattr(obj, attr) |
|
17 | getattr(obj, attr) | |
18 | return True |
|
18 | return True | |
19 | except: |
|
19 | except: | |
20 | return False |
|
20 | return False | |
21 |
|
21 | |||
22 |
|
22 | |||
23 | def dir2(obj): |
|
23 | def dir2(obj): | |
24 | """dir2(obj) -> list of strings |
|
24 | """dir2(obj) -> list of strings | |
25 |
|
25 | |||
26 | Extended version of the Python builtin dir(), which does a few extra |
|
26 | Extended version of the Python builtin dir(), which does a few extra | |
27 | checks. |
|
27 | checks. | |
28 |
|
28 | |||
29 | This version is guaranteed to return only a list of true strings, whereas |
|
29 | This version is guaranteed to return only a list of true strings, whereas | |
30 | dir() returns anything that objects inject into themselves, even if they |
|
30 | dir() returns anything that objects inject into themselves, even if they | |
31 | are later not really valid for attribute access (many extension libraries |
|
31 | are later not really valid for attribute access (many extension libraries | |
32 | have such bugs). |
|
32 | have such bugs). | |
33 | """ |
|
33 | """ | |
34 |
|
34 | |||
35 | # Start building the attribute list via dir(), and then complete it |
|
35 | # Start building the attribute list via dir(), and then complete it | |
36 | # with a few extra special-purpose calls. |
|
36 | # with a few extra special-purpose calls. | |
37 |
|
37 | |||
38 | try: |
|
38 | try: | |
39 | words = set(dir(obj)) |
|
39 | words = set(dir(obj)) | |
40 | except Exception: |
|
40 | except Exception: | |
41 | # TypeError: dir(obj) does not return a list |
|
41 | # TypeError: dir(obj) does not return a list | |
42 | words = set() |
|
42 | words = set() | |
43 |
|
43 | |||
44 |
if safe_hasattr(obj, |
|
44 | if safe_hasattr(obj, "__class__"): | |
45 | words |= set(dir(obj.__class__)) |
|
45 | words |= set(dir(obj.__class__)) | |
46 |
|
46 | |||
47 | # filter out non-string attributes which may be stuffed by dir() calls |
|
47 | # filter out non-string attributes which may be stuffed by dir() calls | |
48 | # and poor coding in third-party modules |
|
48 | # and poor coding in third-party modules | |
49 |
|
49 | |||
50 | words = [w for w in words if isinstance(w, str)] |
|
50 | words = [w for w in words if isinstance(w, str)] | |
51 | return sorted(words) |
|
51 | return sorted(words) | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | def get_real_method(obj, name): |
|
54 | def get_real_method(obj, name): | |
55 | """Like getattr, but with a few extra sanity checks: |
|
55 | """Like getattr, but with a few extra sanity checks: | |
56 |
|
56 | |||
57 | - If obj is a class, ignore everything except class methods |
|
57 | - If obj is a class, ignore everything except class methods | |
58 | - Check if obj is a proxy that claims to have all attributes |
|
58 | - Check if obj is a proxy that claims to have all attributes | |
59 | - Catch attribute access failing with any exception |
|
59 | - Catch attribute access failing with any exception | |
60 | - Check that the attribute is a callable object |
|
60 | - Check that the attribute is a callable object | |
61 |
|
61 | |||
62 | Returns the method or None. |
|
62 | Returns the method or None. | |
63 | """ |
|
63 | """ | |
64 | try: |
|
64 | try: | |
65 |
canary = getattr(obj, |
|
65 | canary = getattr(obj, "_ipython_canary_method_should_not_exist_", None) | |
66 | except Exception: |
|
66 | except Exception: | |
67 | return None |
|
67 | return None | |
68 |
|
68 | |||
69 | if canary is not None: |
|
69 | if canary is not None: | |
70 | # It claimed to have an attribute it should never have |
|
70 | # It claimed to have an attribute it should never have | |
71 | return None |
|
71 | return None | |
72 |
|
72 | |||
73 | try: |
|
73 | try: | |
74 | m = getattr(obj, name, None) |
|
74 | m = getattr(obj, name, None) | |
75 | except Exception: |
|
75 | except Exception: | |
76 | return None |
|
76 | return None | |
77 |
|
77 | |||
78 | if inspect.isclass(obj) and not isinstance(m, types.MethodType): |
|
78 | if inspect.isclass(obj) and not isinstance(m, types.MethodType): | |
79 | return None |
|
79 | return None | |
80 |
|
80 | |||
81 | if callable(m): |
|
81 | if callable(m): | |
82 | return m |
|
82 | return m | |
83 |
|
83 | |||
84 | return None |
|
84 | return None |
General Comments 0
You need to be logged in to leave comments.
Login now