Get the contents of an object stored in S3 as bytes

        :param s3_path: URL for target S3 location
        :return: File contents as pure bytes
488515
def get_as_bytes(self, s3_path):
        
        (bucket, key) = self._path_to_bucket_and_key(s3_path)
        obj = self.s3.Object(bucket, key)
        contents = obj.get()['Body'].read()
        return contents
733170
def get_stream(self, rel_path, cb=None, return_meta=False):
        """"""
        from boto.s3.key import Key
        from boto.exception import S3ResponseError

        import StringIO
        from . import MetadataFlo

        b = StringIO.StringIO()
        try:
            k = self._get_boto_key(rel_path)
            if not k:
                return None

            k.get_contents_to_file(b, cb=cb, num_cb=100)

            b.seek(0)

            if return_meta:
                d = k.metadata
                d['size'] = k.size
                d['etag'] = k.etag
            else:
                d = {}

            return MetadataFlo(b, d)

        except S3ResponseError as e:
            if e.status == 404:
                return None
            else:
                raise e
1374410
def get_content_version(cls, abspath: str) -> str:
        
        data = cls.get_content(abspath)
        hasher = hashlib.md5()
        if isinstance(data, bytes):
            hasher.update(data)
        else:
            for chunk in data:
                hasher.update(chunk)
        return hasher.hexdigest()
732788
def file_path(self, request, response=None, info=None):
        
        return json.dumps(self._extract_key_info(request))
990632
def get_key(self, path):
        
        (bucket, key) = self._path_to_bucket_and_key(path)

        if self._exists(bucket, key):
            return self.s3.ObjectSummary(bucket, key)
739111
def bucket_and_path(self, url):
        """"""
        url = compat.as_str_any(url)
        if url.startswith("s3://"):
            url = url[len("s3://"):]
        idx = url.index("/")
        bucket = url[:idx]
        path = url[(idx + 1):]
        return bucket, path
356216
def read_bytes(self, path):
        """"""
        file = staticfiles_storage.open(path)
        content = file.read()
        file.close()
        return content
767213
def fs_encode(path):
    

    path = _get_path(path)
    if path is None:
        raise TypeError("expected a valid path to encode")
    if isinstance(path, six.text_type):
        if six.PY2:
            return b"".join(
                (
                    _byte(ord(c) - 0xDC00)
                    if 0xDC00 <= ord(c) <= 0xDCFF
                    else c.encode(_fs_encoding, _fs_encode_errors)
                )
                for c in path
            )
        return path.encode(_fs_encoding, _fs_encode_errors)
    return path
516970
def load_data(cls, relpath):
        
        filepath = os.path.join(cls.data_path, relpath)
        with open(filepath) as fp:
            content = fp.read()

        return content
185434
def get_file_contents(self, path):
        
        path = self._normalize_path(path)
        res = self._session.get(
            self._webdav_url + parse.quote(self._encode_string(path))
        )
        if res.status_code == 200:
            return res.content
        elif res.status_code >= 400:
            raise HTTPResponseError(res)
        return False
380011
def download(s3_conn, out_filename, s3_path):
    
    bucket_name, prefix = split_s3_path(s3_path)
    bucket = s3_conn.get_bucket(bucket_name)
    key = boto.s3.key.Key(
        bucket=bucket,
        name=prefix
    )
    logging.info('loading from %s into %s', key, out_filename)
    key.get_contents_to_filename(out_filename, cb=log_download_progress)
201427
def _normalize_file_path(file_path):
        
        if not file_path:
            return None
        elif file_path.startswith('s3://') or \
                file_path.startswith('http://') or \
                file_path.startswith('https://'):
            return file_path
        return path.abspath(file_path)
991783
def load_file(client, bucket, data_file):
    """"""
    logger.debug('Loading item from s3. Bucket: {bucket} Key: {key}'.format(
        bucket=bucket,
        key=data_file
    ))

    # If the file doesn't exist, then return an empty dict:
    try:
        data = _get_from_s3(client, bucket, data_file)

    except ClientError as ce:
        if ce.response['Error']['Code'] == 'NoSuchKey':
            return {}

        else:
            raise ce

    if sys.version_info > (3,):
        data = data.decode('utf-8')

    return json.loads(data)
1197860
def get_dir_contents(self, path, ref=github.GithubObject.NotSet):
        
        assert isinstance(path, (str, unicode)), path
        assert ref is github.GithubObject.NotSet or isinstance(ref, (str, unicode)), ref
        url_parameters = dict()
        if ref is not github.GithubObject.NotSet:
            url_parameters["ref"] = ref
        headers, data = self._requester.requestJsonAndCheck(
            "GET",
            self.url + "/contents/" + urllib.quote(path),
            parameters=url_parameters
        )

        # Handle 302 redirect response
        if headers.get('status') == '302 Found' and headers.get('location'):
            headers, data = self._requester.requestJsonAndCheck(
                "GET",
                headers['location'],
                parameters=url_parameters
            )

        return [
            github.ContentFile.ContentFile(self._requester, headers, attributes, completed=(attributes["type"] != "file"))  # Lazy completion only makes sense for files. See discussion here: https://github.com/jacquev6/PyGithub/issues/140#issuecomment-13481130
            for attributes in data
        ]
208363
def save_to_path(self, file_path, chunk_size=DOWNLOAD_FILE_CHUNK_SIZE):
        
        response = self._get_download_response()
        with open(file_path, 'wb') as f:
            for chunk in response.iter_content(chunk_size=chunk_size):
                if chunk:  # filter out keep-alive new chunks
                    f.write(chunk)
474977
def read(self, path, filename=None, offset=None, size=-1):
        
        storageScheme, key = self.getkey(path, filename=filename)

        if offset or (size > -1):
            if not offset:
                offset = 0
            if size > -1:
                sizeStr = offset + size - 1  # range header is inclusive
            else:
                sizeStr = ""
            headers = {"Range": "bytes=%d-%s" % (offset, sizeStr)}
            return key.get_contents_as_string(headers=headers)
        else:
            return key.get_contents_as_string()
688809
def get_content(path):
    """"""
    with codecs.open(abs_path(path), encoding='utf-8') as f:
        return f.read()