Exemplo n.º 1
0
    def canonical_resource(self):
        '''
            详见:http://sinastorage.sinaapp.com/developer/interface/aws/auth.html
        '''
        res = "/"
        if self.bucket:
            res += '%s/'%aws_urlquote(self.bucket)
        if self.key is not None:
            res += "%s" % aws_urlquote(self.key)
        if self.subresource:
            if self.subresource in self.subresource_need_to_sign:
                res += "?%s" % aws_urlquote(self.subresource)
        if self.args:
            rv = {}
            for key, value in six.iteritems(self.args):
#                 key = key.lower()
                if key in self.subresource_kv_need_to_sign:
                    rv[key] = value
            
            if len(rv) > 0 :
                parts = []
                for key in sorted(rv):
                    parts.append("%s=%s" % (key, rv[key]))
                res += "%s%s" % ('&' if self.subresource and self.subresource in self.subresource_need_to_sign else '?', "&".join(parts))
        return res
Exemplo n.º 2
0
    def canonical_resource(self):
        '''
			详见:http://sinastorage.sinaapp.com/developer/interface/aws/auth.html
		'''
        res = "/"
        if self.bucket:
            res += '%s/' % aws_urlquote(self.bucket)
        if self.key is not None:
            res += "%s" % aws_urlquote(self.key)
        if self.subresource:
            if self.subresource in self.subresource_need_to_sign:
                res += "?%s" % aws_urlquote(self.subresource)
        if self.args:
            rv = {}
            for key, value in six.iteritems(self.args):
                #                 key = key.lower()
                if key in self.subresource_kv_need_to_sign:
                    rv[key] = value

            if len(rv) > 0:
                parts = []
                for key in sorted(rv):
                    parts.append("%s=%s" % (key, rv[key]))
                res += "%s%s" % ('&' if self.subresource and self.subresource
                                 in self.subresource_need_to_sign else '?',
                                 "&".join(parts))
        return res
Exemplo n.º 3
0
    def url(self, base_url, arg_sep="&", bucketAsDomain=False):
        if bucketAsDomain:  #bucket name 作为域名
            url = 'http://' + self.bucket + "/"
        else:
            url = base_url + "/"

        #生成url,不适用https方式请求
        if url.startswith('https://'):
            url = 'http://' + url[8:]

        if self.key:
            url += aws_urlquote(self.key)
        if self.subresource or self.args:
            ps = []
            if self.subresource:
                ps.append(self.subresource)
            if self.args:
                args = self.args
                if hasattr(args, "iteritems") or hasattr(args, "items"):
                    args = six.iteritems(args)
                args = ((urllib.parse.quote_plus(k),
                         urllib.parse.quote_plus(v)) for (k, v) in args)
                args = arg_sep.join("%s=%s" % i for i in args)
                ps.append(args)
            url += "?" + "&".join(ps)
        return url
Exemplo n.º 4
0
 def __init__(self, name=None, base_url=None, timeout=None, secure=False):
     if sinastorage.getDefaultAppInfo() is not None :
         self.access_key = sinastorage.getDefaultAppInfo().access_key
         self.secret_key = sinastorage.getDefaultAppInfo().secret_key
         secure = sinastorage.getDefaultAppInfo().secure
     else :
         import os
         if 'S3_ACCESS_KEY_ID' in os.environ and 'S3_SECRET_ACCESS_KEY' in os.environ:
             self.access_key = os.environ.get('S3_ACCESS_KEY_ID')
             self.secret_key = os.environ.get('S3_SECRET_ACCESS_KEY')
             secure = True
         else:
             raise ValueError("access_key and secret_key must not be None! \n\
             Please set sinastorage.setDefaultAppInfo('access_key', 'secret_key') \n\
             or set S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY in Environment first!")
     
     scheme = ("http", "https")[int(bool(secure))]
     if not base_url:
         base_url = "%s://%s" % (scheme, sinastorage_domain)
         if name:
             base_url += "/%s" % aws_urlquote(name)
     elif secure is not None:
         if not base_url.startswith(scheme + "://"):
             raise ValueError("secure=%r, url must use %s"
                              % (secure, scheme))
     self.opener = self.build_opener()
     self.name = name
     
     self.base_url = base_url
     self.timeout = 30
     self.timeout = timeout
