def test_store_creation(self): from com.hp.hpl.jena.tdb import TDBFactory from java.io import ByteArrayInputStream from java.lang import String db_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'OAC-testing.tdb') dataset = TDBFactory.createDataset(db_path) # Make sure the store was created assert os.path.isdir(db_path) # Make InputStream triples rdf_text = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="info:fedora/changeme:651"><rdf:type rdf:resource="oa:Annotation"></rdf:type><oa:hasBody xmlns:oa="http://www.w3.org/ns/openannotation/core/" rdf:resource="info:fedora/changeme:650"></oa:hasBody><oa:modelVersion xmlns:oa="http://www.w3.org/ns/openannotation/core/" rdf:resource="http://www.openannotation.org/spec/core/20120509.html"></oa:modelVersion><oa:generated xmlns:oa="http://www.w3.org/ns/openannotation/core/">2012-06-07T03:50:55.993000Z</oa:generated></rdf:Description><rdf:Description rdf:about="info:fedora/changeme:650"><rdf:type rdf:resource="oa:Body"></rdf:type><dc:format xmlns:dc="http://purl.org/dc/elements/1.1/">text/xml</dc:format></rdf:Description></rdf:RDF>' rdfxml = String(rdf_text) input_stream = ByteArrayInputStream(rdfxml.getBytes()) model = dataset.getDefaultModel() model.begin() model.read(input_stream, None) model.commit() model.close() # Were all of the triples added? assert model.size() == 6 shutil.rmtree(db_path) # Was the store removed? assert not os.path.isdir(db_path)
def __activate__(self, context): # Prepare variables self.index = context["fields"] self.object = context["object"] self.payload = context["payload"] self.params = context["params"] self.utils = context["pyUtils"] self.config = context["jsonConfig"] self.wfSecurityExceptions = None self.message_list = None # Because the workflow messaging system wants access to this data # BEFORE it actual hits the index we are going to cache it into an # object payload too. self.directIndex = JsonSimple() # Common data self.__newDoc() #print "+++ direct-files.py - itemType='%s'" % self.itemType # Real metadata if self.itemType == "object": self.__previews() self.__basicData() self.__metadata() # Update the 'direct.index' payload - BEFORE messages are sent directString = String(self.directIndex.toString()) inStream = ByteArrayInputStream(directString.getBytes("UTF-8")) try: StorageUtils.createOrUpdatePayload(self.object, "direct.index", inStream) except StorageException, e: print " * direct-files.py : Error updating direct payload" self.__messages() self.__displayType()
def __call__(self): """ A Python object is callable if it defines a __call__ method. Each worker thread performs a number of runs of the test script, as configured by the property grinder.runs. For each run, the worker thread calls its TestRunner; thus the __call__ method can be thought of as the definition of a run. """ # Normally test results are reported automatically when the test returns. If you want to # alter the statistics after a test has completed, you must set delayReports = 1 to delay # the reporting before performing the test. This only affects the current worker thread. grinder.statistics.delayReports = 1 msg = te_message.Message( "1.0", "20111020153610", 200, None, "GPE-111", 111, "OPERATOR-111", "00000000001", None, request_msgbody ) # print("******hello" + str(type(msg))) # print("msg.raw_body" + msg.raw_body) # print("des:" + msg.encrypted_body) body = String(msg.encrypted_body) response = request.POST(CONF_url, body.getBytes(), msg.assemble_nvpairs()) code = int(response.getHeader("X-Response-Code")) # verify response status if 200 != code: print("------------------------------------ERROR: %d" % code) # Set success = 0 to mark the test as a failure. grinder.statistics.forLastTest.setSuccess(0) else: print("------------------------------------PASS!")
def checkInbox(): for message in voice.sms().messages: if not message.isRead: n=message.phoneNumber msgtxt = str(message.messageText) txtarray = msgtxt.split(" ") print txtarray if len(txtarray) > 2: e = String(txtarray[0]) #print e key = txtarray[1] #print key code = ' '.join([str(x) for x in txtarray[2:len(txtarray)]]) #print code if e.equalsIgnoreCase("encode"): coded = encrypt(code, key) #print "Coded message" if len(coded) < 140: postToTwitter(coded) returnText(n, "Posted to Twitter: "+coded) else: returnText(n, "Coded message too long") elif e.equalsIgnoreCase("decode"): uncoded = decrypt(code, key) #print "Decoded message" returnText(n, "Uncoded text: "+uncoded) else: returnText(n, "Unable to parse input text message") message.delete() time.sleep(10)
def test_null_pointer_exception(self): try: # throws http://stackoverflow.com/questions/3131865/why-does-string-valueofnull-throw-a-nullpointerexception String.valueOf(None) except Exception as ex: # because it's not a checked exception, mapped exceptions doesn't apply here (all Runtime) self.assertIn('java.lang.NullPointerException', str(ex.message))
def __init__(self, Framework): Netlinks_Service.NetlinksService.__init__(self, Framework) shouldIgnoreLocal = self.getParameterValue('ignoreLocalConnections') if shouldIgnoreLocal == None: shouldIgnoreLocal = 'false' self.ignoreLocalConnections = Boolean.parseBoolean(shouldIgnoreLocal) self.dependencyNameIsKey = modeling.checkIsKeyAttribute('dependency', 'dependency_name') self.dependencySourceIsKey = modeling.checkIsKeyAttribute('dependency', 'dependency_source') ignoredIpsList = self.getParameterValue('ignoredIps') self.ignoredIps = None if ignoredIpsList != None: ipPatterns = ignoredIpsList.split(',') if (len(ipPatterns) > 0) and (ipPatterns[0] != ''): for ipPattern in ipPatterns: pattern = String(ipPattern) pattern = String(pattern.replaceAll("\.", "\\\.")) pattern = String(pattern.replaceAll("\*", "\\\d+")) try: m = Pattern.compile(pattern) if self.ignoredIps == None: self.ignoredIps = ArrayList() self.ignoredIps.add(m) except: logger.debug('Failed to compile ip pattern:', ipPattern) self.initializeServices()
def __formData(self): # Find our workflow form data packagePid = None try: self.pidList = self.object.getPayloadIdList() for pid in self.pidList: if pid.endswith(self.packagePidSuffix): packagePid = pid except StorageException: self.log.error("Error accessing object PID list for object '{}' ", self.oid) return if packagePid is None: self.log.debug("Object '{}' has no form data", self.oid) return # Retrieve our form data workflowData = None try: payload = self.object.getPayload(packagePid) try: workflowData = JsonSimple(payload.open()) except Exception: self.log.error("Error parsing JSON '{}'", packagePid) finally: payload.close() except StorageException: self.log.error("Error accessing '{}'", packagePid) return # Test our version data self.version = workflowData.getString("{NO VERSION}", ["redbox:formVersion"]) oldData = String(workflowData.toString(True)) if self.version != self.redboxVersion: self.log.info("OID '{}' requires an upgrade: '{}' => '{}'", [self.oid, self.version, self.redboxVersion]) # The version data is old, run our upgrade # function to see if any alterations are # required. Most likely at least the # version number will change. newWorkflowData = self.__upgrade(workflowData) else: newWorkflowData = self.__hotfix(workflowData) if newWorkflowData is not None: self.log.debug("OID '{}' was hotfixed for v1.2 'dc:type' bug", self.oid) else: self.log.debug("OID '{}' requires no work, skipping", self.oid) return # Backup our data first backedUp = self.__backup(oldData) if not backedUp: self.log.error("Upgrade aborted, data backup failed!") return # Save the newly modified data jsonString = String(newWorkflowData.toString(True)) inStream = ByteArrayInputStream(jsonString.getBytes("UTF-8")) try: self.object.updatePayload(packagePid, inStream) except StorageException, e: self.log.error("Error updating workflow payload: ", e)
def getTFPackagePid(self,oid): digitalObject = StorageUtils.getDigitalObject(self.storage,oid) for pid in digitalObject.getPayloadIdList(): pidString = String(pid) if pidString.endsWith("tfpackage"): return pid return None
def __saveManifest(self, oid): object = self.services.getStorage().getObject(oid) sourceId = object.getSourceId() manifestStr = String(self.__manifest.toString()) object.updatePayload(sourceId, ByteArrayInputStream(manifestStr.getBytes("UTF-8"))) object.close()
def getDistributors(self,oshv,sqlServerId): #is there is a chance that we have more than one distributor? rs = self.connection.doCall(Queries.SERVER_DIST_CALL) distributor = None databaseName = None while rs.next(): name = rs.getString('distributor') if(name is None): rs.close() return None databaseName = rs.getString('distribution database') max = int(rs.getInt('max distrib retention')) min = int(rs.getInt('min distrib retention')) history = int(rs.getInt('history retention')) cleanup = String(rs.getString('history cleanup agent')) idx = cleanup.indexOf('Agent history clean up:') if(idx>=0): cleanup=cleanup.substring(len("Agent history clean up:")) distributor = ObjectStateHolder('sqlserverdistributor') sqlServer = self.createSqlServer(name,oshv,sqlServerId) distributor.setContainer(sqlServer) distributor.setAttribute(Queries.DATA_NAME,name) distributor.setIntegerAttribute('maxTxRetention',max) distributor.setIntegerAttribute('minTxRetention',min) distributor.setIntegerAttribute('historyRetention',history) distributor.setAttribute('cleanupAgentProfile',cleanup) oshv.add(sqlServer) oshv.add(distributor) database = self.getDatabase(sqlServer,databaseName) oshv.add(database) oshv.add(modeling.createLinkOSH('use',distributor,database)) rs.close() if(distributor!=None): logger.debug('we got a distributor') return [distributor,databaseName]
def sortResultsByCode(self): tempMap = HashMap() for result in self.__results: uri = String(self.getValue(result, "dc_identifier")) lastIndex = uri.lastIndexOf('/') + 1 code = uri.substring(lastIndex) tempMap.put(code, result) self.resultsByCode = TreeMap(tempMap)
def read_methods(file): names = {} for line in file: nline = line.strip() jstr = String(nline) hcode = jstr.hashCode() names[hcode] = nline return names
def test_null_pointer_exception(self): try: # throws http://stackoverflow.com/questions/3131865/why-does-string-valueofnull-throw-a-nullpointerexception String.valueOf(None) except Exception as ex: # because it's not a checked exception, mapped exceptions doesn't apply here (all Runtime) if not jep.USE_MAPPED_EXCEPTIONS: self.assertEquals(ex.java_name, 'java.lang.NullPointerException')
def __saveWorkflowMetadata(self, oid): object = self.services.getStorage().getObject(oid) manifestStr = String(self.__workflowMetadata.toString()) object.updatePayload("workflow.metadata", ByteArrayInputStream(manifestStr.getBytes("UTF-8"))) object.close() self.__indexer.index(oid) self.__indexer.commit()
def test_override(self): class Foo(Runnable): def toString(self): return "Foo" self.assertEquals(String.valueOf(Foo()), "Foo", "toString not overridden in interface") class A(Object): def toString(self): return 'name' self.assertEquals('name', String.valueOf(A()), 'toString not overriden in subclass')
def _getXmlRootFromString(self, xmlString): """ Parses string xml representation and returns root element str->Element @raise JavaException: XML parsing failed """ xmlString = ''.join([line.strip() for line in xmlString.split('\n') if line]) strContent = String(xmlString) return SAXBuilder().build(ByteArrayInputStream(strContent.getBytes('utf-8'))).getRootElement()
def evaluate(self,arguments,field,format): from java.lang import String flag=true values=field.getValues() for value in values: argument=String(value) arguments.append(argument) if not argument.matches(format): flag=false return flag
def decodeMessage(wrapper, message): result = "" decoded = Base64.decodeBase64(message) try: Z = String(decoded, "UTF-8") result = Z.split(wrapper)[1] except Exception as ex: # Error decoding a Tango message. pass return result
def test_call_static_methods(self): s1 = String.valueOf(['1', '2', '3']) s2 = String.valueOf('123') s3 = String.valueOf(123) s4 = String.valueOf(123) s5 = String.valueOf(['0', '1', '2', '3', 'a', 'b'], 1, 3) self.assertEqual(s1, s2) self.assertEqual(s1, s3) self.assertEqual(s1, s4) self.assertEqual(s1, s5)
def resolveEntity(self, name, publicId, baseURI, systemId): logger.debug("XMLExternalEntityResolver resolveEntity, name : ", name, ", publicId: ", publicId, ", baseURI: ", baseURI, ", systemId: ", systemId ) try: filename = systemId logger.debug('resolveEntity, file name: ', filename, ", path: ", self.remotePath) strContent = String( self.fileMonitor.getFileContent(self.remotePath + self.fsSeparator + filename ) ) return InputSource( ByteArrayInputStream( strContent.getBytes() ) ) except Exception, ex: logger.debug("XMLExternalEntityResolver Exception: ", ex )
def encrypt(self, pystrPlaintext): try: plaintext = JavaString(pystrPlaintext) keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES") key = keyFactory.generateSecret(PBEKeySpec(self.PASSWORD)) pbeCipher = Cipher.getInstance("PBEWithMD5AndDES") paramSpec = PBEParameterSpec(self.SALT, 20) pbeCipher.init(Cipher.ENCRYPT_MODE, key, paramSpec) return self._base64Encode(pbeCipher.doFinal(plaintext.getBytes())) except: raise
def test_bigtest03(self): '''Get recids_hm_strstr''' message = self.bridge.createMessage('bigtest') \ .setParam('action', 'recids_hm_strstr') \ .setParam('size', self.size) self.bridge.sendMessage(message) res = HashMap.cast_(message.getResults()) assert res.size() == self.size assert str(String.cast_(res.get('0'))) == '0' assert str(String.cast_(res.get('5'))) == '5'
def _create_xacml_role_mapper_entries(self, role_expressions_map): _method_name = '_create_xacml_role_mapper_entries' self.logger.entering(class_name=self.__class_name, method_name=_method_name) entries = {} if role_expressions_map is not None: try: for role_name in role_expressions_map.keys(): # Get the role expression role_expression = role_expressions_map[role_name] # Convert the role expression policy = self._converter.convertRoleExpression( None, role_name, role_expression, None) role = self._escaper.escapeString(role_name) cn = self._escaper.escapeString(policy.getId().toString()) xacml = self._b64encoder.encodeBuffer( String(policy.toString()).getBytes("UTF-8")) # Setup the lines that make up the role entry entry = [] entry.append( 'dn: cn=' + cn + '+xacmlVersion=1.0,ou=Policies,ou=XACMLRole,ou=@realm@,dc=@domain@\n' ) entry.append('objectclass: top\n') entry.append('objectclass: xacmlEntry\n') entry.append('objectclass: xacmlRoleAssignmentPolicy\n') entry.append('cn: ' + cn + '\n') entry.append('xacmlVersion: 1.0\n') entry.append('xacmlStatus: 3\n') entry.append('xacmlDocument:: ' + xacml + '\n') entry.append('xacmlRole: ' + role + '\n') entry.append('\n') # Add to the map of role entries entries[role] = entry except DocumentParseException, dpe: ex = exception_helper.create_exception( self._exception_type, 'WLSDPLY-01804', role_name, role_expression, dpe.getLocalizedMessage(), error=dpe) self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name) raise ex except URISyntaxException, use: ex = exception_helper.create_exception( self._exception_type, 'WLSDPLY-01804', role_name, role_expression, use.getLocalizedMessage(), error=use) self.logger.throwing(ex, class_name=self.__class_name, method_name=_method_name) raise ex
def create_readme_file(connection, workspace_path, variables): if variables['create_in_github_organization']: path = variables['github_organization'] else: path = variables['github_username'] contents='''# %s [![Build Status](https://travis-ci.org/%s/%s.svg?branch=master)](https://travis-ci.org/%s/%s) [REPLACE ME WITH CODACY BADGE](https://www.codacy.com) [![Code Climate](https://codeclimate.com/github/%s/%s/badges/gpa.svg)](https://codeclimate.com/github/%s/%s) [![License: MIT][%s-license-image] ][%s-license-url] [![Github All Releases][%s-downloads-image]]() [%s-license-image]: https://img.shields.io/badge/License-MIT-yellow.svg [%s-license-url]: https://opensource.org/licenses/MIT [%s-downloads-image]: https://img.shields.io/github/downloads/xebialabs-community/%s/total.svg ## Preface ## Overview ## Installation ## References ''' % (variables['github_repo_name'], path, variables['github_repo_name'], path, variables['github_repo_name'], path, variables['github_repo_name'], path, variables['github_repo_name'], variables['github_repo_name'], variables['github_repo_name'], variables['github_repo_name'], variables['github_repo_name'], variables['github_repo_name'], variables['github_repo_name'], variables['github_repo_name'],) repo_directory=OverthereUtils.constructPath(connection.getFile(workspace_path), '%s' % variables['github_repo_name']) readme_file=connection.getFile(OverthereUtils.constructPath(connection.getFile(repo_directory), 'README.md')) OverthereUtils.write(String(contents).getBytes(), readme_file)
def rshCommand(env, hostname, username, identityFileFullPath, password, _command): command = _command print 'On Server :' + hostname + ' RSH issuing command: >' + _command + '<' if (String(identityFileFullPath).contains(':') or String(identityFileFullPath).contains('\\') or String(identityFileFullPath).contains('/')): output = execSshRemote(hostname, username, identityFileFullPath, password, command) else: output = execSshRemoteUsrPwd(hostname, username, password, command) print 'On Server :' + hostname + ' RSH Returned: ' + output return output
def _build_mapping_hash(self, mapping_type, mapping_name, mapping): """ Build a template hash for the specified mapping element from the model. :param mapping_type: the type of the mapping, such as 'CrossDomain' :param mapping_name: the mapping name from the model, such as 'map1' :param mapping: the mapping element from the model :return: the template hash """ resource_name = self._build_resource_name(mapping_type, mapping_name, mapping) remote_user = self._get_required_attribute(mapping, REMOTE_USER, mapping_type, mapping_name) credential_cn = self._create_cn(resource_name, remote_user) # the password needs to be encrypted, then base64 encoded password = self._get_required_attribute(mapping, REMOTE_PASSWORD, mapping_type, mapping_name) encrypted = self._weblogic_helper.encrypt( password, self._model_context.get_domain_home()) password_encoded = self._b64_encoder.encodeBuffer( String(encrypted).getBytes("UTF-8")) # the local user and resource CN will be updated later for each user return { HASH_CREDENTIAL_CN: credential_cn, HASH_LOCAL_USER: NULL, HASH_PASSWORD_ENCODED: password_encoded, HASH_REMOTE_USER: remote_user, HASH_RESOURCE_CN: NULL, HASH_RESOURCE_NAME: resource_name }
def _decode_from_file_system(self, arg): encoding = sys.getfilesystemencoding() if sys.platform.startswith('java'): # http://bugs.jython.org/issue1592 from java.lang import String arg = String(arg) return unic(arg, encoding) if encoding else unic(arg)
def create_build_gradle_file(connection, workspace_path, variables): contents = '''plugins { id "com.github.hierynomus.license" version "0.13.0" } defaultTasks 'build' apply plugin: 'java' apply plugin: 'idea' apply plugin: 'eclipse' apply plugin: 'maven' version='%s' license { header rootProject.file('License.md') strictCheck false excludes(["**/*.json"]) ext.year = Calendar.getInstance().get(Calendar.YEAR) ext.name = 'XEBIALABS' } ''' % variables['initial_version'] repo_directory = OverthereUtils.constructPath( connection.getFile(workspace_path), '%s' % variables['github_repo_name']) build_gradle_file = connection.getFile( OverthereUtils.constructPath(connection.getFile(repo_directory), 'build.gradle')) OverthereUtils.write(String(contents).getBytes(), build_gradle_file)
def __process_args(args): """ Process the command-line arguments and prompt the user for any missing information :param args: the command-line arguments list :raises CLAException: if an error occurs while validating and processing the command-line arguments """ _method_name = '__process_args' cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments) required_arg_map, optional_arg_map = cla_util.process_args(args) __verify_required_args_present(required_arg_map) __validate_mode_args(optional_arg_map) __process_passphrase_arg(optional_arg_map) # # Prompt for the password to encrypt if the -manual switch was specified # if CommandLineArgUtil.ENCRYPT_MANUAL_SWITCH in optional_arg_map and \ CommandLineArgUtil.ONE_PASS_SWITCH not in optional_arg_map: try: pwd = getcreds.getpass('WLSDPLY-04200') except IOException, ioe: ex = exception_helper.create_encryption_exception( 'WLSDPLY-04201', ioe.getLocalizedMessage(), error=ioe) __logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex optional_arg_map[CommandLineArgUtil.ONE_PASS_SWITCH] = String(pwd)
def _encrypt_variable_value(passphrase, dict_name, field_name, var_name, variables): """ Encrypt the variable value. :param passphrase: the encryption passphrase :param dict_name: the model element name :param field_name: the attribute name :param var_name: the variable name :param variables: the variables :return: the number of variable changes """ _method_name = '_encrypt_variable_value' variable_changes = 0 if variables is None: return variable_changes if var_name in variables: var_value = variables[var_name] if len(var_value) > 0: encrypted_value = EncryptionUtils.encryptString(var_value, String(passphrase).toCharArray()) variables[var_name] = encrypted_value _logger.fine('WLSDPLY-04106', dict_name, field_name, var_name, class_name=_class_name, method_name=_method_name) variable_changes = 1 else: ex = exception_helper.create_encryption_exception('WLSDPLY-04107', var_name, field_name, dict_name) _logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex return variable_changes
def log_plot(self, plot, name=None, footer=None): if name == None: name = "Scripting plot" if not plot is None and hasattr(plot, 'pv'): if footer is None: if hasattr(plot, 'title'): footer = plot.title try: self.logger.appendImageEntry(name, plot.pv.getPlot().getImage(), footer) except: print 'failed to send plot to notebook db' elif not plot is None and hasattr(plot, 'cache'): if footer is None: if hasattr(plot, 'title'): footer = plot.title try: from org.apache.commons.codec.binary import Base64 from java.lang import String self.logger.appendImageEntry( name, String(Base64.encodeBase64(plot.cache.getImageCache())), footer) except: print 'failed to send plot to notebook db'
def prepareForStep(self, configurationAttributes, requestParameters, step): print "BioID. Prepare for step called : step %s" % step if step == 1: return True elif step == 2 or step == 3: identity = CdiUtil.bean(Identity) user_name = identity.getWorkingParameter("user_name") auth_method = identity.getWorkingParameter("bioID_auth_method") print "BioID. step %s %s" % (step, auth_method) bcid = self.STORAGE + "." + self.PARTITION + "." + str(String(user_name).hashCode()) print "bcid %s" %bcid if step == 2 and auth_method == 'enrollment': print "access token used by upload method - enroll" access_token = self.getAccessToken( bcid, "enroll" ) # either step2 and verification or step 3 which is verification post enrollment else: print "access token used by upload method - verify" access_token = self.getAccessToken( bcid, "verify" ) print "access_token %s - " % access_token identity.setWorkingParameter("access_token",access_token) return True else: return False
def addDataLinage(key,filename,value): if data_linage.getProperty(key) is None: data_linage.setProperty(key,filename + ' [Value=' + value + ']') else: # Simple bit of code that stops it adding the same file twice if String(data_linage.getProperty(key)).indexOf(filename) != 0: data_linage.setProperty(key,filename + ' [Value=' + value + ']' + ' --> \r\n Inherited From : ' + data_linage.getProperty(key))
def decode_from_system(string, can_be_from_java=True): """Decodes bytes from system (e.g. cli args or env vars) to Unicode.""" if sys.platform.startswith('java') and can_be_from_java: # http://bugs.jython.org/issue1592 from java.lang import String string = String(string) return unic(string, SYSTEM_ENCODING)
def __process_passphrase_arg(optional_arg_map): """ Prompt for the passphrase. :param optional_arg_map: the optional arguments map :raises CLAException: if an error occurs reading the passphrase input from the user """ _method_name = '__process_passphrase_arg' if CommandLineArgUtil.PASSPHRASE_SWITCH not in optional_arg_map: got_matching_passphrases = False while not got_matching_passphrases: try: passphrase = getcreds.getpass('WLSDPLY-04203') passphrase2 = getcreds.getpass('WLSDPLY-04204') except IOException, ioe: ex = exception_helper.create_encryption_exception( 'WLSDPLY-04205', ioe.getLocalizedMessage(), error=ioe) __logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex if passphrase == passphrase2: got_matching_passphrases = True optional_arg_map[ CommandLineArgUtil.PASSPHRASE_SWITCH] = String(passphrase)
def __activate__(self, context): try: self.log = context["log"] self.response = context["response"] self.request = context["request"] self.systemConfig = context["systemConfig"] self.storage = context["Services"].getStorage() self.indexer = context["Services"].getIndexer() self.sessionState = context["sessionState"] self.sessionState.set("username", "admin") out = self.response.getPrintWriter("text/plain; charset=UTF-8") relationshipMapper = ApplicationContextProvider.getApplicationContext().getBean("relationshipMapper") externalCurationMessageBuilder = ApplicationContextProvider.getApplicationContext().getBean("externalCurationMessageBuilder") oid = self.request.getParameter("oid") if oid is None : identifier = self.request.getParameter("identifier") oid = self.findOidByIdentifier(identifier) relationshipType = self.request.getParameter("relationship") curatedPid = self.request.getParameter("curatedPid") sourceId = self.request.getParameter("sourceIdentifier") digitalObject = StorageUtils.getDigitalObject(self.storage, oid) metadataJson = self.getTfPackage(digitalObject) relationships = metadataJson.getArray("relationships") found = False for relationship in relationships: if relationship.get("identifier") == sourceId: relationship.put("isCurated",True) relationship.put("curatedPid",curatedPid) found = True if not found: relationship = JsonObject() relationship.put("isCurated",True) relationship.put("curatedPid",curatedPid) relationship.put("relationship",relationshipType) relationship.put("identifier",sourceId) relationships.add(relationship) self.log.info(metadataJson.toString(True)) out.println(metadataJson.toString(True)) istream = ByteArrayInputStream(String(metadataJson.toString(True)).getBytes()) for pid in digitalObject.getPayloadIdList(): if pid.endswith(".tfpackage"): StorageUtils.createOrUpdatePayload(digitalObject,pid,istream) out.close() finally: self.sessionState.remove("username")
def dataq_to_string(dataq, string): from java.lang import String if dataq == None: if string == None: raise LowError("At least one argument needs to be bound") else: return (IclDataQ(String(string).getBytes()), string) else: s = str(String(dataq.getData())) if string == None: return (dataq, s) else: if s == string: return (dataq, string) else: return None
def test_object_varargs(self): "array.array objects can be used in the varargs position, with primitive boxing" a = array('i', range(5, 10)) self.assertEqual( 'arg 0=5, arg 1=6, arg 2=7, arg 3=8, arg 4=9', JString.format('arg 0=%d, arg 1=%d, arg 2=%d, arg 3=%d, arg 4=%d', [5, 6, 7, 8, 9]))
def process_online_args(optional_arg_map): """ Determine if we are executing in online mode and if so, validate/prompt for the necessary parameters. :param optional_arg_map: the optional arguments map :return: the WLST mode :raises CLAException: if an error occurs reading input from the user """ _method_name = 'process_online_args' mode = WlstModes.OFFLINE if CommandLineArgUtil.ADMIN_URL_SWITCH in optional_arg_map: if CommandLineArgUtil.ADMIN_USER_SWITCH not in optional_arg_map: try: username = getcreds.getuser('WLSDPLY-09001') except IOException, ioe: ex = exception_helper.create_cla_exception('WLSDPLY-09002', ioe.getLocalizedMessage(), error=ioe) ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE) __logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex optional_arg_map[CommandLineArgUtil.ADMIN_USER_SWITCH] = username if CommandLineArgUtil.ADMIN_PASS_SWITCH not in optional_arg_map: try: password = getcreds.getpass('WLSDPLY-09003') except IOException, ioe: ex = exception_helper.create_cla_exception('WLSDPLY-09004', ioe.getLocalizedMessage(), error=ioe) ex.setExitCode(CommandLineArgUtil.ARG_VALIDATION_ERROR_EXIT_CODE) __logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex optional_arg_map[CommandLineArgUtil.ADMIN_PASS_SWITCH] = String(password)
def test_object_varargs(self): "array.array objects can be used in the varargs position, with primitive boxing" a = array("i", range(5, 10)) self.assertEqual( "arg 0=5, arg 1=6, arg 2=7, arg 3=8, arg 4=9", JString.format("arg 0=%d, arg 1=%d, arg 2=%d, arg 3=%d, arg 4=%d", [5, 6, 7, 8, 9]), )
class Typesetter(): a = String("xxxx" + "x x" + "xxxx" + "x x" + "x x") d = String("xxx " + "x x" + "x x" + "x x" + "xxx ") e = String("xxxx" + "x " + "xxx " + "x " + "xxxx") g = String("xxxx" + "x " + "x xx" + "x x" + "xxxx") i = String("x" + "x" + "x" + "x" + "x") j = String("xxx" + " x" + " x" + " x" + "xxx") m = String("xxxxx" + "x x x" + "x x x" + "x x x" + "x x x") r = String("xxxx" + "x x" + "xxxx" + "x x " + "x xx")
def icl_to_value(icl): "Map an ICL object to a value" if icl.isVar(): return Variable(ICL_CONSTRUCTOR.asString(icl)) # name = iclVarName(icl) # if name.startswith('_'): # return OAAVar('$' + name[1:]) # else: # return OAAVar('$' + name) elif icl.isInt(): i = icl.toLong() try: return int(i) except: return i elif icl.isList(): list = [] for elt in icl.listIterator(): list.append(icl_to_value(elt)) return tuple(list) elif icl.isStruct(): functor = getFunctor(icl) args = [icl_to_value(x) for x in icl.iterator()] if functor in SPECIAL_FUNCTORS: if len(args) == 1: arg = args[0] if functor is REF_FUNCTOR: if isinstance(arg, types.IntegerType): obj = getObject(arg) if obj is not None: return obj else: err = "Referenced object no longer exists: %r" else: err = "Reference functor must take an integer argument: %r" elif isinstance(arg, basestring): if functor == ATOM_FUNCTOR: return Symbol(arg) else: return Symbol(arg).structure() else: err = "Special functor must take a string argument: %r" else: err = "Special functor must take exactly one argument: %r" else: return Structure(Symbol(functor), args) elif icl.isStr(): return icl.toUnquotedString() elif icl.isFloat(): return icl.toFloat() # elif icl.isIclDataQ(): # return icl elif icl.isIclDataQ(): # converting IclDataQ to string return str(String(icl.getData())) else: err = "Unknown ICL type: %r" raise InvalidICLError(err % icl)
def hasPlanPDF(self, oid): object = self.vc('Services').getStorage().getObject(oid) payloadList = object.getPayloadIdList() for payload in payloadList: if String(payload).contains("pdf"): return True return False
def pylistToJavaStringList(pylist): ''' Going forward should use pyValToJavaObj instead. ''' jlist = ArrayList() for i in pylist: jlist.add(String(i)) return jlist
def getColumnClass(self, column): # return [String, String, String, JComboBox][column] if column == 3: print self.actions_combo.getClass() return self.actions_combo.getClass() else: return String().getClass() # Jython bug
def approveSelection(self): filePath = self.getSelectedFile().getPath() fileName = String(self.getSelectedFile().getName()) if fileName.matches('[_a-zA-Z0-9()~#.]+'): if os.path.exists(filePath): message = 'File "' + str(fileName) + ' exists. Overwrite?' result = JOptionPane.showConfirmDialog(self, message, 'Confirm Overwrite', JOptionPane.YES_NO_OPTION) if result == JOptionPane.YES_OPTION: JFileChooser.approveSelection(self) else: JFileChooser.approveSelection(self) else: message = 'The file name contains illegal characters. Please rename.' JOptionPane.showMessageDialog(self, message, 'Error', JOptionPane.ERROR_MESSAGE)
def zip_workspace(self, workspace_path, connection): zip_script = self.get_os_specific_zip_command(workspace_path) zip_script_file = connection.getFile(OverthereUtils.constructPath(connection.getFile(workspace_path), 'zip.cmd')) OverthereUtils.write(String(zip_script).getBytes(), zip_script_file) zip_script_file.setExecutable(True) command = CmdLine() command.addArgument(zip_script_file.getPath()) return connection.execute(command)
def _setAdminUser(): if len(passphrases[ANM_PASSPHRASE]) > 0: print("Creating custom admin user") store = AdminUserStoreDAO() store.createInitialAdminUserStore( options.anmUsername, String(passphrases[ANM_PASSPHRASE]).toCharArray()) store.write(os.path.join(DISTDIR, "conf"))
def test_set_string_array(self): from java.lang import String from jep.test import Test t = Test() ar = jarray(1, String) ar[0] = String("String") result = t.setStringArray(ar) self.assertEqual(result[0], ar[0])
def test_output_arg(self): string = String('\u1156\u2278\u3390\u44AB') for btarray in ([0] * 4, (0,) * 4, jarray(jbyte)([0] * 4)): # This version of getBytes returns the 8 low-order of each Unicode character. string.getBytes(0, 4, btarray, 0) if not isinstance(btarray, tuple): self.assertEqual(btarray, [ctypes.c_int8(x).value for x in [0x56, 0x78, 0x90, 0xAB]]) for method in ["arraySort", "arraySortObject"]: for input in [[], [42], [5, 7, 2, 11, 3]]: with self.subTest(method=method, input=input): l = input.copy() getattr(TA, method)(l) self.assertEqual(sorted(input), l)
def open_image_plus(host, username, password, group_id, image_id): options = "" options += "location=[OMERO] open=[omero:server=" options += host options += "\nuser="******"\npass="******"\ngroupID=" options += String.valueOf(group_id) options += "\niid=" options += String.valueOf(image_id) options += "]" options += " windowless=true " IJ.runPlugIn("loci.plugins.LociImporter", options)
def value_to_icl(x): # DOESN'T HANDLE INFINITE STRUCTURES WELL "Map a value to an ICL object" if isinstance(x, types.IntType): return IclInt(x) elif isinstance(x, types.LongType): return IclInt(x) elif isinstance(x, types.FloatType): return IclFloat(x) elif isinstance(x, basestring): try: return IclStr(str(x)) except: #OAA has a hard-limit on string length return IclDataQ(String(str(x)).getBytes()) elif isinstance(x, types.TupleType): al = ArrayList(len(x)) for elt in x: al.add(value_to_icl(elt)) return IclList(al) elif isStructure(x): s = x.functor.name nargs = len(x) if nargs == 0: # treat as '@@'("absname") args = (s, ) s = NULLARY_FUNCTOR else: args = x al = ArrayList(nargs) for elt in args: al.add(value_to_icl(elt)) return IclStruct(s, al) elif isinstance(x, IclTerm): return x elif isVariable(x) and x.isLocal(): return ICL_CONSTRUCTOR.createVariable(-1, -1, x.name) # name = x.name # if name[1] in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": # return IclVar(name[1:]) # else: # return IclVar("_"+name[1:]) elif isSymbol(x): # treat as '@'("absname") al = ArrayList(1) al.add(IclStr(x.name)) return IclStruct(ATOM_FUNCTOR, al) elif x is None: # treat as '#'(0) al = ArrayList(1) al.add(IclInt(0)) return IclStruct(REF_FUNCTOR, al) elif hasattr(x, "coerceToSPARKForOAA"): return value_to_icl(x.coerceToSPARKForOAA()) else: # treat as '#'(<id>) id = getId(x) print "Unusual object type=%s id=%s being passed to OAA: %r" \ % (type(x), id, x) al = ArrayList(1) al.add(IclInt(id)) return IclStruct(REF_FUNCTOR, al)
def testBuildRequestPath(self): ipg, callbacks = self._ipg() firstLine = "GET /folder1/folder1/file.php HTTP/1.1" secondLine = "Host: example.org" headers = ArrayList() headers.add(firstLine) headers.add(secondLine) request = GenericMock() request.repeatedAnalyzedRequest.parameters = [] request.repeatedAnalyzedRequest.headers = headers request.repeatedHttpRequestResponse.request = String(firstLine + "\r\n" + secondLine + "\r\n").getBytes() insertionPoints = ipg.getInsertionPoints(request, False) insertionPoints[0].updateContentLength = lambda x: x insertionPoints[1].updateContentLength = lambda x: x insertionPoints[2].updateContentLength = lambda x: x callbacks.helpers.urlEncode.return_value = "LOLLOLLOL" ret = insertionPoints[0].buildRequest(String("LOLLOLLOL").getBytes()) self.assertTrue(str(String(ret)).startswith("GET /LOLLOLLOL/folder1/file.php HTTP/1.1")) ret = insertionPoints[1].buildRequest(String("LOLLOLLOL").getBytes()) self.assertTrue(str(String(ret)).startswith("GET /folder1/LOLLOLLOL/file.php HTTP/1.1")) ret = insertionPoints[2].buildRequest(String("LOLLOLLOL").getBytes()) self.assertTrue(str(String(ret)).startswith("GET /folder1/folder1/LOLLOLLOL HTTP/1.1"))
def testDirectEncryptionVariablesNoOverwrite(self): copy2(self._src_model_file_w_variables, self._target_model_test2) args = list() args.append( 'encrypt') # dummy arg for args[0] to get arg padding right args.append(CommandLineArgUtil.ORACLE_HOME_SWITCH) args.append(self._oracle_home) args.append(CommandLineArgUtil.MODEL_FILE_SWITCH) args.append(self._target_model_test2) args.append(CommandLineArgUtil.PASSPHRASE_SWITCH) args.append(self._passphrase) exit_code = encrypt._process_request(args) self.assertEquals(exit_code, 0) model = FileToPython(self._target_model_test2).parse() passphrase_array = String(self._passphrase).toCharArray() admin_pass = model['domainInfo']['AdminPassword'] self.assertNotEquals(admin_pass.startswith('{AES}'), True) nm_pass = model['topology']['SecurityConfiguration'][ 'NodeManagerPasswordEncrypted'] self.assertNotEquals(nm_pass.startswith('{AES}'), True) ds1_pass = model['resources']['JDBCSystemResource']['Generic1'][ 'JdbcResource']['JDBCDriverParams']['PasswordEncrypted'] self.assertEquals(ds1_pass.startswith('{AES}'), True) _decrypted_ds1_pass = EncryptionUtils.decryptString( ds1_pass, passphrase_array) self.assertEquals(str(String(_decrypted_ds1_pass)), self._unencrypted_password) ons_pass = \ model['resources']['JDBCSystemResource']['Generic1']['JdbcResource']['JDBCOracleParams']['OnsWalletPasswordEncrypted'] self.assertNotEquals(ons_pass.startswith('{AES}'), True) ds2_pass = model['resources']['JDBCSystemResource']['Generic2'][ 'JdbcResource']['JDBCDriverParams']['PasswordEncrypted'] self.assertEquals(ds2_pass.startswith('{AES}'), True) _decrypted_ds2_pass = EncryptionUtils.decryptString( ds2_pass, passphrase_array) self.assertEquals(str(String(_decrypted_ds2_pass)), self._unencrypted_password) return
def __readWsdlWithIBMFactory(wsdlData, importWsdlDocuments = 1): if wsdlData == None: raise WSDLException('WSDL Content is Null') else: from com.ibm.wsdl.factory import WSDLFactoryImpl wsdlfactoryIdox = WSDLFactoryImpl() reader = wsdlfactoryIdox.newWSDLReader() if importWsdlDocuments == 1: reader.setFeature('javax.wsdl.importDocuments', Boolean.TRUE) else: reader.setFeature('javax.wsdl.importDocuments', Boolean.FALSE) wsdlData = String(wsdlData.strip()) arr = wsdlData.getBytes() stream = ByteArrayInputStream(arr) inSrc = InputSource(stream) defintion = reader.readWSDL(None, inSrc) return defintion
def __createNew(self): self.vc("log").debug("Creating a new package...") packageType, jsonConfigFile = self.__getPackageTypeAndJsonConfigFile() self.vc("log").debug("packageType = '{}'", packageType) self.vc("log").debug("jsonConfigFile = '{}'", jsonConfigFile) manifestHash = "%s.tfpackage" % uuid.uuid4() # store the manifest file for harvesting packageDir = FascinatorHome.getPathFile("packages") packageDir.mkdirs() manifestFile = File(packageDir, manifestHash) outStream = FileOutputStream(manifestFile) outWriter = OutputStreamWriter(outStream, "UTF-8") self.vc("sessionState").set("package/active", None) manifest = self.__getActiveManifest() manifest.setType(packageType) metaList = list(self.vc("formData").getValues("metaList")) jsonObj = manifest.getJsonObject() for metaName in metaList: value = self.vc("formData").get(metaName) jsonObj.put(metaName, value) if self.vc("formData").getValues("sequencesMetaList") != None: sequenceService = ApplicationContextProvider.getApplicationContext().getBean("sequenceService") sequencesMetaList = list(self.vc("formData").getValues("sequencesMetaList")) for sequenceInfo in sequencesMetaList: sequenceInfoJson = JsonSimple(sequenceInfo) sequenceIndex = sequenceService.getSequence(sequenceInfoJson.getString(None,"sequenceName")) jsonObj.put(sequenceInfoJson.getString(None,"metadataName"), String.format(sequenceInfoJson.getString(None,"stringFormat"),sequenceIndex)) self.vc("log").debug("json object created is: %r" % jsonObj) outWriter.write(manifest.toString(True)) outWriter.close() # adding ability to set access plugin accessPlugin = self.vc("formData").get("access_plugin", "derby") if accessPlugin is not None: self.vc("page").authentication.set_access_plugin(accessPlugin) try: # harvest the package as an object username = self.vc("sessionState").get("username") if username is None: username = "******" # necessary? harvester = None # set up config files, creating if necessary workflowsDir = FascinatorHome.getPathFile("harvest/workflows") configFile = self.__getFile(workflowsDir, jsonConfigFile) self.__getFile(workflowsDir, "packaging-rules.py") # run the harvest client with our packaging workflow config harvester = HarvestClient(configFile, manifestFile, username) harvester.start() manifestId = harvester.getUploadOid() harvester.shutdown() except Exception, ex: error = "Packager workflow failed: %s" % str(ex) self.vc("log").error(error, ex) if harvester is not None: harvester.shutdown() return '{ "status": "failed" }'
def parseCommandLine(argv): fullArgPairPattern = Pattern.compile("--\\w+=\\S*") justArgNamePattern = Pattern.compile("--\\w+") cmdParamProps = {} if (len(argv) > 0): for param in argv: cmdParam = String(param) fullMatcher = fullArgPairPattern.matcher(cmdParam) if (fullMatcher.matches()): (paramName, paramValue) = cmdParam.split("=") cmdParamProps[paramName] = paramValue else: nameMatcher = justArgNamePattern.matcher(cmdParam) if (nameMatcher.matches()): cmdParamProps[param] = None else: print("This " + param + " is not a Command Line parameter") return cmdParamProps
def test_invenio_search(self): kws = HashMap() #.of_(String, List) p = ArrayList() #.of_(String) of = ArrayList() #.of_(String) rg = ArrayList() #.of_(String) p.add('recid:94') of.add('xm') kws.put('p', p) kws.put('of', of) message = self.bridge.createMessage('invenio_search') \ .setParam('kwargs', kws) self.bridge.sendMessage(message) result = str(String.cast_(message.getResults())) assert '<controlfield tag="001">94</controlfield>' in result p.clear() p.add('recid:0->50') message = self.bridge.createMessage('invenio_search') \ .setParam('kwargs', kws) self.bridge.sendMessage(message) result = str(String.cast_(message.getResults())) print result assert 'Search-Engine-Total-Number-Of-Results: 42' in result assert len(result) > 1000 assert result.count('<record>') == 10 rg.add('200') kws.put('rg', rg) message = self.bridge.createMessage('invenio_search') \ .setParam('kwargs', kws) self.bridge.sendMessage(message) result = str(String.cast_(message.getResults())) assert 'Search-Engine-Total-Number-Of-Results: 42' in result assert len(result) > 1000 assert result.count('<record>') == 42
def parseNlbProps(output, resultVector, hostOSH, framework, ip): clusterNameAndProps = output.split('\n', 1) #the name of the cluster; also reflected in props that's why commented #clusterName = clusterNameAndProps[0] clusterPropsAndPortRules = re.split(PROP_RULE_SEPARATOR, clusterNameAndProps[1]) #cut the statistics from output portRulesPropsString = re.split('\\s\\sStatistics:', clusterPropsAndPortRules[2])[0] props = Properties() propsString = String(clusterPropsAndPortRules[0]) props.load(ByteArrayInputStream(propsString.getBytes('UTF-8'))) parseRulesConfigOsh = parsePortRules(portRulesPropsString) nlbCluster = NlbClusterBuilder(props, parseRulesConfigOsh, hostOSH, framework, ip) nlbCluster.addOshToVector(resultVector) nlbNode = NlbSwBuilder(props, nlbCluster.getNlbClusterOSH(), hostOSH, framework) nlbNode.addOshToVector(resultVector)
def setResponseBody(self, body): """ Set the response body. This method may be called multiple times with different values. @param body: The data that should be send in the response body. @type body: string """ self.__response_body = String(body)