(cls, args)
| 816 | |
| 817 | @classmethod |
| 818 | def _parse_args(cls, args): |
| 819 | # This is useful when you don't want to create an instance, just |
| 820 | # canonicalize some constructor arguments. |
| 821 | parts = [] |
| 822 | for a in args: |
| 823 | if isinstance(a, PurePath): |
| 824 | parts += a._parts |
| 825 | else: |
| 826 | if sys.version_info >= (3, 6): |
| 827 | a = os.fspath(a) |
| 828 | else: |
| 829 | # duck typing for older Python versions |
| 830 | if hasattr(a, "__fspath__"): |
| 831 | a = a.__fspath__() |
| 832 | if isinstance(a, str): |
| 833 | # Force-cast str subclasses to str (issue #21127) |
| 834 | parts.append(str(a)) |
| 835 | # also handle unicode for PY2 (pycompat.text_type = unicode) |
| 836 | elif pycompat.PY2 and isinstance(a, pycompat.text_type): |
| 837 | # cast to str using filesystem encoding |
| 838 | parts.append(a.encode(sys.getfilesystemencoding())) |
| 839 | else: |
| 840 | raise TypeError( |
| 841 | "argument should be a str object or an os.PathLike " |
| 842 | "object returning str, not %r" |
| 843 | % type(a)) |
| 844 | return cls._flavour.parse_parts(parts) |
| 845 | |
| 846 | @classmethod |
| 847 | def _from_parts(cls, args, init=True): |
no test coverage detected