Fill up the include_dict with new includes found from the file. Args: filename: the name of the header to read. include_dict: a dictionary in which the headers are inserted. io: The io factory to use to read the file. Provided for testability. Returns: True if a header was succ
(filename, include_dict, io=codecs)
| 6026 | |
| 6027 | |
| 6028 | def UpdateIncludeState(filename, include_dict, io=codecs): |
| 6029 | """Fill up the include_dict with new includes found from the file. |
| 6030 | |
| 6031 | Args: |
| 6032 | filename: the name of the header to read. |
| 6033 | include_dict: a dictionary in which the headers are inserted. |
| 6034 | io: The io factory to use to read the file. Provided for testability. |
| 6035 | |
| 6036 | Returns: |
| 6037 | True if a header was successfully added. False otherwise. |
| 6038 | """ |
| 6039 | headerfile = None |
| 6040 | try: |
| 6041 | with io.open(filename, 'r', 'utf8', 'replace') as headerfile: |
| 6042 | linenum = 0 |
| 6043 | for line in headerfile: |
| 6044 | linenum += 1 |
| 6045 | clean_line = CleanseComments(line) |
| 6046 | match = _RE_PATTERN_INCLUDE.search(clean_line) |
| 6047 | if match: |
| 6048 | include = match.group(2) |
| 6049 | include_dict.setdefault(include, linenum) |
| 6050 | return True |
| 6051 | except IOError: |
| 6052 | return False |
| 6053 | |
| 6054 | |
| 6055 |
no test coverage detected