

def _listing(self, env, start_response, prefix=None):
    '\n        Sends an HTML object listing to the remote client.\n\n        :param env: The original WSGI environment dict.\n        :param start_response: The original WSGI start_response hook.\n        :param prefix: Any prefix desired for the container listing.\n        '
    label = env['PATH_INFO']
    if self._listings_label:
        groups = env['PATH_INFO'].split('/')
        label = '{0}/{1}'.format(self._listings_label, '/'.join(groups[4:]))
    if (not config_true_value(self._listings)):
        body = ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n<html>\n<head>\n<title>Listing of %s</title>\n' % cgi.escape(label))
        if self._listings_css:
            body += ('  <link rel="stylesheet" type="text/css" href="%s" />\n' % self._build_css_path((prefix or '')))
        else:
            body += '  <style type="text/css">\n   h1 {font-size: 1em; font-weight: bold;}\n   p {font-size: 2}\n  </style>\n'
        body += '</head>\n<body>  <h1>Web Listing Disabled</h1>   <p>The owner of this web site has disabled web listing.   <p>If you are the owner of this web site, you can enable   web listing by setting X-Container-Meta-Web-Listings.</p>'
        if self._index:
            body += ('<h1>Index File Not Found</h1> <p>The owner of this web site has set  <b>X-Container-Meta-Web-Index: %s</b>.  However, this file is not found.</p>' % self._index)
        body += ' </body>\n</html>\n'
        resp = HTTPNotFound(body=body)(env, self._start_response)
        return self._error_response(resp, env, start_response)
    tmp_env = make_env(env, 'GET', ('/%s/%s/%s' % (self.version, self.account, self.container)), self.agent, swift_source='SW')
    tmp_env['QUERY_STRING'] = 'delimiter=/&format=json'
    if prefix:
        tmp_env['QUERY_STRING'] += ('&prefix=%s' % quote(prefix))
    else:
        prefix = ''
    resp = self._app_call(tmp_env)
    if (not is_success(self._get_status_int())):
        return self._error_response(resp, env, start_response)
    listing = None
    body = ''.join(resp)
    if body:
        listing = json.loads(body)
    if (not listing):
        resp = HTTPNotFound()(env, self._start_response)
        return self._error_response(resp, env, start_response)
    headers = {
        'Content-Type': 'text/html; charset=UTF-8',
    }
    body = ('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n<html>\n <head>\n  <title>Listing of %s</title>\n' % cgi.escape(label))
    if self._listings_css:
        body += ('  <link rel="stylesheet" type="text/css" href="%s" />\n' % self._build_css_path(prefix))
    else:
        body += '  <style type="text/css">\n   h1 {font-size: 1em; font-weight: bold;}\n   th {text-align: left; padding: 0px 1em 0px 1em;}\n   td {padding: 0px 1em 0px 1em;}\n   a {text-decoration: none;}\n  </style>\n'
    body += (' </head>\n <body>\n  <h1 id="title">Listing of %s</h1>\n  <table id="listing">\n   <tr id="heading">\n    <th class="colname">Name</th>\n    <th class="colsize">Size</th>\n    <th class="coldate">Date</th>\n   </tr>\n' % cgi.escape(label))
    if prefix:
        body += '   <tr id="parent" class="item">\n    <td class="colname"><a href="../">../</a></td>\n    <td class="colsize">&nbsp;</td>\n    <td class="coldate">&nbsp;</td>\n   </tr>\n'
    for item in listing:
        if ('subdir' in item):
            subdir = item['subdir'].encode('utf-8')
            if prefix:
                subdir = subdir[len(prefix):]
            body += ('   <tr class="item subdir">\n    <td class="colname"><a href="%s">%s</a></td>\n    <td class="colsize">&nbsp;</td>\n    <td class="coldate">&nbsp;</td>\n   </tr>\n' % (quote(subdir), cgi.escape(subdir)))
    for item in listing:
        if ('name' in item):
            name = item['name'].encode('utf-8')
            if prefix:
                name = name[len(prefix):]
            content_type = item['content_type'].encode('utf-8')
            bytes = human_readable(item['bytes'])
            last_modified = cgi.escape(item['last_modified'].encode('utf-8')).split('.')[0].replace('T', ' ')
            body += ('   <tr class="item %s">\n    <td class="colname"><a href="%s">%s</a></td>\n    <td class="colsize">%s</td>\n    <td class="coldate">%s</td>\n   </tr>\n' % (' '.join((('type-' + cgi.escape(t.lower(), quote=True)) for t in content_type.split('/'))), quote(name), cgi.escape(name), bytes, last_modified))
    body += '  </table>\n </body>\n</html>\n'
    resp = Response(headers=headers, body=body)
    return resp(env, start_response)

dataset/ETHPy150Open openstack/swift/swift/common/middleware/staticweb.py _StaticWebContext._listing/original