code: def get_attachment(
              self,
              attachment,
              headers=None,
              write_to=None,
              attachment_type=None):
          
          # need latest rev
          self.fetch()
          attachment_url = '/'.join((self.document_url, attachment))
          if headers is None:
              headers = {'If-Match': self['_rev']}
          else:
              headers['If-Match'] = self['_rev']
  
          resp = self.r_session.get(attachment_url, headers=headers)
          resp.raise_for_status()
  
          if attachment_type is None:
              if resp.headers['Content-Type'].startswith('text/'):
                  attachment_type = 'text'
              elif resp.headers['Content-Type'] == 'application/json':
                  attachment_type = 'json'
              else:
                  attachment_type = 'binary'
  
          if write_to is not None:
              if attachment_type in ('text', 'json'):
                  write_to.write(resp.text)
              else:
                  write_to.write(resp.content)
          if attachment_type == 'text':
              return resp.text
          if attachment_type == 'json':
              return response_to_json_dict(resp)
  
          return resp.content
docs: Retrieves a document's attachment and optionally writes it to a file.
          If the content_type of the attachment is 'application/json' then the
          data returned will be in JSON format otherwise the response content will
          be returned as text or binary.
  
          :param str attachment: Attachment file name used to identify the
              attachment.
          :param dict headers: Optional, additional headers to be sent
              with request.
          :param file write_to: Optional file handler to write the attachment to.
              The write_to file must be opened for writing prior to including it
              as an argument for this method.
          :param str attachment_type: Optional setting to define how to handle the
              attachment when returning its contents from this method.  Valid
              values are ``'text'``, ``'json'``, and ``'binary'``  If
              omitted then the returned content will be based on the
              response Content-Type.
  
          :returns: The attachment content