Skip to content

Commit

Permalink
Commented out gzip support. Prunned subprocess pipe, IO objects creat…
Browse files Browse the repository at this point in the history
…ion. Renamed 2 classes to fall into naming convention.

- Commented out gzip support. IronPython does not have gzip. WSGI PEP333 prescribes that the app itself does not mess with compression and let the server deal with it. I don't want to mess with that at all because the size improvement of using gzip is immaterial because git bundles are already well-packed.
- Prunned the types and quantity of temp file object crated during spawning of subprocess. Specifically, trying to avoid creating IO-likes for stderr and stdin when not needed. This is dangerous in case of stderr as if the output is large, it will block, but we will go on this way, and will deal with problems when they show up.
- Class lister was listing the classes in alphabetical order, not order of appearance. Got tired of that, renamed 2 related classes to start from name of superclass.
  • Loading branch information
dvdotsenko committed Sep 21, 2010
1 parent 3a10b91 commit 0dbdc4a
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions git_http_backend/GitHttpBackend.py
Expand Up @@ -26,13 +26,13 @@
along with git_http_backend.py Project. If not, see <http://www.gnu.org/licenses/>.
'''
import os

import io
import subprocess
import tempfile
try:
import gzip
except:
gzip = False
#try:
# import gzip
#except:
# gzip = False
from wsgiref.headers import Headers

# needed for WSGI Selector
Expand Down Expand Up @@ -121,17 +121,17 @@ def package_response(self, outIO, environ, start_response, headers = []):
# that i would not have to relocate data from tempfile to gzip temp file, but
# subprocess.Popen(... stdout = gzIO, ...) spills both, compressed and uncompressed
# command output into gzIO's underlying fileno. Ugh! You just can't do the right thing around here...
if self.gzip_response and gzip and bool( (environ.get('HTTP_ACCEPT_ENCODING') or '').find('gzip') > -1 ):
outIO.seek(0,2)
if outIO.tell() > 1024:
_file_out = tempfile.SpooledTemporaryFile(max_size=self.tmp_file_buffer_size, mode='w+b')
_zfile = gzip.GzipFile(mode = 'wb', fileobj = _file_out)
outIO.seek(0)
_zfile.writelines(outIO)
_zfile.close()
outIO.close()
outIO = _file_out
headersIface['Content-Encoding'] = 'gzip'
# if self.gzip_response and gzip and bool( (environ.get('HTTP_ACCEPT_ENCODING') or '').find('gzip') > -1 ):
# outIO.seek(0,2)
# if outIO.tell() > 1024:
# _file_out = tempfile.SpooledTemporaryFile(max_size=self.tmp_file_buffer_size, mode='w+b')
# _zfile = gzip.GzipFile(mode = 'wb', fileobj = _file_out)
# outIO.seek(0)
# _zfile.writelines(outIO)
# _zfile.close()
# outIO.close()
# outIO = _file_out
# headersIface['Content-Encoding'] = 'gzip'

outIO.seek(0)

Expand Down Expand Up @@ -389,15 +389,14 @@ def get_command_output(self, cmd,
else:
_internal_stderr = False

_c = subprocess.Popen(cmd, bufsize = 1, stdin = stdin, stdout = stdout, stderr = stderr)
_return_code = _c.wait()
_c = subprocess.Popen(cmd, bufsize = -1, stdin = stdin, stdout = stdout, stderr = stderr)
if _internal_stdin:
_c.stdin.close()
_return_code = _c.wait()
if _internal_stderr:
if _c.stderr.tell():
_c.stderr.read()
stderr = _c.stderr

return stdout, stderr, _return_code
return stdout, stderr , _return_code

def basic_checks(self, dataObj, environ, start_response):
'''
Expand Down Expand Up @@ -474,7 +473,7 @@ def basic_checks(self, dataObj, environ, start_response):
dataObj['repo_path'] = repo_path
return None

class GitInfoRefsHandler(GitHTTPBackendBase):
class GitHTTPBackendInfoRefs(GitHTTPBackendBase):
'''
Implementation of a WSGI handler (app) specifically capable of responding
to git-http-backend (Git Smart HTTP) /info/refs call over HTTP GET.
Expand Down Expand Up @@ -528,7 +527,7 @@ def __call__(self, environ, start_response):
return self.canned_handlers(environ, start_response, 'execution_failed')
return self.package_response(stdout, environ, start_response, headers)

class SmartHTTPRPCHandler(GitHTTPBackendBase):
class GitHTTPBackendSmartHTTP(GitHTTPBackendBase):
'''
Implementation of a WSGI handler (app) specifically capable of responding
to git-http-backend (Git Smart HTTP) RPC calls sent over HTTP POST.
Expand Down Expand Up @@ -637,8 +636,8 @@ def assemble_WSGI_git_app(path_prefix = '.', repo_uri_marker = '', performance_s

selector = WSGIHandlerSelector()
generic_handler = StaticWSGIServer(**settings)
git_inforefs_handler = GitInfoRefsHandler(**settings)
git_rpc_handler = SmartHTTPRPCHandler(**settings)
git_inforefs_handler = GitHTTPBackendInfoRefs(**settings)
git_rpc_handler = GitHTTPBackendSmartHTTP(**settings)

if repo_uri_marker:
marker_regex = r'(?P<decorative_path>.*?)(?:/'+ repo_uri_marker + ')'
Expand Down Expand Up @@ -734,7 +733,6 @@ def assemble_WSGI_git_app(path_prefix = '.', repo_uri_marker = '', performance_s
http://localhost/.git/
This allows GitHttpBackend.py to be "self-serving" :)
'''
import os
import sys

command_options = {
Expand Down

0 comments on commit 0dbdc4a

Please sign in to comment.