<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic sprintf() NaElement method not working in Python NMSDK 5.4P1 in Software Development Kit (SDK) and API Discussions</title>
    <link>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/sprintf-NaElement-method-not-working-in-Python-NMSDK-5-4P1/m-p/117385#M1873</link>
    <description>&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with python libs of MNSDK 5.4P1. I realised that NaElement sptrinf() method is not working. I am buiding this class:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;def GetInfoPath(self):
		'''It's supposed to just retrieved one volume.'''

		netappops.logger.debug("GetInfoPath: Begin")
		s=self.__CreateServer(self.serverpath)
			
		tag=None
		while True:
			#build query
			api1 = NaElement("volume-get-iter")
			if tag is not None: 
				api1.child_add_string("tag",tag);
			api1.child_add_string("max-records",10);
			query = NaElement("query")
			
			
			volpath_parent = NaElement("volume-attributes")
			volpath = NaElement("volume-id-attributes")
			volpath.child_add_string("junction-path",self.serverlayout)
			self.volume["junction-path"]=self.serverlayout

			query.child_add(volpath_parent)
			volpath_parent.child_add(volpath)		
			api1.child_add(query)
			#print(api1.sprintf())		
			#Get attributes we want
			desiredAttrs = NaElement("desired-attributes")
			desiredAutoSpace = NaElement("volume-autosize-attributes")
			desiredIdAttr = NaElement("volume-id-attributes")
			desiredSpace = NaElement("volume-space-attributes")
			desiredState = NaElement("volume-state-attributes")
			desiredAttrs.child_add(desiredAutoSpace)
			desiredAttrs.child_add(desiredIdAttr)
			desiredAttrs.child_add(desiredSpace)
			desiredAttrs.child_add(desiredState)
			api1.child_add(desiredAttrs)
			
			netappops.logger.debug("query looks like: %s",api1.sprintf())&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This always fails with this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "netappops.py", line 194, in &amp;lt;module&amp;gt;&lt;BR /&gt;a.GetInfoPath()&lt;BR /&gt;File "netappops.py", line 126, in GetInfoPath&lt;BR /&gt;print(api1.sprintf())&lt;BR /&gt;File "/ORA/dbs01/work/storage-api/lib/python/NetApp/NaElement.py", line 236, in sprintf&lt;BR /&gt;s = s+c.sprintf(indent + "\t")&lt;BR /&gt;File "/ORA/dbs01/work/storage-api/lib/python/NetApp/NaElement.py", line 238, in sprintf&lt;BR /&gt;self.element['content'] = NaElement.escapeHTML(self.element['content'])&lt;BR /&gt;File "/ORA/dbs01/work/storage-api/lib/python/NetApp/NaElement.py", line 342, in escapeHTML&lt;BR /&gt;cont = re.sub(r'&amp;amp;','&amp;amp;amp;',cont,count=0)&lt;BR /&gt;File "/ORA/dbs01/work/storage-api/v1/lib64/python3.4/re.py", line 179, in sub&lt;BR /&gt;return _compile(pattern, flags).sub(repl, string, count)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have modified the file:&amp;nbsp;&lt;SPAN&gt;/ORA/dbs01/work/storage-api/lib/python/NetApp/NaElement.py &amp;nbsp;appending the lines in bald:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;  @staticmethod

    def escapeHTML(cont):
        """ This is a private function, not to be called externally.
        This method converts reserved HTML characters to corresponding entity names.
        """
        #APPEND BEGIN
        if not isinstance(cont,str):
                cont = str(cont)
        #APPEND END
        cont = re.sub(r'&amp;amp;','&amp;amp;amp;',cont,count=0)
        cont = re.sub(r'&amp;lt;','&amp;amp;lt;',cont,count=0)
        cont = re.sub(r'&amp;gt;','&amp;amp;gt;',cont,count=0)
        cont = re.sub(r"'",'&amp;amp;apos;',cont,count=0)
        cont = re.sub(r'"','&amp;amp;quot;',cont,count=0)

        """ The existence of '&amp;amp;' (ampersand) sign in entity names implies that multiple calls
        to this function will result in non-idempotent encoding. So, to handle such situation
        or when the input itself contains entity names, we reconvert such recurrences to
        appropriate characters.
        """
        cont = re.sub(r'&amp;amp;amp;amp;','&amp;amp;amp;',cont,count=0)
        cont = re.sub(r'&amp;amp;amp;lt;','&amp;amp;lt;',cont,count=0)
        cont = re.sub(r'&amp;amp;amp;gt;','&amp;amp;gt;',cont,count=0)
        cont = re.sub(r'&amp;amp;amp;apos;','&amp;amp;apos;',cont,count=0)
        cont = re.sub(r'&amp;amp;amp;quot;','&amp;amp;quot;',cont,count=0)
        return cont&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now it looks working:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;storage-api-console DEBUG    MainProcess query looks like: &amp;lt;volume-get-iter&amp;gt;
        &amp;lt;max-records&amp;gt;10&amp;lt;/max-records&amp;gt;
        &amp;lt;query&amp;gt;
                &amp;lt;volume-attributes&amp;gt;
                        &amp;lt;volume-id-attributes&amp;gt;
                                &amp;lt;junction-path&amp;gt;/ORA/dbs07/DNFS&amp;lt;/junction-path&amp;gt;
                        &amp;lt;/volume-id-attributes&amp;gt;
                &amp;lt;/volume-attributes&amp;gt;
        &amp;lt;/query&amp;gt;
        &amp;lt;desired-attributes&amp;gt;
                &amp;lt;volume-autosize-attributes&amp;gt;&amp;lt;/volume-autosize-attributes&amp;gt;
                &amp;lt;volume-id-attributes&amp;gt;&amp;lt;/volume-id-attributes&amp;gt;
                &amp;lt;volume-space-attributes&amp;gt;&amp;lt;/volume-space-attributes&amp;gt;
                &amp;lt;volume-state-attributes&amp;gt;&amp;lt;/volume-state-attributes&amp;gt;
        &amp;lt;/desired-attributes&amp;gt;
