How to use the pathlib2._PosixFlavour function in pathlib2

To help you get started, we’ve selected a few pathlib2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nodepy / nodepy / src / nodepy / utils / path / urlpath.py View on Github external
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):
github nodepy / nodepy / src / nodepy / utils / path / zippath.py View on Github external
  @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):