Re: How to set/update value in a xml file using requests in python

2018-02-06 Thread dieter
Sum J  writes:
> My xml file is located in local network : 
> http://192.168.43.109/DevMgmt/NetAppsDyn.xml
>
> Below is a part content of above xml I want to update :
>
> 
> 
> 
> off
> 
>
> I want to set value for 'ResourceUI' and 'Port' field in above xml.
> I have used below code :
>
>  data = {
>   'ResourceURI':'web-proxy.xxx.yy.com',
>   'Port':8080
> }
>
> URL = 'http://192.168.75.165/DevMgmt/NetAppsDyn.xml'
>
> # content type
> head = {'Content-type': 'text/xml'}
> # sending get request
> gr= requests.get(url=URL)
> print gr
>
> # sending put request
> r = requests.put(url=URL, data=data,headers=head)
> print r.status_code
> # extracting response text
> output_xml = r.text
> print("The op xml is:%s" % output_xml)
>
> Issue : The fields are not getting updated in xml using put request. I am 
> able to see the response for get (request) , but for put request it is 
> throwing errror code : 301 , resource has been moved permanently.

This may not be a Python question.

You are sending your data
("{'ResourceURI':'web-proxy.xxx.yy.com', 'Port':8080})
to the web service under "http://192.168.75.165/DevMgmt/NetAppsDyn.xml";.
Apparently, this web service does not interpret the data in the way you
expect.

Note, that you do not send an XML document to "NetAppsDyn.xml"
(despite your `Content-type="text/xml"`). The typical (WevDAV)
"put" would require that "data" contains a complete replacement
for the object to be replaced, not just some modifications
(of course, the object might have a specialized "put" which could
support partial updates -- but apparently, in your current
situation, this is either not the case or the "put" involved
expects to get the replacement information in a different way).

I would approach your task as follows:

 1. Fetch the original XML

 2. Use one of Python's XML libraries (I would use "lxml")
to create the modified XML

 3. "put" the modified XML to the server

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to work on a package

2018-02-06 Thread dieter
Roel Schroeven  writes:
> I'm fairly comfortable writing Python code, but I only have experience
> writing scripts with perhaps a few supporting modules. Now I want to
> start writing a package, and I'm feeling a bit helpless: I'm not sure
> how to organize my work.

You may have a look at
"https://packaging.python.org/"; and
"https://packaging.python.org/tutorials/distributing-packages/#requirements-for-packaging-and-distributing";.

> In my way of thinking, I would have a working tree for the package (or
> even more than one), and also an installed version (once version 0.1
> or so is ready).
>
> For example, let's say I'm working on luaparser
> (https://github.com/boolangery/py-lua-parser). There are tests in
> directory luaparser/tests, and I want to execute those tests. So I
> execute, for example:
>
> $ python3 -m unittest test_ast.py

Likely, there are many ways to execute tests for your package.

I am using "setuptools" for packaging (an extension
of Python's standard "disutils"). Its "setup.py" supports the "test"
command. This means, properly set up, I can run tests
with "python setup.py test".

-- 
https://mail.python.org/mailman/listinfo/python-list


How to set/update value in a xml file using requests in python

2018-02-06 Thread Sum J
My xml file is located in local network : 
http://192.168.43.109/DevMgmt/NetAppsDyn.xml

Below is a part content of above xml I want to update :




off


I want to set value for 'ResourceUI' and 'Port' field in above xml.
I have used below code :

 data = {
  'ResourceURI':'web-proxy.xxx.yy.com',
  'Port':8080
}

URL = 'http://192.168.75.165/DevMgmt/NetAppsDyn.xml'

# content type
head = {'Content-type': 'text/xml'}
# sending get request
gr= requests.get(url=URL)
print gr

# sending put request
r = requests.put(url=URL, data=data,headers=head)
print r.status_code
# extracting response text
output_xml = r.text
print("The op xml is:%s" % output_xml)

Issue : The fields are not getting updated in xml using put request. I am able 
to see the response for get (request) , but for put request it is throwing 
errror code : 301 , resource has been moved permanently.
-- 
https://mail.python.org/mailman/listinfo/python-list


How to work on a package

2018-02-06 Thread Roel Schroeven
I'm fairly comfortable writing Python code, but I only have experience 
writing scripts with perhaps a few supporting modules. Now I want to 
start writing a package, and I'm feeling a bit helpless: I'm not sure 
how to organize my work.


In my way of thinking, I would have a working tree for the package (or 
even more than one), and also an installed version (once version 0.1 or 
so is ready).


For example, let's say I'm working on luaparser 
(https://github.com/boolangery/py-lua-parser). There are tests in 
directory luaparser/tests, and I want to execute those tests. So I 
execute, for example:


$ python3 -m unittest test_ast.py

But that doesn't work:

E
==
ERROR: test_ast (unittest.loader._FailedTest)
--
ImportError: Failed to import test module: test_ast
Traceback (most recent call last):
  File "/usr/lib/python3.5/unittest/loader.py", line 153, in 
loadTestsFromName

module = __import__(module_name)
  File "/home/roel/temp/py-lua-parser/luaparser/tests/test_ast.py", 
line 1, in 

from luaparser.utils  import tests
ImportError: No module named 'luaparser'


The test tries to import the global luaparser package (beause they use 
absoluate imports, which is the recommended way if I understand 
correctly), but that's not what I want: I want to test the local version 
in my working tree.


I guess I could use something like

$ PYTHONPATH=../.. python3 -m unittest test_ast.py

but it feels like there should be a better way than manually specifying 
the module search path.


How do people usually do this? Is there maybe a guide that explains the 
practical side of writing packages?


--
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
  -- Isaac Asimov

Roel Schroeven

--
https://mail.python.org/mailman/listinfo/python-list


Packaging uwsgi flask app for non-programmers?

2018-02-06 Thread Israel Brewster
I have been working on writing an Alexa skill which, as part of it, requires a 
local web server on the end users machine - the Alexa skill sends commands to 
this server, which runs them on the local machine. I wrote this local server in 
Flask, and run it using uwsgi, using a command like: "uwsgi serverconfig.ini".

The problem is that in order for this to work, the end user must:

1) Install python 3.6 (or thereabouts)
2) Install a number of python modules, and
3) run a command line (from the appropriate directory)

Not terribly difficult, but when I think of my target audience (Alexa users), I 
could easily see even these steps being "too complicated". I was looking at 
pyinstaller to create a simple double-click application, but it appears that 
pyinstaller needs a python script as the "base" for the application, whereas my 
"base" is uwsgi. Also, I do need to leave a config file accessible for the end 
user to be able to edit. Is there a way to use pyinstaller in this scenario, or 
perhaps some other option that might work better to package things up?
 
---
Israel Brewster
Systems Analyst II
Ravn Alaska
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7293
---




-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Does anyone know ni?

2018-02-06 Thread Roel Schroeven

Ian Kelly schreef op 6/02/2018 21:43:

It was used for package support and is no longer needed from Python
1.5. http://legacy.python.org/doc/essays/packages.html


Thanks!

--
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
  -- Isaac Asimov

Roel Schroeven

--
https://mail.python.org/mailman/listinfo/python-list


Re: Does anyone know ni?

2018-02-06 Thread Ian Kelly
It was used for package support and is no longer needed from Python
1.5. http://legacy.python.org/doc/essays/packages.html

On Tue, Feb 6, 2018 at 1:27 PM, Roel Schroeven  wrote:
> I'm having a look at py-iso8211 from
> https://sourceforge.net/projects/py-iso8211/ to see if I can get it to work
> without too much work. It uses a module 'ni', for example in __init__.py:
>
>
> """
> ...
> """
>
> # Make the above more easily available - if you do:
> #
> # import ni
> # ni.ni() # (currently needed (in Python 1.3) to start "ni" up)
> # import iso8211
> # print  iso8211.Intro
> #
> # then you should get the sensible result...
>
> Intro   = __doc__
>
>
> Is it something that was needed in very old Python versions to get access to
> the docstring?
>
> --
> The saddest aspect of life right now is that science gathers knowledge
> faster than society gathers wisdom.
>   -- Isaac Asimov
>
> Roel Schroeven
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Does anyone know ni?

2018-02-06 Thread Roel Schroeven
I'm having a look at py-iso8211 from 
https://sourceforge.net/projects/py-iso8211/ to see if I can get it to 
work without too much work. It uses a module 'ni', for example in 
__init__.py:



"""
...
"""

# Make the above more easily available - if you do:
#
# import ni
# ni.ni() # (currently needed (in Python 1.3) to start "ni" up)
# import iso8211
# print  iso8211.Intro
#
# then you should get the sensible result...

Intro   = __doc__


Is it something that was needed in very old Python versions to get 
access to the docstring?


--
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
  -- Isaac Asimov

Roel Schroeven

--
https://mail.python.org/mailman/listinfo/python-list


Fwd: [Python-Dev] libxml2 installation/binding issue

2018-02-06 Thread Dan Stromberg
Perhaps look over (or use) http://stromberg.dnsalias.org/~strombrg/cpythons/ ?

It defaults to building many versions of CPython, but can build just
one if you prefer.

It knows how to build GTK+ as well, for some newer versions of CPython.

-- Forwarded message --
From: Priest, Matt 
Date: Mon, Feb 5, 2018 at 2:41 PM
Subject: [Python-Dev] libxml2 installation/binding issue
To: "python-...@python.org" 


Hello,



I am not sure if this is the correct place to post an issue/question
like this, but here goes…



I’ve successfully (?) installed Python 3.6.4 and libxml2, with the
ultimate goal of installing GTK+ 3.22.0.

However, I’m running into this error:





python3

Python 3.6.4 (default, Feb  5 2018, 13:28:04)

[GCC 4.7.2] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> import libxml2

Traceback (most recent call last):

  File "", line 1, in 

  File 
"/nfs/sc/disks/slx_1353/mlpriest/sl1/work_root/a0/development/sfwr/lib/python3.6/site-packages/libxml2.py",
line 1, in 

import libxml2mod

ImportError: 
/nfs/sc/disks/slx_1353/mlpriest/sl1/work_root/a0/development/sfwr/lib/python3.6/site-packages/libxml2mod.so:
undefined symbol: _PyVerify_fd





Here are the details on the version, cflags, and ldflags.

python3 --version ;

Python 3.6.4

python3-config --cflags

-I/nfs/sc/disks/slx_1353/mlpriest/sl1/work_root/a0/development/sfwr/include/python3.6m

-I/nfs/sc/disks/slx_1353/mlpriest/sl1/work_root/a0/development/sfwr/include/python3.6m

-Wno-unused-result

-Wsign-compare

-fPIC -DNDEBUG

-g

-fwrapv

-O3

-Wall

-Wstrict-prototypes



python3-config –ldflags;

-L/nfs/sc/disks/slx_1353/mlpriest/sl1/work_root/a0/development/sfwr/lib/python3.6/config-3.6m-x86_64-linux-gnu

-L/nfs/sc/disks/slx_1353/mlpriest/sl1/work_root/a0/development/sfwr/lib

-lpython3.6m

-lpthread

-ldl

-lutil

-lrt

-lm

-Xlinker

-export-dynamic



Anyhelp or hint would be appreciated…







Matt




___
Python-Dev mailing list
python-...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/drsalists%40gmail.com
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: libxml2 installation/binding issue with Python 3.6.4

2018-02-06 Thread Priest, Matt
Dieter,

I'm sure it's the Python version, I was hoping the "latest" set of the 
dependencies would get me there.
I'll explore stepping that version back and let you know...  

Thank you,

Matt

-Original Message-
From: Python-list [mailto:python-list-bounces+matt.priest=intel@python.org] 
On Behalf Of dieter
Sent: Tuesday, February 6, 2018 12:57 AM
To: python-list@python.org
Subject: Re: libxml2 installation/binding issue with Python 3.6.4

"Priest, Matt"  writes:
> ...
> I've successfully (?) installed Python 3.6.4 and libxml2, with the ultimate 
> goal of installing GTK+ 3.22.0.

You might also try "lxml" - which is an alternative for "libxml2".

> However, I'm running into this error:
> ...
> import libxml2mod
> ImportError: 
> /nfs/sc/disks/slx_1353/mlpriest/sl1/work_root/a0/development/sfwr/lib/
> python3.6/site-packages/libxml2mod.so: undefined symbol: _PyVerify_fd

This indicates a version mismatch between the C part of "libxml2" and something 
in your system - maybe the "libxml2" C library but more likely Python (given 
the name).

Are you sure that "libxml2" is Python 3 ready?

--
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: "None" and "pass"

2018-02-06 Thread Rhodri James

On 06/02/18 10:23, alister via Python-list wrote:

On Tue, 06 Feb 2018 08:55:35 +1100, Chris Angelico wrote:


On Tue, Feb 6, 2018 at 8:39 AM, Ben Finney 
wrote:

Chris Angelico  writes:


As one special case, I would accept this sort of code:

def f():
 ...

(three dots representing the special value Ellipsis)

It's a great short-hand for "stub".


I would not accept that.

An even better way to write a stub function is to write a docstring:

 def frobnicate():
 """ Frobnicate the spangule. """

A docstring, like any bare expression, is also a valid statement.
Writing a docstring can be done immediately, because if you're writing
a stub function you at least know the external interface of that
function.



This is true, but I'd rather have something _under_ the docstring if
possible, and "..." works well for that. A docstring with nothing
underneath doesn't look like a stub - it looks like a failed edit or
something. Having a placeholder shows that it's intentional.

ChrisA


indeed and pass was implemented for precisely this usage
why even think about possible alternatives


None shall pass.

(Seriously.  I'm disappointed in all of you :-)

--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: "None" and "pass"

2018-02-06 Thread alister via Python-list
On Tue, 06 Feb 2018 08:55:35 +1100, Chris Angelico wrote:

> On Tue, Feb 6, 2018 at 8:39 AM, Ben Finney 
> wrote:
>> Chris Angelico  writes:
>>
>>> As one special case, I would accept this sort of code:
>>>
>>> def f():
>>> ...
>>>
>>> (three dots representing the special value Ellipsis)
>>>
>>> It's a great short-hand for "stub".
>>
>> I would not accept that.
>>
>> An even better way to write a stub function is to write a docstring:
>>
>> def frobnicate():
>> """ Frobnicate the spangule. """
>>
>> A docstring, like any bare expression, is also a valid statement.
>> Writing a docstring can be done immediately, because if you're writing
>> a stub function you at least know the external interface of that
>> function.
>>
>>
> This is true, but I'd rather have something _under_ the docstring if
> possible, and "..." works well for that. A docstring with nothing
> underneath doesn't look like a stub - it looks like a failed edit or
> something. Having a placeholder shows that it's intentional.
> 
> ChrisA

indeed and pass was implemented for precisely this usage
why even think about possible alternatives



-- 
Use an accordion.  Go to jail.
-- KFOG, San Francisco
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: From recovery.js to recoveryjsonlz4

2018-02-06 Thread Cecil Westerhof
breamore...@gmail.com writes:

> On Monday, February 5, 2018 at 1:28:16 PM UTC, Cecil Westerhof wrote:
>> I have a script to get the number of windows and tabs that firefox
>> uses. It always used a file recovery.js, but it changed to
>> recovery.jsonlz4.
>> 
>> Looking at the extension I would think it is an lz4 compressed file.
>> But when I use:
>> import lz4
>> 
>> I see that it is deprecated. How should I work with this file?
>> 
>
> I can't see anything here
> http://python-lz4.readthedocs.io/en/stable/lz4.html to indicate that the
> package is deprecated, although the lz4version function has been since
> version 0.14. Further the latest 0.21.6 was released just yesterday,
> 04/02/2018, so I'm guessing that you've just misread something.

Well, when using 'import lz4' and giving tab in ipython, you get:
deprecated
library_version_number
library_version_string
lz4version
VERSION
version

Looking at:
http://python-lz4.readthedocs.io/en/stable/lz4.frame.html

I tried to replace:
loads(open(recover, 'rb').read().decode('utf-8'))

With:
import lz4.frame
.
.
.
lz4.frame.open(recover, 'rb').read().decode('utf-8')

But this gives:
--
RuntimeError  Traceback (most recent call last)
 in ()
> 1 dummy = lz4.frame.open(recover, 'rb').read().decode('utf-8')

/usr/local/lib/python3.5/dist-packages/lz4/frame/__init__.py in read(self, 
size)
507 """
508 self._check_can_read()
--> 509 return self._buffer.read(size)
510 
511 def read1(self, size=-1):

/usr/lib/python3.5/_compression.py in read(self, size)
101 else:
102 rawblock = b""
--> 103 data = self._decompressor.decompress(rawblock, size)
104 if data:
105 break

/usr/local/lib/python3.5/dist-packages/lz4/frame/__init__.py in 
decompress(self, data, max_length)
295 data,
296 max_length=max_length,
--> 297 return_bytearray=self._return_bytearray,
298 )
299 

RuntimeError: LZ4F_decompress failed with code: ERROR_frameType_unknown

What works is:
dummy = lz4.frame.open(recover, 'rb')

And this gives a:


But when I then do:
input = dummy.read()

I get (as above):
---
RuntimeError  Traceback (most recent call last)
 in ()
> 1 input = dummy.read()

/usr/local/lib/python3.5/dist-packages/lz4/frame/__init__.py in read(self, 
size)
507 """
508 self._check_can_read()
--> 509 return self._buffer.read(size)
510 
511 def read1(self, size=-1):

/usr/lib/python3.5/_compression.py in read(self, size)
101 else:
102 rawblock = b""
--> 103 data = self._decompressor.decompress(rawblock, size)
104 if data:
105 break

/usr/local/lib/python3.5/dist-packages/lz4/frame/__init__.py in 
decompress(self, data, max_length)
295 data,
296 max_length=max_length,
--> 297 return_bytearray=self._return_bytearray,
298 )
299 

RuntimeError: LZ4F_decompress failed with code: ERROR_frameType_unknown

So how do I circumvent this error to read the file?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list