@@ -395,6 +395,8 @@ class ParseContext(object):
395
395
396
396
def __init__ (self , filename , template = None ):
397
397
self .filename = os .path .abspath (filename )
398
+ if sys .platform == 'win32' :
399
+ self .filename = self .filename .replace ('\\ ' , '/' )
398
400
if template is None :
399
401
with open (filename ) as f :
400
402
self .template = f .read ()
@@ -573,8 +575,6 @@ def append_text(self, text, file, line):
573
575
# We can only insert the line directive at a line break
574
576
if len (self .result_text ) == 0 \
575
577
or self .result_text [- 1 ].endswith ('\n ' ):
576
- if sys .platform == 'win32' :
577
- file = file .replace ('\\ ' , '/' )
578
578
substitutions = {'file' : file , 'line' : line + 1 }
579
579
format_str = self .line_directive + '\n '
580
580
self .result_text .append (format_str % substitutions )
@@ -779,7 +779,7 @@ def expand(filename, line_directive=_default_line_directive, **local_bindings):
779
779
... 'line: %(line)d)',
780
780
... x=2
781
781
... ).replace(
782
- ... '"%s"' % f.name, '"dummy.file"')
782
+ ... '"%s"' % f.name.replace('\\', '/') , '"dummy.file"')
783
783
>>> print(result, end='')
784
784
//#sourceLocation(file: "dummy.file", line: 1)
785
785
---
@@ -1067,7 +1067,7 @@ def execute_template(
1067
1067
Keyword arguments become local variable bindings in the execution context
1068
1068
1069
1069
>>> root_directory = os.path.abspath('/')
1070
- >>> file_name = root_directory + 'dummy.file'
1070
+ >>> file_name = ( root_directory + 'dummy.file').replace('\\', '/')
1071
1071
>>> ast = parse_template(file_name, text=
1072
1072
... '''Nothing
1073
1073
... % if x:
@@ -1239,7 +1239,7 @@ def succ(a):
1239
1239
1240
1240
Example: `#sourceLocation(file: "%%(file)s", line: %%(line)d)`
1241
1241
1242
- The default works automatically with the `line-directive` tool,
1242
+ The default works automatically with the `line-directive` tool,
1243
1243
which see for more information.
1244
1244
''' )
1245
1245
0 commit comments