Exemplo n.º 5
0
 def url(self, base_url, arg_sep="&", bucketAsDomain=False):
     if bucketAsDomain:              #bucket name 作为域名
         url = 'http://'+self.bucket + "/"
     else:
         url = base_url + "/"
         
     #生成url,不适用https方式请求
     if url.startswith('https://') :
         url = 'http://'+url[8:]
         
     if self.key:
         url += aws_urlquote(self.key)
     if self.subresource or self.args:
         ps = []
         if self.subresource:
             ps.append(self.subresource)
         if self.args:
             args = self.args
             if hasattr(args, "iteritems") or hasattr(args, "items"):
                 args = six.iteritems(args)
             args = ((urllib.parse.quote_plus(k), urllib.parse.quote_plus(v)) for (k, v) in args)
             args = arg_sep.join("%s=%s" % i for i in args)
             ps.append(args)
         url += "?" + "&".join(ps)
     return url
    def __init__(self, name=None, base_url=None, timeout=None, secure=False):
        if sinastorage.getDefaultAppInfo() is not None:
            self.access_key = sinastorage.getDefaultAppInfo().access_key
            self.secret_key = sinastorage.getDefaultAppInfo().secret_key
            secure = sinastorage.getDefaultAppInfo().secure
        else:
            import os
            if 'S3_ACCESS_KEY_ID' in os.environ and 'S3_SECRET_ACCESS_KEY' in os.environ:
                self.access_key = os.environ.get('S3_ACCESS_KEY_ID')
                self.secret_key = os.environ.get('S3_SECRET_ACCESS_KEY')
                secure = True
            else:
                raise ValueError(
                    "access_key and secret_key must not be None! \n\
                Please set sinastorage.setDefaultAppInfo('access_key', 'secret_key') \n\
                or set S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY in Environment first!"
                )

        scheme = ("http", "https")[int(bool(secure))]
        if not base_url:
            base_url = "%s://%s" % (scheme, sinastorage_domain)
            if name:
                base_url += "/%s" % aws_urlquote(name)
        elif secure is not None:
            if not base_url.startswith(scheme + "://"):
                raise ValueError("secure=%r, url must use %s" %
                                 (secure, scheme))
        self.opener = self.build_opener()
        self.name = name

        self.base_url = base_url
        self.timeout = 30
        self.timeout = timeout
Exemplo n.º 7
0
 def url(self, base_url, arg_sep="&"):
     url = base_url + "/"
     if self.key:
         url += aws_urlquote(self.key)
     if self.subresource or self.args:
         ps = []
         if self.subresource:
             ps.append(self.subresource)
         if self.args:
             args = self.args
             if hasattr(args, "iteritems"):
                 args = args.iteritems()
             args = ((quote_plus(k), quote_plus(v)) for (k, v) in args)
             args = arg_sep.join("%s=%s" % i for i in args)
             ps.append(args)
         url += "?" + "&".join(ps)
     return url
Exemplo n.º 8
0
 def __init__(self, name=None, base_url=None, timeout=None, secure=False):
     if sinastorage.getDefaultAppInfo() is None :
         raise ValueError("access_key and secret_key must not be None! Please set sinastorage.setDefaultAppInfo('access_key', 'secret_key') first!")
     self.access_key = sinastorage.getDefaultAppInfo().access_key
     self.secret_key = sinastorage.getDefaultAppInfo().secret_key
     secure = sinastorage.getDefaultAppInfo().secure
     
     scheme = ("http", "https")[int(bool(secure))]
     if not base_url:
         base_url = "%s://%s" % (scheme, sinastorage_domain)
         if name:
             base_url += "/%s" % aws_urlquote(name)
     elif secure is not None:
         if not base_url.startswith(scheme + "://"):
             raise ValueError("secure=%r, url must use %s"
                              % (secure, scheme))
     self.opener = self.build_opener()
     self.name = name
     
     self.base_url = base_url
     self.timeout = 30
     self.timeout = timeout