diff --git a/trac/util/text.py b/trac/util/text.py
|
a
|
b
|
|
| 76 | 76 | message = '\n%s\n%s' % (to_unicode('\n'.join(traceback_only)), message) |
| 77 | 77 | return message |
| 78 | 78 | |
| | 79 | def path_to_unicode(path): |
| | 80 | """Convert a filesystem path to unicode, using the filesystem encoding.""" |
| | 81 | if isinstance(path, str): |
| | 82 | try: |
| | 83 | return unicode(text, sys.getfilesystemencoding()) |
| | 84 | except UnicodeDecodeError: |
| | 85 | return unicode(path, 'latin1') |
| | 86 | return unicode(path) |
| | 87 | |
| 79 | 88 | _js_quote = {'\\': '\\\\', '"': '\\"', '\b': '\\b', '\f': '\\f', |
| 80 | 89 | '\n': '\\n', '\r': '\\r', '\t': '\\t', "'": "\\'"} |
| 81 | 90 | for i in range(0x20) + [ord(c) for c in '&<>']: |
diff --git a/trac/wiki/admin.py b/trac/wiki/admin.py
|
a
|
b
|
|
| 24 | 24 | from trac.util.compat import any |
| 25 | 25 | from trac.util.datefmt import format_datetime, from_utimestamp, \ |
| 26 | 26 | to_utimestamp, utc |
| 27 | | from trac.util.text import to_unicode, unicode_quote, unicode_unquote, \ |
| 28 | | print_table, printout |
| | 27 | from trac.util.text import path_to_unicode, print_table, printout, \ |
| | 28 | to_unicode, unicode_quote, unicode_unquote |
| 29 | 29 | from trac.util.translation import _ |
| 30 | 30 | |
| 31 | 31 | |
| … |
… |
|
| 102 | 102 | else: |
| 103 | 103 | if os.path.isfile(filename): |
| 104 | 104 | raise AdminCommandError(_("File '%(name)s' exists", |
| 105 | | name=filename)) |
| | 105 | name=path_to_unicode(filename))) |
| 106 | 106 | f = open(filename, 'w') |
| 107 | 107 | try: |
| 108 | 108 | f.write(text.encode('utf-8')) |
| … |
… |
|
| 114 | 114 | if filename: |
| 115 | 115 | if not os.path.isfile(filename): |
| 116 | 116 | raise AdminCommandError(_("'%(name)s' is not a file", |
| 117 | | name=filename)) |
| | 117 | name=path_to_unicode(filename))) |
| 118 | 118 | data = read_file(filename) |
| 119 | 119 | else: |
| 120 | 120 | data = sys.stdin.read() |
| … |
… |
|
| 166 | 166 | if os.path.isfile(filename): |
| 167 | 167 | if self.import_page(filename, page, create_only, replace): |
| 168 | 168 | printout(_(" %(page)s imported from %(filename)s", |
| 169 | | filename=filename, page=page)) |
| | 169 | filename=path_to_unicode(filename), |
| | 170 | page=page)) |
| 170 | 171 | |
| 171 | 172 | def _complete_page(self, args): |
| 172 | 173 | if len(args) == 1: |
| … |
… |
|
| 241 | 242 | os.mkdir(directory) |
| 242 | 243 | else: |
| 243 | 244 | raise AdminCommandError(_("'%(name)s' is not a directory", |
| 244 | | name=directory)) |
| | 245 | name=path_to_unicode(directory))) |
| 245 | 246 | db = self.env.get_db_cnx() |
| 246 | 247 | cursor = db.cursor() |
| 247 | 248 | for p in pages: |
| … |
… |
|
| 263 | 264 | page = unicode_unquote(page.encode('utf-8')) |
| 264 | 265 | if self.import_page(path, page, replace=replace): |
| 265 | 266 | printout(_(" %(page)s imported from %(filename)s", |
| 266 | | filename=path, page=page)) |
| | 267 | filename=path_to_unicode(path), page=page)) |
| 267 | 268 | |
| 268 | 269 | def _do_load(self, *paths): |
| 269 | 270 | self._load_or_replace(paths, replace=False) |