# -*- coding: utf-8 -*-
"""
   etc.client
   ~~~~~~~~~~
"""
from __future__ import absolute_import

from six.moves.urllib.parse import urlparse

from .adapters import EtcdAdapter, MockAdapter
from .helpers import gen_repr


__all__ = ['Client']


ADAPTER_CLASSES = {
    'http': EtcdAdapter,
    'https': EtcdAdapter,
    'mock': MockAdapter,
}
DEFAULT_URL = 'http://127.0.0.1:4001'


class Client(object):

    def __init__(self, url=DEFAULT_URL, *args, **kwargs):
        url_info = urlparse(url)
        adapter_class = ADAPTER_CLASSES[url_info.scheme]
        self._adapter = adapter_class(url, *args, **kwargs)

    @property
    def url(self):
        return self._adapter.url

    def __repr__(self):
        return gen_repr(self.__class__, u"'{0}'", self.url, short=True)

    def get(self, key, recursive=False, sorted=False, quorum=False,
            timeout=None):
        """Gets a value of key."""
        return self._adapter.get(
            key, recursive=recursive, sorted=sorted, quorum=quorum,
            timeout=timeout)

    def wait(self, key, index=0, recursive=False, sorted=False, quorum=False,
             timeout=None):
        """Waits until a node changes."""
        return self._adapter.get(
            key, recursive=recursive, sorted=sorted, quorum=quorum,
            wait=True, wait_index=index, timeout=timeout)

    def set(self, key, value=None, dir=False, ttl=None,
            prev_value=None, prev_index=None, timeout=None):
        """Sets a value to a key."""
        return self._adapter.set(
            key, value, dir=dir, ttl=ttl,
            prev_value=prev_value, prev_index=prev_index, timeout=timeout)

    def create(self, key, value=None, dir=False, ttl=None, timeout=None):
        """Creates a new key."""
        return self._adapter.set(
            key, value, dir=dir, ttl=ttl, prev_exist=False, timeout=timeout)

    def update(self, key, value=None, dir=False, ttl=None,
               prev_value=None, prev_index=None, timeout=None):
        """Updates an existing key."""
        return self._adapter.set(
            key, value, dir=dir, ttl=ttl,
            prev_value=prev_value, prev_index=prev_index, prev_exist=True,
            timeout=timeout)

    def append(self, key, value=None, dir=False, ttl=None, timeout=None):
        """Creates a new automatically increasing key in the given directory
        key.
        """
        return self._adapter.append(
            key, value, dir=dir, ttl=ttl, timeout=timeout)

    def delete(self, key, dir=False, recursive=False,
               prev_value=None, prev_index=None, timeout=None):
        """Deletes a key."""
        return self._adapter.delete(
            key, dir=dir, recursive=recursive,
            prev_value=prev_value, prev_index=prev_index, timeout=timeout)

@@ -933,37 +933,24 @@
 adapter.get(
-%0A            
 key, recursi
@@ -969,32 +969,65 @@
 , sorted=sorted,
+%0A                                
  quorum=quorum,%0A
@@ -1025,28 +1025,16 @@
 =quorum,
-%0A           
  timeout
@@ -1225,29 +1225,16 @@
 ter.get(
-%0A            
 key, rec
@@ -1265,16 +1265,49 @@
 =sorted,
+%0A                                
  quorum=
@@ -1313,28 +1313,16 @@
 =quorum,
-%0A           
  wait=Tr
@@ -1338,24 +1338,57 @@
 index=index,
+%0A                                
  timeout=tim
@@ -1577,37 +1577,24 @@
 adapter.set(
-%0A            
 key, value, 
@@ -1603,32 +1603,53 @@
 r=dir, ttl=ttl,%0A
+                     
             prev
@@ -1681,32 +1681,65 @@
 ndex=prev_index,
+%0A                                
  timeout=timeout
@@ -1877,37 +1877,24 @@
 adapter.set(
-%0A            
 key, value, 
@@ -1910,16 +1910,49 @@
 ttl=ttl,
+%0A                                
  prev_ex
@@ -2175,29 +2175,16 @@
 ter.set(
-%0A            
 key, val
@@ -2197,32 +2197,53 @@
 r=dir, ttl=ttl,%0A
+                     
             prev
@@ -2283,16 +2283,49 @@
 v_index,
+%0A                                
  prev_ex
@@ -2333,28 +2333,16 @@
 st=True,
-%0A           
  timeout
@@ -2564,29 +2564,16 @@
 .append(
-%0A            
 key, val
@@ -2593,16 +2593,52 @@
 ttl=ttl,
+%0A                                   
  timeout
@@ -2831,29 +2831,16 @@
 .delete(
-%0A            
 key, dir
@@ -2866,16 +2866,40 @@
 ursive,%0A
+                        
         
@@ -2916,32 +2916,68 @@
 alue=prev_value,
+%0A                                   
  prev_index=prev

Change indentation