Skip to content

Commit db5bc40

Browse files
author
Daniel Kinzler
committed
port handling for VALUE results and improved parameterr checkesw
git-svn-id: https://svn.toolserver.org/svnroot/daniel/duesenstuff/trunk/gpClient@570 9f2c43bc-b3c0-43f4-b155-41619b16f219
1 parent 6c73083 commit db5bc40

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

php/gpClient.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ public function __call($name, $arguments) {
13011301
$map = false;
13021302
}
13031303

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

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

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

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

14481448
$strictArgs = $this->strictArguments;
14491449

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

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

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

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

1598-
if ( $strict ) return preg_match('/^\w[-\w]*$/', $arg); #TODO: port stricter pattern to python
1599-
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
1598+
if ( $strict ) return preg_match('/^\w[-\w]*$/', $arg);
1599+
else return !preg_match('/[\s\0-\x1F\x80-\xFF|<>!&#]/', $arg); //space, low chars, high chars, and operators.
16001600
}
16011601

16021602
/**

python/gp/client.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,15 @@ def exec_command(*arguments):
13861386
else:
13871387
map_it = False
13881388

1389+
if re.search( '-value$', cmd ):
1390+
if capture:
1391+
raise gpUsageException( "using the _value suffix together with the capture_ prefix is meaningless" )
1392+
1393+
cmd = cmd[:-6]
1394+
val = True
1395+
} else {
1396+
val = False
1397+
}
13891398

13901399
result = None
13911400

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

1484-
if status == 'OK':
1493+
if status == 'OK' or status == 'VALUE':
14851494
if self.__command_has_output:
14861495
if map_it:
14871496
return sink.getMap()
@@ -1497,9 +1506,15 @@ def exec_command(*arguments):
14971506
return False
14981507
else:
14991508
if result:
1500-
return result # from handler
1501-
else:
1502-
return status
1509+
status = result # from handler
1510+
1511+
if val:
1512+
if status == "VALUE" or status == "OK":
1513+
return self.statusMessage; #XXX: not so pretty
1514+
else:
1515+
raise gpUsageException( "Can't apply _value modifier: command " + command + " did not return a VALUE or OK status, but this: " + status )
1516+
1517+
return status
15031518

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

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

15721587
strictArgs = self.strictArguments
1588+
1589+
if c == "set-meta" or c == "authorize": #XXX: ugly hack for wellknown commands
1590+
strictArgs = False
1591+
15731592
for c in command:
15741593
if not isinstance(c, (str, unicode, int, long)):
15751594
raise gpUsageException(
@@ -1660,7 +1679,7 @@ def execute(self, command, source=None, sink=None, row_munger=None):
16601679
self.status = match.group(1)
16611680
self.statusMessage = match.group(2).strip()
16621681

1663-
if self.status != 'OK' and self.status != 'NONE':
1682+
if self.status != 'OK' and self.status != 'NONE' and self.status != 'VALUE':
16641683
raise gpProcessorException(
16651684
self.status, self.statusMessage, command)
16661685

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

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

17781797
@staticmethod
17791798
def splitRow(s):

0 commit comments

Comments
 (0)