Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import io
import os
import pathlib2 as pathlib
import posixpath
import six
try:
from urllib.request import urlopen
from urllib.parse import urlparse, urlunparse
except ImportError:
from urllib2 import urlopen
from urlparse import urlparse, urlunparse
class _UrlFlavour(pathlib._PosixFlavour):
sep = '/'
altsep = ''
has_drv = False
pathmod = posixpath
is_supported = True
def splitroot(self, part, sep=sep):
res = urlparse(part)
return (
res.scheme + '://' if res.scheme else '',
res.netloc + '/' if res.netloc else '',
urlunparse(('', '', res.path, res.params, res.query, res.fragment))
)
class PureUrlPath(pathlib.PurePath):
@maybe_classmethod
def _from_parts(self, *args, **kwargs):
new = super(CopyFromSourceMixin, self)._from_parts(*args, **kwargs)
if not isinstance(self, type):
new._copy_from_source(self)
return new
@property
def parents(self):
parents = pathlib._PathParents(self)
parents._pathcls = self
return parents
class PureZipPath(CopyFromSourceMixin, pathlib.PurePath):
_flavour = pathlib._PosixFlavour()
_flavour.is_supported = True
__slots__ = ()
def __new__(cls, zipf, s):
self = super(PureZipPath, cls).__new__(cls, s)
self._init_zipf(zipf)
return self
def _copy_from_source(self, source):
self._init_zipf(source._zipf)
def _init_zipf(self, zipf):
self._zipf = zipf
class ZipPath(pathlib.Path, PureZipPath):