Skip to content

Commit

Permalink
port handling for VALUE results and improved parameterr checkesw
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.toolserver.org/svnroot/daniel/duesenstuff/trunk/gpClient@570 9f2c43bc-b3c0-43f4-b155-41619b16f219
  • Loading branch information
Daniel Kinzler committed Jan 3, 2012
1 parent 6c73083 commit db5bc40
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
14 changes: 7 additions & 7 deletions php/gpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ public function __call($name, $arguments) {
$map = false;
}

if ( preg_match( '/-value$/', $cmd ) ) { #TODO: port to python
if ( preg_match( '/-value$/', $cmd ) ) {
if ($capture) throw new gpUsageException( "using the _value suffix together with the capture_ prefix is meaningless" );

$cmd = substr( $cmd, 0, strlen($cmd) -6 );
Expand Down Expand Up @@ -1367,7 +1367,7 @@ public function __call($name, $arguments) {

//note: call modifiers like "_capture" change the return type!
if ( $capture ) {
if ( $status == 'OK' || $status == 'VALUE' ) { #TODO: port VALUE to python
if ( $status == 'OK' || $status == 'VALUE' ) {
if ( $has_output ) {
if ($map) return $sink->getMap();
else return $sink->getData();
Expand All @@ -1380,7 +1380,7 @@ public function __call($name, $arguments) {
} else {
if ( $result ) $status = $result; // from handler

if ( $val ) { #TODO: port to python!
if ( $val ) {
if ( $status == "VALUE" || $status == "OK" ) {
return $this->statusMessage; #XXX: not so pretty
} else {
Expand Down Expand Up @@ -1447,7 +1447,7 @@ public function exec( $command, gpDataSource $source = null, gpDataSink $sink =

$strictArgs = $this->strictArguments;

if ( $c == "set-meta" || $c == "authorize" ) { #XXX: ugly hack for wellknown commands #TODO: port to python
if ( $c == "set-meta" || $c == "authorize" ) { #XXX: ugly hack for wellknown commands
$strictArgs = false;
}

Expand Down Expand Up @@ -1526,7 +1526,7 @@ public function exec( $command, gpDataSource $source = null, gpDataSink $sink =
$this->status = $m[1];
$this->statusMessage = trim($m[2]);

if ( $this->status != 'OK' && $this->status != 'NONE' && $this->status != 'VALUE' ) { #TODO: port VALUE to python
if ( $this->status != 'OK' && $this->status != 'NONE' && $this->status != 'VALUE' ) {
throw new gpProcessorException( $this->status, $m[2], $command );
}

Expand Down Expand Up @@ -1595,8 +1595,8 @@ public static function isValidCommandString( $command ) {
public static function isValidCommandArgument( $arg, $strict = true ) {
if ( $arg === '' || $arg === false || $arg === null ) return false;

if ( $strict ) return preg_match('/^\w[-\w]*$/', $arg); #TODO: port stricter pattern to python
else return !preg_match('/[\s\0-\x1F\x80-\xFF|<>!&#]/', $arg); //space, low chars, high chars, and operators. #TODO: port exclusion of spaces and inclusion of colons to python
if ( $strict ) return preg_match('/^\w[-\w]*$/', $arg);
else return !preg_match('/[\s\0-\x1F\x80-\xFF|<>!&#]/', $arg); //space, low chars, high chars, and operators.
}

/**
Expand Down
37 changes: 28 additions & 9 deletions python/gp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,15 @@ def exec_command(*arguments):
else:
map_it = False

if re.search( '-value$', cmd ):
if capture:
raise gpUsageException( "using the _value suffix together with the capture_ prefix is meaningless" )

cmd = cmd[:-6]
val = True
} else {
val = False
}

result = None

Expand Down Expand Up @@ -1481,7 +1490,7 @@ def exec_command(*arguments):
#note: call modifiers like capture change the return type!
if capture:

if status == 'OK':
if status == 'OK' or status == 'VALUE':
if self.__command_has_output:
if map_it:
return sink.getMap()
Expand All @@ -1497,9 +1506,15 @@ def exec_command(*arguments):
return False
else:
if result:
return result # from handler
else:
return status
status = result # from handler

if val:
if status == "VALUE" or status == "OK":
return self.statusMessage; #XXX: not so pretty
else:
raise gpUsageException( "Can't apply _value modifier: command " + command + " did not return a VALUE or OK status, but this: " + status )

return status

setattr(self, name, exec_command) #re-use closure!

Expand Down Expand Up @@ -1570,6 +1585,10 @@ def execute(self, command, source=None, sink=None, row_munger=None):
raise gpUsageException("invalid command name: %s" % c)

strictArgs = self.strictArguments

if c == "set-meta" or c == "authorize": #XXX: ugly hack for wellknown commands
strictArgs = False

for c in command:
if not isinstance(c, (str, unicode, int, long)):
raise gpUsageException(
Expand Down Expand Up @@ -1660,7 +1679,7 @@ def execute(self, command, source=None, sink=None, row_munger=None):
self.status = match.group(1)
self.statusMessage = match.group(2).strip()

if self.status != 'OK' and self.status != 'NONE':
if self.status != 'OK' and self.status != 'NONE' and self.status != 'VALUE':
raise gpProcessorException(
self.status, self.statusMessage, command)

Expand Down Expand Up @@ -1770,10 +1789,10 @@ def isValidCommandArgument(arg, strict=True): #static #OK
return False

if strict:
return re.match('^\w[-\w]*(:\w[-\w]*)?$', str(arg))
#XXX: the ":" is needed for user:passwd auth. not pretty.
return( not re.search('[\0-\x1F\x80-\xFF:|<>!&#]', str(arg)))
# low chars, high chars, and operators.
return re.match('^\w[-\w]*$', str(arg))
else:
return not re.search('[\s\0-\x1F\x80-\xFF|<>!&#]', str(arg))
# low chars, high chars, and operators.

@staticmethod
def splitRow(s):
Expand Down

0 comments on commit db5bc40

Please sign in to comment.