A single line of input and associated info. Includes the following as properties: line The original, raw line continue_prompt Is this line a continuation in a sequence of multiline input? pre Any leading whitespace. esc The escape character(s) in pre
| 79 | |
| 80 | |
| 81 | class LineInfo(object): |
| 82 | """A single line of input and associated info. |
| 83 | |
| 84 | Includes the following as properties: |
| 85 | |
| 86 | line |
| 87 | The original, raw line |
| 88 | |
| 89 | continue_prompt |
| 90 | Is this line a continuation in a sequence of multiline input? |
| 91 | |
| 92 | pre |
| 93 | Any leading whitespace. |
| 94 | |
| 95 | esc |
| 96 | The escape character(s) in pre or the empty string if there isn't one. |
| 97 | Note that '!!' and '??' are possible values for esc. Otherwise it will |
| 98 | always be a single character. |
| 99 | |
| 100 | ifun |
| 101 | The 'function part', which is basically the maximal initial sequence |
| 102 | of valid python identifiers and the '.' character. This is what is |
| 103 | checked for alias and magic transformations, used for auto-calling, |
| 104 | etc. In contrast to Python identifiers, it may start with "%" and contain |
| 105 | "*". |
| 106 | |
| 107 | the_rest |
| 108 | Everything else on the line. |
| 109 | """ |
| 110 | def __init__(self, line, continue_prompt=False): |
| 111 | self.line = line |
| 112 | self.continue_prompt = continue_prompt |
| 113 | self.pre, self.esc, self.ifun, self.the_rest = split_user_input(line) |
| 114 | |
| 115 | self.pre_char = self.pre.strip() |
| 116 | if self.pre_char: |
| 117 | self.pre_whitespace = '' # No whitespace allowed before esc chars |
| 118 | else: |
| 119 | self.pre_whitespace = self.pre |
| 120 | |
| 121 | def ofind(self, ip): |
| 122 | """Do a full, attribute-walking lookup of the ifun in the various |
| 123 | namespaces for the given IPython InteractiveShell instance. |
| 124 | |
| 125 | Return a dict with keys: {found, obj, ospace, ismagic} |
| 126 | |
| 127 | Note: can cause state changes because of calling getattr, but should |
| 128 | only be run if autocall is on and if the line hasn't matched any |
| 129 | other, less dangerous handlers. |
| 130 | |
| 131 | Does cache the results of the call, so can be called multiple times |
| 132 | without worrying about *further* damaging state. |
| 133 | """ |
| 134 | return ip._ofind(self.ifun) |
| 135 | |
| 136 | def __str__(self): |
| 137 | return "LineInfo [%s|%s|%s|%s]" %(self.pre, self.esc, self.ifun, self.the_rest) |
no outgoing calls