&amp;lt;/volume-get-iter&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please could you verify the solution and solve the problem for next release of the NMSDK.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THank you,&lt;/P&gt;&lt;P&gt;RUben&lt;/P&gt;</description>
    <pubDate>Wed, 04 Jun 2025 21:42:08 GMT</pubDate>
    <dc:creator>gasparuben</dc:creator>
    <dc:date>2025-06-04T21:42:08Z</dc:date>
    <item>
      <title>sprintf() NaElement method not working in Python NMSDK 5.4P1</title>
      <link>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/sprintf-NaElement-method-not-working-in-Python-NMSDK-5-4P1/m-p/117385#M1873</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with python libs of MNSDK 5.4P1. I realised that NaElement sptrinf() method is not working. I am buiding this class:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;def GetInfoPath(self):
		'''It's supposed to just retrieved one volume.'''

		netappops.logger.debug("GetInfoPath: Begin")
		s=self.__CreateServer(self.serverpath)
			
		tag=None
		while True:
			#build query
			api1 = NaElement("volume-get-iter")
			if tag is not None: 
				api1.child_add_string("tag",tag);
			api1.child_add_string("max-records",10);
			query = NaElement("query")
			
			
			volpath_parent = NaElement("volume-attributes")
			volpath = NaElement("volume-id-attributes")
			volpath.child_add_string("junction-path",self.serverlayout)
			self.volume["junction-path"]=self.serverlayout

			query.child_add(volpath_parent)
			volpath_parent.child_add(volpath)		
			api1.child_add(query)
			#print(api1.sprintf())		
			#Get attributes we want
			desiredAttrs = NaElement("desired-attributes")
			desiredAutoSpace = NaElement("volume-autosize-attributes")
			desiredIdAttr = NaElement("volume-id-attributes")
			desiredSpace = NaElement("volume-space-attributes")
			desiredState = NaElement("volume-state-attributes")
			desiredAttrs.child_add(desiredAutoSpace)
			desiredAttrs.child_add(desiredIdAttr)
			desiredAttrs.child_add(desiredSpace)
			desiredAttrs.child_add(desiredState)
			api1.child_add(desiredAttrs)
			
			netappops.logger.debug("query looks like: %s",api1.sprintf())&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This always fails with this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "netappops.py", line 194, in &amp;lt;module&amp;gt;&lt;BR /&gt;a.GetInfoPath()&lt;BR /&gt;File "netappops.py", line 126, in GetInfoPath&lt;BR /&gt;print(api1.sprintf())&lt;BR /&gt;File "/ORA/dbs01/work/storage-api/lib/python/NetApp/NaElement.py", line 236, in sprintf&lt;BR /&gt;s = s+c.sprintf(indent + "\t")&lt;BR /&gt;File "/ORA/dbs01/work/storage-api/lib/python/NetApp/NaElement.py", line 238, in sprintf&lt;BR /&gt;self.element['content'] = NaElement.escapeHTML(self.element['content'])&lt;BR /&gt;File "/ORA/dbs01/work/storage-api/lib/python/NetApp/NaElement.py", line 342, in escapeHTML&lt;BR /&gt;cont = re.sub(r'&amp;amp;','&amp;amp;amp;',cont,count=0)&lt;BR /&gt;File "/ORA/dbs01/work/storage-api/v1/lib64/python3.4/re.py", line 179, in sub&lt;BR /&gt;return _compile(pattern, flags).sub(repl, string, count)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have modified the file:&amp;nbsp;&lt;SPAN&gt;/ORA/dbs01/work/storage-api/lib/python/NetApp/NaElement.py &amp;nbsp;appending the lines in bald:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;  @staticmethod

    def escapeHTML(cont):
        """ This is a private function, not to be called externally.
        This method converts reserved HTML characters to corresponding entity names.
        """
        #APPEND BEGIN
        if not isinstance(cont,str):
                cont = str(cont)
        #APPEND END
        cont = re.sub(r'&amp;amp;','&amp;amp;amp;',cont,count=0)
        cont = re.sub(r'&amp;lt;','&amp;amp;lt;',cont,count=0)
        cont = re.sub(r'&amp;gt;','&amp;amp;gt;',cont,count=0)
        cont = re.sub(r"'",'&amp;amp;apos;',cont,count=0)
        cont = re.sub(r'"','&amp;amp;quot;',cont,count=0)

        """ The existence of '&amp;amp;' (ampersand) sign in entity names implies that multiple calls
        to this function will result in non-idempotent encoding. So, to handle such situation
        or when the input itself contains entity names, we reconvert such recurrences to
        appropriate characters.
        """
        cont = re.sub(r'&amp;amp;amp;amp;','&amp;amp;amp;',cont,count=0)
        cont = re.sub(r'&amp;amp;amp;lt;','&amp;amp;lt;',cont,count=0)
        cont = re.sub(r'&amp;amp;amp;gt;','&amp;amp;gt;',cont,count=0)
        cont = re.sub(r'&amp;amp;amp;apos;','&amp;amp;apos;',cont,count=0)
        cont = re.sub(r'&amp;amp;amp;quot;','&amp;amp;quot;',cont,count=0)
        return cont&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now it looks working:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;storage-api-console DEBUG    MainProcess query looks like: &amp;lt;volume-get-iter&amp;gt;
        &amp;lt;max-records&amp;gt;10&amp;lt;/max-records&amp;gt;
        &amp;lt;query&amp;gt;
                &amp;lt;volume-attributes&amp;gt;
                        &amp;lt;volume-id-attributes&amp;gt;
                                &amp;lt;junction-path&amp;gt;/ORA/dbs07/DNFS&amp;lt;/junction-path&amp;gt;
                        &amp;lt;/volume-id-attributes&amp;gt;
                &amp;lt;/volume-attributes&amp;gt;
        &amp;lt;/query&amp;gt;
        &amp;lt;desired-attributes&amp;gt;
                &amp;lt;volume-autosize-attributes&amp;gt;&amp;lt;/volume-autosize-attributes&amp;gt;
                &amp;lt;volume-id-attributes&amp;gt;&amp;lt;/volume-id-attributes&amp;gt;
                &amp;lt;volume-space-attributes&amp;gt;&amp;lt;/volume-space-attributes&amp;gt;
                &amp;lt;volume-state-attributes&amp;gt;&amp;lt;/volume-state-attributes&amp;gt;
        &amp;lt;/desired-attributes&amp;gt;
&amp;lt;/volume-get-iter&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please could you verify the solution and solve the problem for next release of the NMSDK.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;THank you,&lt;/P&gt;&lt;P&gt;RUben&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jun 2025 21:42:08 GMT</pubDate>
      <guid>https://community.netapp.com/t5/Software-Development-Kit-SDK-and-API-Discussions/sprintf-NaElement-method-not-working-in-Python-NMSDK-5-4P1/m-p/117385#M1873</guid>
      <dc:creator>gasparuben</dc:creator>
      <dc:date>2025-06-04T21:42:08Z</dc:date>
    </item>
  </channel>
</rss>

