From jeroen.vloothuis at pareto.nl Thu Apr 13 15:32:33 2006 From: jeroen.vloothuis at pareto.nl (Jeroen Vloothuis) Date: Thu Apr 13 15:37:10 2006 Subject: [Tramline-dev] Tramline and not tramlining it all Message-ID: Skipped content of type multipart/alternative-------------- next part -------------- A non-text attachment was scrubbed... Name: tramline.patch Type: text/x-patch Size: 2056 bytes Desc: tramline.patch Url : http://codespeak.net/pipermail/tramline-dev/attachments/20060413/d8745b61/tramline.bin From jeroen.vloothuis at pareto.nl Thu Apr 13 21:30:42 2006 From: jeroen.vloothuis at pareto.nl (Jeroen Vloothuis) Date: Thu Apr 13 21:31:22 2006 Subject: [Tramline-dev] Tramline and not tramlining it all In-Reply-To: References: Message-ID: <20060413193042.GA6951@pareto.nl> Hi, This time I return to you with a complete patch. The explicit handling is nog configurable through a mod_python option. Just stick this above your input filter etc. lines: PythonOption explicit_enable True Note that the True is actually passed as a string. So typing anything there will result in explicitness being enabled. To disable it just leave it our (default Tramline behaviour, nothing changed). Regards, Jeroen -------------- next part -------------- Index: core.py =================================================================== --- core.py (revision 25809) +++ core.py (working copy) @@ -205,6 +205,8 @@ # we use a state pattern where the handle method gets # replaced by the current handle method for this state. self.handle = self.handle_first_boundary + self.vars_to_handle = [] + self._enable_vars='' def pushInput(self, data, out): lines = data.splitlines(True) @@ -253,7 +255,7 @@ self._disposition_options = {} self._content_type = 'text/plain' self._content_type_options = {} - + def handle_headers(self, line, out): out.write(line) if line in ['\n', '\r\n']: @@ -272,7 +274,13 @@ filename = self._disposition_options.get('filename') # if filename is empty, assume no file is submitted and submit # empty file -- don't tramline this special case - if filename is None or not filename: + if out.req.get_options().get('explicit_enable') and \ + self._disposition_options.get('name')=='tramline_enable': + self.handle = self.handle_enable_vars + return + elif (filename is None or not filename) or \ + out.req.get_options().get('explicit_enable') and \ + self._disposition_options.get('name') not in self.vars_to_handle: self.handle = self.handle_data return fd, pathname, file_id = createUniqueFile() @@ -283,6 +291,19 @@ self._previous_line = None self.handle = self.handle_file_data + + def handle_enable_vars(self, line, out): + out.write(line) + if line == self._boundary: + self.init_headers() + self.handle = self.handle_headers + self.vars_to_handle.append(self._enable_vars.strip()) + self._enable_vars='' + elif line == self._last_boundary: + # we should be done + self.handle = None # shouldn't be called again + else: + self._enable_vars+=line def handle_data(self, line, out): out.write(line) Index: tests/data/input6.txt =================================================================== --- tests/data/input6.txt (revision 0) +++ tests/data/input6.txt (revision 0) @@ -0,0 +1,16 @@ +-----------------------------100323068321119442571506749230 +Content-Disposition: form-data; name="tramline_enable" + +test +-----------------------------100323068321119442571506749230 +Content-Disposition: form-data; filename="test.txt"; name="test" +Content-Type: application/octet-stream + +first line +second line + +-----------------------------100323068321119442571506749230 +Content-Disposition: form-data; name="submit" + +submit data +-----------------------------100323068321119442571506749230-- Index: tests/test_core.py =================================================================== --- tests/test_core.py (revision 25809) +++ tests/test_core.py (working copy) @@ -11,6 +11,10 @@ self.headers_out = {} self.main = None self.method = method + self.options = {} + + def get_options(self): + return self.options class Filter: def __init__(self, input, output, is_last=True, method='POST'): @@ -348,6 +352,39 @@ self.assertEquals('foo', d['filename']) + def test_explicit_enabling(self): + # first make sure we fail in normal mode when explicit + # enabling is enabled (boy this term needs something better) + input = open(get_data_path('input2.txt'), 'rb') + output = StringIO() + filter = Filter(input, output) + filter.req.options['explicit_enable'] = True + + inputfilter(filter) + + input.close() + + output_data = output.getvalue() + + file_id = self.file_id(output_data) + self.assert_(not os.path.isfile(os.path.join(tramline_upload_path, file_id))) + + # now go at it again and make sure it works this time + input = open(get_data_path('input6.txt'), 'rb') + output = StringIO() + filter = Filter(input, output) + filter.req.options['explicit_enable'] = True + + inputfilter(filter) + + input.close() + + output_data = output.getvalue() + + file_id = self.file_id(output_data) + self.assert_(os.path.isfile(os.path.join(tramline_upload_path, file_id))) + + def file_id(self, data, start=0): i = data.find('filename', start) if i == -1: From faassen at infrae.com Fri Apr 21 13:27:31 2006 From: faassen at infrae.com (Martijn Faassen) Date: Fri Apr 21 13:25:12 2006 Subject: [Tramline-dev] Tramline and not tramlining it all In-Reply-To: <20060413193042.GA6951@pareto.nl> References: <20060413193042.GA6951@pareto.nl> Message-ID: <4448C1A3.7060309@infrae.com> Jeroen Vloothuis wrote: > Hi, > This time I return to you with a complete patch. The explicit handling > is nog configurable through a mod_python option. Just stick this above > your input filter etc. lines: > > PythonOption explicit_enable True > > Note that the True is actually passed as a string. So typing anything > there will result in explicitness being enabled. To disable it just > leave it our (default Tramline behaviour, nothing changed). Hey, Sorry to get back to you so late. Much improvement, but I'd still like to see an explicit test for this functionality as well. That is, a test that demonstrates that when this option is enabled, everything works as expected (no tramlining of file when no explicit marker, tramlining when explicit marker is present). I don't think such test are there yet, right? Regards, Martijn From faassen at infrae.com Thu Apr 27 14:44:09 2006 From: faassen at infrae.com (Martijn Faassen) Date: Thu Apr 27 14:41:03 2006 Subject: [Tramline-dev] Tramline and not tramlining it all In-Reply-To: <4448C1A3.7060309@infrae.com> References: <20060413193042.GA6951@pareto.nl> <4448C1A3.7060309@infrae.com> Message-ID: <4450BC99.7080900@infrae.com> Martijn Faassen wrote: > Jeroen Vloothuis wrote: > >> Hi, >> This time I return to you with a complete patch. The explicit handling >> is nog configurable through a mod_python option. Just stick this above >> your input filter etc. lines: >> >> PythonOption explicit_enable True >> >> Note that the True is actually passed as a string. So typing anything >> there will result in explicitness being enabled. To disable it just >> leave it our (default Tramline behaviour, nothing changed). > > > Hey, > > Sorry to get back to you so late. Much improvement, but I'd still like > to see an explicit test for this functionality as well. I completely misread the patch and didn't see this explicit test. Sorry about that! Regards, Martijn From jeroen.vloothuis at pareto.nl Thu Apr 27 14:58:00 2006 From: jeroen.vloothuis at pareto.nl (Jeroen Vloothuis) Date: Thu Apr 27 14:58:39 2006 Subject: [Tramline-dev] Configuring Tramline Message-ID: <20060427125800.GE10326@pareto69.pareto.nl> Hi, A few things like paths are now hardcoded in Tramline. These things could/should be made configureable. One thing we could do is place these in the Apache conf using PythonOption statements. Info on these can be found here: http://www.modpython.org/live/mod_python-3.1.2b/doc-html/dir-other-po.html An advantage to using this over external config files would be that this is in the same place as all the other Apache settings. It also should allow for a virtual host setup with multiple distinct Tramline settings. What do you think, should we change the hardcoded settings to use PythonOption's? Regards, Jeroen