コード例 #1
0
ファイル: client.py プロジェクト: ssmir/couchapp
def escape_docid(docid):
    if docid.startswith('/'):
        docid = docid[1:]
    if docid.startswith('_design'):
        docid = '_design/%s' % util.url_quote(docid[8:], safe='')
    else:
        docid = util.url_quote(docid, safe='')
    return docid
コード例 #2
0
ファイル: client.py プロジェクト: rhunter/couchapp
def escape_docid(docid):
    if docid.startswith("/"):
        docid = docid[1:]
    if docid.startswith("_design"):
        docid = "_design/%s" % util.url_quote(docid[8:], safe="")
    else:
        docid = util.url_quote(docid, safe="")
    return docid
コード例 #3
0
ファイル: client.py プロジェクト: ssmir/couchapp
    def put_attachment(self, doc, content=None, name=None, headers=None):
        """ Add attachement to a document. All attachments are streamed.

        @param doc: dict, document object
        @param content: string, iterator,  fileobj
        @param name: name or attachment (file name).
        @param headers: optionnal headers like `Content-Length` 
        or `Content-Type`

        @return: updated document object
        """
        headers = {}
        content = content or ""
            
        if name is None:
            if hasattr(content, "name"):
                name = content.name
            else:
                raise InvalidAttachment(
                            'You should provid a valid attachment name')
        name = util.url_quote(name, safe="")
        res = self.put("%s/%s" % (escape_docid(doc['_id']), name), 
                    payload=content, headers=headers, rev=doc['_rev'])
        json_res = res.json_body
        
        if 'ok' in json_res:
            return doc.update(self.open_doc(doc['_id']))
        return False
コード例 #4
0
ファイル: client.py プロジェクト: rhunter/couchapp
    def delete_attachment(self, doc, name):
        """ delete attachement to the document
        
        @param doc: dict, document object in python
        @param name: name of attachement

        @return: updated document object
        """
        name = util.url_quote(name, safe="")
        self.delete("%s/%s" % (escape_docid(doc["_id"]), name), rev=doc["_rev"]).json_body
        return doc.update(self.open_doc(doc["_id"]))
コード例 #5
0
ファイル: forms.py プロジェクト: gbuesing/couchapp
 def __init__(self, name, value, fname=None, filetype=None, filesize=None):
     self.name = url_quote(name)
     if value is not None and not hasattr(value, 'read'):
         value = url_quote(value)
         self.size = len(value)
     self.value = value
     if fname is not None:
         if isinstance(fname, unicode):
             fname = fname.encode("utf-8").encode("string_escape").replace('"', '\\"')
         else:
             fname = fname.encode("string_escape").replace('"', '\\"')
     self.fname = fname
     if filetype is not None:
         filetype = to_bytestring(filetype)
     self.filetype = filetype
     
     if isinstance(value, file) and filesize is None:
         try:
             value.flush()
         except IOError:
             pass
         self.size = int(os.fstat(value.fileno())[6])
コード例 #6
0
ファイル: forms.py プロジェクト: gbuesing/couchapp
 def encode_hdr(self, boundary):
     """Returns the header of the encoding of this parameter"""
     boundary = url_quote(boundary)
     headers = ["--%s" % boundary]
     if self.fname:
         disposition = 'form-data; name="%s"; filename="%s"' % (self.name,
                 self.fname)
     else:
         disposition = 'form-data; name="%s"' % self.name
     headers.append("Content-Disposition: %s" % disposition)
     if self.filetype:
         filetype = self.filetype
     else:
         filetype = "text/plain; charset=utf-8"
     headers.append("Content-Type: %s" % filetype)
     headers.append("Content-Length: %i" % self.size)
     headers.append("")
     headers.append("")
     return "\r\n".join(headers)
コード例 #7
0
ファイル: resource.py プロジェクト: gbuesing/couchapp
    def _make_uri(self, base, *path, **query):
        """Assemble a uri based on a base, any number of path segments, 
        and query string parameters.

        """
        base_trailing_slash = False
        if base and base.endswith("/"):
            base_trailing_slash = True
            base = base[:-1]
        retval = [base]

        # build the path
        _path = []
        trailing_slash = False       
        for s in path:
            if s is not None and isinstance(s, basestring):
                if len(s) > 1 and s.endswith('/'):
                    trailing_slash = True
                else:
                    trailing_slash = False
                _path.append(util.url_quote(s.strip('/'), self.charset, self.safe))
                       
        path_str =""
        if _path:
            path_str = "/".join([''] + _path)
            if trailing_slash:
                path_str = path_str + "/" 
        elif base_trailing_slash:
            path_str = path_str + "/" 
            
        if path_str:
            retval.append(path_str)

        params_str = util.url_encode(query, self.charset, self.encode_keys)
        if params_str:
            retval.extend(['?', params_str])

        return ''.join(retval)
コード例 #8
0
ファイル: forms.py プロジェクト: gbuesing/couchapp
def form_encode(obj, charser="utf8"):
    tmp = []
    for key, value in obj.items():
        tmp.append("%s=%s" % (url_quote(key), 
                url_quote(value)))
    return to_bytestring("&".join(tmp))