# -*- coding: utf-8 -*-
from __future__ import absolute_import

from . import base


class Section(base.SectionBase):
	@base.returns_single_item
	def publish(self, ipfs_path, resolve=True, lifetime="24h", ttl=None, key=None, **kwargs):
		"""Publishes an object to IPNS.

		IPNS is a PKI namespace, where names are the hashes of public keys, and
		the private key enables publishing new (signed) values. In publish, the
		default value of *name* is your own identity public key.

		.. code-block:: python

			>>> client.name.publish('/ipfs/QmfZY61ukoQuCX8e5Pt7v8pRfhkyxwZK … GZ5d')
			{'Value': '/ipfs/QmfZY61ukoQuCX8e5Pt7v8pRfhkyxwZKZMTodAtmvyGZ5d',
			 'Name': 'QmVgNoP89mzpgEAAqK8owYoDEyB97MkcGvoWZir8otE9Uc'}

		Parameters
		----------
		ipfs_path : str
			IPFS path of the object to be published
		resolve : bool
			Resolve given path before publishing
		lifetime : str
			Time duration that the record will be valid for

			Accepts durations such as ``"300s"``, ``"1.5h"`` or ``"2h45m"``.
			Valid units are:

			 * ``"ns"``
			 * ``"us"`` (or ``"µs"``)
			 * ``"ms"``
			 * ``"s"``
			 * ``"m"``
			 * ``"h"``
		ttl : string
			Time duration this record should be cached for.
			Same syntax like 'lifetime' option. (experimental feature)
		key : string
			 Name of the key to be used, as listed by 'ipfs key list'.

		Returns
		-------
			dict : IPNS hash and the IPFS path it points at
		"""
		opts = {"lifetime": lifetime, "resolve": resolve}
		if ttl:
			opts["ttl"] = ttl
		if key:
			opts["key"] = key
		kwargs.setdefault("opts", {}).update(opts)

		args = (ipfs_path,)
		return self._client.request('/name/publish', args, decoder='json', **kwargs)
	
	
	@base.returns_single_item
	def resolve(self, name=None, recursive=False, nocache=False, **kwargs):
		"""Gets the value currently published at an IPNS name.

		IPNS is a PKI namespace, where names are the hashes of public keys, and
		the private key enables publishing new (signed) values. In resolve, the
		default value of ``name`` is your own identity public key.

		.. code-block:: python

			>>> client.name.resolve()
			{'Path': '/ipfs/QmfZY61ukoQuCX8e5Pt7v8pRfhkyxwZKZMTodAtmvyGZ5d'}

		Parameters
		----------
		name : str
			The IPNS name to resolve (defaults to the connected node)
		recursive : bool
			Resolve until the result is not an IPFS name (default: false)
		nocache : bool
			Do not use cached entries (default: false)

		Returns
		-------
			dict : The IPFS path the IPNS hash points at
		"""
		opts = {"recursive": recursive, "nocache": nocache}
		kwargs.setdefault("opts", {}).update(opts)
		args = (name,) if name is not None else ()
		return self._client.request('/name/resolve', args, decoder='json', **kwargs)
@@ -217,16 +217,50 @@
 ey=None,
+%0A%09            allow_offline=False,
  **kwarg
@@ -884,16 +884,176 @@
 lishing%0A
+%09%09allow_offline : bool%0A%09%09%09 When offline, save the IPNS record to the the local%0A%09%09%09 datastore without broadcasting to the network instead%0A%09%09%09 of simply failing.%0A
 %09%09lifeti
@@ -1617,16 +1617,26 @@
 ifetime,
+%0A%09%09       
  %22resolv
@@ -1646,16 +1646,58 @@
  resolve
+,%0A%09%09        %22allow-offline%22: allow_offline
 %7D%0A%09%09if t
@@ -1983,32 +1983,86 @@
 , nocache=False,
+%0A%09            dht_record_count=None, dht_timeout=None,
  **kwargs):%0A%09%09%22%22
@@ -2700,136 +2700,471 @@
 se)%0A
-%0A%09%09Returns%0A%09%09-------%0A%09%09%09dict : The IPFS path the IPNS hash points at%0A%09%09%22%22%22%0A%09%09opts = %7B%22recursive%22: recursive, %22nocache%22: nocache%7D
+%09%09dht_record_count: int%0A%09%09%09Number of records to request for DHT resolution.%0A%09%09dht_timeout: string%0A%09%09%09Max time to collect values during DHT resolution eg %2230s%22.%0A%09%09%09Pass 0 for no timeout%0A%0A%09%09Returns%0A%09%09-------%0A%09%09%09dict : The IPFS path the IPNS hash points at%0A%09%09%22%22%22%0A%09%09opts = %7B%22recursive%22: recursive, %22nocache%22: nocache%7D%0A%09%09if dht_record_count is not None:%0A%09%09%09opts%5B%22dht-record-count%22%5D = dht_record_count%0A%09%09if dht_timeout is not None:%0A%09%09%09opts%5B%22dht-timeout%22%5D = dht_timeout%0A
 %0A%09%09k

add dht-related arguments to publish