2
# -*- coding: utf-8 -*-
4
# Copyright (c) 2013 Will Bond <will@wbond.net>
6
# Permission is hereby granted, free of charge, to any person obtaining a copy
7
# of this software and associated documentation files (the "Software"), to deal
8
# in the Software without restriction, including without limitation the rights
9
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
# copies of the Software, and to permit persons to whom the Software is
11
# furnished to do so, subject to the following conditions:
13
# The above copyright notice and this permission notice shall be included in
14
# all copies or substantial portions of the Software.
16
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
from watchdog.utils import platform
39
fs_encoding = sys.getfilesystemencoding()
40
# This is used by Linux when the locale seems to be improperly set. UTF-8 tends
41
# to be the encoding used by all distros, so this is a good fallback.
42
fs_fallback_encoding = 'utf-8'
46
if isinstance(path, str_cls):
48
path = path.encode(fs_encoding, 'strict')
49
except UnicodeEncodeError:
50
if not platform.is_linux():
52
path = path.encode(fs_fallback_encoding, 'strict')
57
if isinstance(path, bytes_cls):
59
path = path.decode(fs_encoding, 'strict')
60
except UnicodeDecodeError:
61
if not platform.is_linux():
63
path = path.decode(fs_fallback_encoding, 'strict')