OLD | NEW |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """The operating system path specification implementation.""" | 2 """The operating system path specification implementation.""" |
3 | 3 |
| 4 from __future__ import unicode_literals |
| 5 |
4 import os | 6 import os |
5 | 7 |
6 from dfvfs.lib import definitions | 8 from dfvfs.lib import definitions |
7 from dfvfs.path import factory | 9 from dfvfs.path import factory |
8 from dfvfs.path import location_path_spec | 10 from dfvfs.path import location_path_spec |
9 | 11 |
10 | 12 |
11 class OSPathSpec(location_path_spec.LocationPathSpec): | 13 class OSPathSpec(location_path_spec.LocationPathSpec): |
12 """Class that implements the operating system path specification.""" | 14 """Operating system path specification.""" |
13 | 15 |
14 _IS_SYSTEM_LEVEL = True | 16 _IS_SYSTEM_LEVEL = True |
15 TYPE_INDICATOR = definitions.TYPE_INDICATOR_OS | 17 TYPE_INDICATOR = definitions.TYPE_INDICATOR_OS |
16 | 18 |
17 def __init__(self, location=None, **kwargs): | 19 def __init__(self, location=None, **kwargs): |
18 """Initializes the path specification. | 20 """Initializes a path specification. |
19 | 21 |
20 Note that the operating system path specification cannot have a parent. | 22 Note that the operating system path specification cannot have a parent. |
21 | 23 |
22 Args: | 24 Args: |
23 location (Optional[str]): operating specific location string e.g. | 25 location (Optional[str]): operating specific location string e.g. |
24 /opt/dfvfs or C:\\Opt\\dfvfs. | 26 /opt/dfvfs or C:\\Opt\\dfvfs. |
25 | 27 |
26 Raises: | 28 Raises: |
27 ValueError: when location is not set or parent is set. | 29 ValueError: when location is not set or parent is set. |
28 """ | 30 """ |
29 if not location: | 31 if not location: |
30 raise ValueError(u'Missing location value.') | 32 raise ValueError('Missing location value.') |
31 | 33 |
32 parent = None | 34 parent = None |
33 if u'parent' in kwargs: | 35 if 'parent' in kwargs: |
34 parent = kwargs[u'parent'] | 36 parent = kwargs['parent'] |
35 del kwargs[u'parent'] | 37 del kwargs['parent'] |
36 | 38 |
37 if parent: | 39 if parent: |
38 raise ValueError(u'Parent value set.') | 40 raise ValueError('Parent value set.') |
39 | 41 |
40 # Within the path specification the path should be absolute. | 42 # Within the path specification the path should be absolute. |
41 location = os.path.abspath(location) | 43 location = os.path.abspath(location) |
42 | 44 |
43 super(OSPathSpec, self).__init__(location=location, parent=parent, **kwargs) | 45 super(OSPathSpec, self).__init__(location=location, parent=parent, **kwargs) |
44 | 46 |
45 | 47 |
46 factory.Factory.RegisterPathSpec(OSPathSpec) | 48 factory.Factory.RegisterPathSpec(OSPathSpec) |
OLD | NEW |