# Path: cloudvolume/exceptions.py
# class UnsupportedProtocolError(ValueError):
#   """Unknown protocol extension."""
#   pass
# 
# Path: cloudvolume/lib.py
# def yellow(text):
#   return colorize('yellow', text)
# 
# def toabs(path):
#   path = os.path.expanduser(path)
#   return os.path.abspath(path)


import cloudfiles.paths
import os
import posixpath
import re
import sys
from collections import namedtuple
from .exceptions import UnsupportedProtocolError
from .lib import yellow, toabs
Supported Formats: None (precomputed), {}
Supported Protocols: {}

Cloud Path Recieved: {}
""").format(
  ", ".join(ALLOWED_FORMATS), ", ".join(ALLOWED_PROTOCOLS), 
  cloudpath
)

def ascloudpath(epath):
  return "{}://{}://{}".format(
    epath.format, epath.protocol, 
    posixpath.join(epath.basepath, epath.layer)
  )

def pop_protocol(cloudpath):
  protocol_re = re.compile(r'(\w+)://')

  match = re.match(protocol_re, cloudpath)

  if not match:
    return (None, cloudpath)

  (protocol,) = match.groups()
  cloudpath = re.sub(protocol_re, '', cloudpath, count=1)

  return (protocol, cloudpath)

def extract_format_protocol(cloudpath):
  global ALLOWED_PROTOCOLS

# Path: cloudvolume/exceptions.py
# class UnsupportedProtocolError(ValueError):
#   """Unknown protocol extension."""
#   pass
# 
# Path: cloudvolume/lib.py
# def yellow(text):
#   return colorize('yellow', text)
# 
# def toabs(path):
#   path = os.path.expanduser(path)
#   return os.path.abspath(path)


# Path: cloudvolume/paths.py
import cloudfiles.paths
import os
import posixpath
import re
import sys
from collections import namedtuple
from .exceptions import UnsupportedProtocolError
from .lib import yellow, toabs

Supported Formats: None (precomputed), {}
Supported Protocols: {}

Cloud Path Recieved: {}
""").format(
  ", ".join(ALLOWED_FORMATS), ", ".join(ALLOWED_PROTOCOLS), 
  cloudpath
)

def ascloudpath(epath):
  return "{}://{}://{}".format(
    epath.format, epath.protocol, 
    posixpath.join(epath.basepath, epath.layer)
  )

def pop_protocol(cloudpath):
  protocol_re = re.compile(r'(\w+)://')

  match = re.match(protocol_re, cloudpath)

  if not match:
    return (None, cloudpath)

  (protocol,) = match.groups()
  cloudpath = re.sub(protocol_re, '', cloudpath, count=1)

  return (protocol, cloudpath)

def extract_format_protocol(cloudpath):
  global ALLOWED_PROTOCOLS

  error = UnsupportedProtocolError(cloudpath_error(cloudpath))