Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(44)

Side by Side Diff: Lib/xml/etree/ElementInclude.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/xml/dom/pulldom.py ('k') | Makefile.pre.in » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # 1 #
2 # ElementTree 2 # ElementTree
3 # $Id: ElementInclude.py 3375 2008-02-13 08:05:08Z fredrik $ 3 # $Id: ElementInclude.py 3375 2008-02-13 08:05:08Z fredrik $
4 # 4 #
5 # limited xinclude support for element trees 5 # limited xinclude support for element trees
6 # 6 #
7 # history: 7 # history:
8 # 2003-08-15 fl created 8 # 2003-08-15 fl created
9 # 2003-11-14 fl fixed default loader 9 # 2003-11-14 fl fixed default loader
10 # 10 #
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 # Fatal include error. 60 # Fatal include error.
61 61
62 class FatalIncludeError(SyntaxError): 62 class FatalIncludeError(SyntaxError):
63 pass 63 pass
64 64
65 ## 65 ##
66 # Default loader. This loader reads an included resource from disk. 66 # Default loader. This loader reads an included resource from disk.
67 # 67 #
68 # @param href Resource reference. 68 # @param href Resource reference.
69 # @param parse Parse mode. Either "xml" or "text". 69 # @param parse Parse mode. Either "xml" or "text".
70 # @param encoding Optional text encoding (UTF-8 by default for "text"). 70 # @param encoding Optional text encoding.
71 # @return The expanded resource. If the parse mode is "xml", this 71 # @return The expanded resource. If the parse mode is "xml", this
72 # is an ElementTree instance. If the parse mode is "text", this 72 # is an ElementTree instance. If the parse mode is "text", this
73 # is a Unicode string. If the loader fails, it can return None 73 # is a Unicode string. If the loader fails, it can return None
74 # or raise an IOError exception. 74 # or raise an IOError exception.
75 # @throws IOError If the loader fails to load the resource. 75 # @throws IOError If the loader fails to load the resource.
76 76
77 def default_loader(href, parse, encoding=None): 77 def default_loader(href, parse, encoding=None):
78 file = open(href)
78 if parse == "xml": 79 if parse == "xml":
79 file = open(href, 'rb')
80 data = ElementTree.parse(file).getroot() 80 data = ElementTree.parse(file).getroot()
81 else: 81 else:
82 if not encoding:
83 encoding = 'UTF-8'
84 file = open(href, 'r', encoding=encoding)
85 data = file.read() 82 data = file.read()
83 if encoding:
84 data = data.decode(encoding)
86 file.close() 85 file.close()
87 return data 86 return data
88 87
89 ## 88 ##
90 # Expand XInclude directives. 89 # Expand XInclude directives.
91 # 90 #
92 # @param elem Root element. 91 # @param elem Root element.
93 # @param loader Optional resource loader. If omitted, it defaults 92 # @param loader Optional resource loader. If omitted, it defaults
94 # to {@link default_loader}. If given, it should be a callable 93 # to {@link default_loader}. If given, it should be a callable
95 # that implements the same interface as <b>default_loader</b>. 94 # that implements the same interface as <b>default_loader</b>.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 raise FatalIncludeError( 134 raise FatalIncludeError(
136 "unknown parse type in xi:include tag (%r)" % parse 135 "unknown parse type in xi:include tag (%r)" % parse
137 ) 136 )
138 elif e.tag == XINCLUDE_FALLBACK: 137 elif e.tag == XINCLUDE_FALLBACK:
139 raise FatalIncludeError( 138 raise FatalIncludeError(
140 "xi:fallback tag must be child of xi:include (%r)" % e.tag 139 "xi:fallback tag must be child of xi:include (%r)" % e.tag
141 ) 140 )
142 else: 141 else:
143 include(e, loader) 142 include(e, loader)
144 i = i + 1 143 i = i + 1
OLDNEW
« no previous file with comments | « Lib/xml/dom/pulldom.py ('k') | Makefile.pre.in » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+