From: Tim Pierce Date: Tue, 25 Nov 2014 22:52:05 +0000 (-0500) Subject: 4621: implement lean_uri_escape X-Git-Tag: 1.1.0~1954^2~4 X-Git-Url: https://git.arvados.org/arvados.git/commitdiff_plain/dc706977b754f7b5b0e5835ef80a2b59bc1773f8 4621: implement lean_uri_escape lean_uri_escape implements URI escaping as in URI::Escape, but with substantially less RAM (at the cost of less error checking). Also fixes a bug in crunch-job's strftime call. --- diff --git a/sdk/cli/bin/crunch-job b/sdk/cli/bin/crunch-job index 0d35d53f9d..0265a4862f 100755 --- a/sdk/cli/bin/crunch-job +++ b/sdk/cli/bin/crunch-job @@ -1702,7 +1702,7 @@ sub api_call { if ($next_try_at < time) { $retry_msg = "Retrying."; } else { - my $next_try_fmt = strftime("%Y-%m-%d %H:%M:%S", $next_try_at); + my $next_try_fmt = strftime("%Y-%m-%d %H:%M:%S", localtime($next_try_at)); $retry_msg = "Retrying at $next_try_fmt."; } Log(undef, "API method $method_name failed: $errmsg. $retry_msg"); diff --git a/sdk/perl/lib/Arvados/Request.pm b/sdk/perl/lib/Arvados/Request.pm index 07ca763d2b..f2a9b63631 100644 --- a/sdk/perl/lib/Arvados/Request.pm +++ b/sdk/perl/lib/Arvados/Request.pm @@ -49,9 +49,9 @@ sub process_request my $content; while (($p, $v) = each %content) { $content .= '&' unless $content eq ''; - $content .= uri_escape($p); + $content .= lean_uri_escape($p); $content .= '='; - $content .= uri_escape($v); + $content .= lean_uri_escape($v); } $self->{'req'}->content_type("application/x-www-form-urlencoded; charset='utf8'"); $self->{'req'}->content(Encode::encode('utf8', $content)); @@ -94,4 +94,12 @@ sub get_headers "" } +# lean_uri_escape consumes about half as much memory +# as URI::Escape::uri_escape. +sub lean_uri_escape { + my ($text) = @_; + $text =~ s/([^A-Za-z0-9\-\._~])/$URI::Escape::escapes{$&}/ge; + return $text; +} + 1;