How to use the prance.util.fs.to_posix function in prance

To help you get started, we’ve selected a few prance 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 jfinkhaeuser / prance / tests / test_util_fs.py View on Github external
def test_to_posix_rel():
  test = "tests/specs/with_externals.yaml"
  assert fs.to_posix(os.path.normpath(test)) == test
github jfinkhaeuser / prance / tests / test_util_fs.py View on Github external
def test_abspath_relative_dir():
  testname = 'error.json'
  relative = os.path.join(os.getcwd(), 'tests', 'specs')
  res = fs.abspath(testname, relative)
  expected = fs.to_posix(os.path.join(os.getcwd(), 'tests', 'specs', testname))
  assert res == expected
github jfinkhaeuser / prance / tests / test_util_fs.py View on Github external
def test_to_posix_abs_posix():
  test = "/etc/passwd"
  expected = test
  assert fs.to_posix(test) == expected
github jfinkhaeuser / prance / tests / test_util_fs.py View on Github external
def test_abspath_basics():
  testname = os.path.normpath('tests/specs/with_externals.yaml')
  res = fs.abspath(testname)
  expected = fs.to_posix(os.path.join(os.getcwd(), testname))
  assert res == expected
github jfinkhaeuser / prance / tests / test_util_fs.py View on Github external
def test_to_posix_abs_win32():
  test = "c:\\windows\\notepad.exe"
  expected = "/c:/windows/notepad.exe"
  assert fs.to_posix(test) == expected
github jfinkhaeuser / prance / prance / util / url.py View on Github external
if is_pathname_valid(url):
      from . import fs
      url = fs.to_posix(url)
    parsed = parse.urlparse(url)

  # Any non-file scheme we just return immediately.
  if parsed.scheme not in (None, '', 'file'):
    return parsed

  # Parse up the reference URL
  reference = relative_to
  if reference and not isinstance(reference, tuple):
    from .fs import is_pathname_valid
    if is_pathname_valid(reference):
      from . import fs
      reference = fs.to_posix(reference)
    reference = parse.urlparse(reference)

  # If the input URL has no path, we assume only its fragment matters.
  # That is, we'll have to set the fragment of the reference URL to that
  # of the input URL, and return the result.
  import os.path
  from .fs import from_posix, abspath
  result_list = None
  if not parsed.path:
    if not reference or not reference.path:
      raise ResolutionError('Cannot build an absolute file URL from a fragment'
          ' without a reference with path!')
    result_list = list(reference)
    result_list[5] = parsed.fragment
  elif os.path.isabs(from_posix(parsed.path)):
    # We have an absolute path, so we can ignore the reference entirely!
github jfinkhaeuser / prance / prance / util / url.py View on Github external
Non-file URLs are left untouched. URLs without scheme are assumed to be file
  URLs.

  :param str/tuple url: The input URL.
  :param str/tuple relative_to: [optional] The URL to which the input URL is
      relative.
  :return: The output URL, parsed into components.
  :rtype: tuple
  """
  # Parse input URL, if necessary
  parsed = url
  if not isinstance(parsed, tuple):
    from .fs import is_pathname_valid
    if is_pathname_valid(url):
      from . import fs
      url = fs.to_posix(url)
    parsed = parse.urlparse(url)

  # Any non-file scheme we just return immediately.
  if parsed.scheme not in (None, '', 'file'):
    return parsed

  # Parse up the reference URL
  reference = relative_to
  if reference and not isinstance(reference, tuple):
    from .fs import is_pathname_valid
    if is_pathname_valid(reference):
      from . import fs
      reference = fs.to_posix(reference)
    reference = parse.urlparse(reference)

  # If the input URL has no path, we assume only its fragment matters.