how can i get the file on my local pc from vps ip with paramiko or by some other way?

2014-12-17 Thread pengsir
I have an vps ,my local pc is in the local area network. When paramiko 
installed on my local pc ,i can get file from my vps.


import paramiko
t = paramiko.Transport(("vps ip",22))
t.connect(username = "username", password = "key")
sftp = paramiko.SFTPClient.from_transport(t)
remotepath='/tmp/test.txt'
localpath='/tmp/test.txt'
sftp.get(remotepath,localpath)

Now the problem is :how can i get the file on my local pc from vps ip 
with paramiko or by some other way?


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


Re: xml SAX Parsing in python

2014-12-17 Thread Stefan Behnel
Hi,

Abubakar Roko schrieb am 17.12.2014 um 07:30:
> Please I am new in using python to write program. I am trying to parse an XML 
> document using sax parse  and store the parsed result in a tree like 
> definedbelow. XNode class define an xml element which has an ID , a tag, a 
> text value, children element and a parent element
>class XNode(object):
> def __init__(self, ID ="", elmName="", 
> elmValue="", parent=None):
>  self.ID = ID 
> self.elmName=elmName self.elmValue=elmValue   
>   self.childs=[]
> self.parent=parent
> 
>def  getPath(self):
>   if self.parent is None:   return 
> self.elmName else:
>return self.parent.getPath()+"/"+ self.elmName
> I  wrote a program that parse an XML document ,  convert the  document  into 
> the tree like structure defined above and then return the parsed result tothe 
> program that call it.  The program shown below.
> 
> import xml.saximport XMLnode as n
> 
> class XML_Handler ( xml.sax.ContentHandler):
> def __init__(self, root):self.root = rootself.tmp =  
> n.XNode()
> def startElement(self, tag, attributes):#if self.root != None:
> if self.root is not None:
> if len(self.tmp.childs) < 10:ID = self.tmp.ID 
> +"." + "0" + str( len(self.tmp.childs))else:ID = 
> self.tmp.ID +"." + str( len(self.tmp.childs)) 
> self.tmp.childs.append( n.XNode(ID,tag,"",self.tmp)) 
> self.tmp= self.tmp.childs[len(self.tmp.childs)-1]else:
> print "0", tag, self.tmp.getPath()self.root= n.XNode("0", 
> tag,"",None)self.tmp=self.root
> def characters(self, content):self.tmp.elmValue += content.strip()
> def endElement(self, tag):self.tmp= self.tmp.parent
> 
> def parse(self, f):xml.sax.parse(self,f)return self.root
> 
> if ( __name__ == "__main__"):
>  parser = xml.sax.make_parser() 
> parser.setFeature(xml.sax.handler.feature_namespaces, 0) root = None
> Handler = XML_Handler(root)parser.setContentHandler( Handler )
> treRoot= parser.parse("Movies.xml")print treRoot
> Can somebody help me answer the following questionMy Question is how do I 
> return the parsed result through the root instance variable of  of 
> XML_Handler classI try to do it but i always get None as answerI am using 
> Window 7 professional and python 2.7

The formatting of your code example was heavily screwed up, please send a
plain text email next time.

My general advice is to use ElementTree instead of SAX. It's way easier to
use (even for simple tasks). Use iterparse() to get event driven
incremental parsing.

https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.iterparse

http://effbot.org/zone/element-iterparse.htm

Stefan


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


Re: uWSGI, nGinx, and python on Wheezy: how do you configure it?

2014-12-17 Thread Veek M
Dumped uwsgi - the documentation is utterly ridculous!! 

Switched to 'Bottle' - very nice, intutive and clean - 
tutorial+documentation is excellent and i got 'hello world' up and running 
in like 10-15 minutes vs the 2 days intermittent it took to scroll through 
the crap that is uwsgi-server. It's got a built in web-server, so no need to 
mess with nginx. http://bottlepy.org/docs/dev/index.html

I think i'll like Flask too - there's a book: "Flask Web Development: 
Developing Web Applications with Python"


Seriously though, it takes a dev about 15 minutes to scrawl out a line-
diagram, scan it, and upload, explaining WTH is going on with his whole 
project - i'll take a 10 MB GIF anyday, vs wasting 1 day flat just staring 
in shock at 'Greenlets' and uwsig protocol and thw WSGI spec and the uWSGI 
server.. here's a quote:

"Loop engines (implement events and concurrency, components can be run in 
preforking, threaded, asynchronous/evented and green thread/coroutine modes. 
Various technologies are supported, including uGreen, Greenlet, Stackless, 
Gevent, Coro::AnyEvent, Tornado, Goroutines and Fibers)"

Somebody reading that might mistake it for the Mars landing.


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


Classes - "delegation" question.

2014-12-17 Thread Ivan Evstegneev
Hello guys,

I have a question about "delegation" coding pattern(I'm working with Python
3.4).
In order to describe my question , I'll provide particular example:

Let assume I have two classes written in module named person.py:


Case 1:

class Person:
def __init__(self, name, job = None, pay =0):
self.name = name
self.job = job
self.pay = pay
def lastName(self):
return self.name.split()[-1]
def giveRaise(self, percent):
self.pay = int(sel.pay * (1 + percent))
def __repr__(self):
return '[Person: %s, %s]' % (self.name, self.pay)

class Manager(Person):
def giveRaise(self, percent, bonus = .10):
Person.giveRaise(self, percent + bonus)


Case 2: 


class Person: 
the same...

class Manager: 
def __init__(self, name, pay):
self.person = Person(name, 'mgr', pay)
def giveRaise(self, percent, bonus = .10):
self.person.giveRaise(percent + bonus)
def __getattr__(self, attr):
return getattr(self.person, attr)
def __repr__(self):
return str(self.person) 

 
I also used some test code proposed by the book:

if __name__ == '__main__':
bob = Person('Bob Smith')
sue = Person('Sue Jones', job='dev', pay=10)
print(bob)
print(sue)
print(bob.lastName(), sue.lastName())
sue.giveRaise(.10)
print(sue)
tom = Manager('Tom Jones', 5) # Job name not needed:
tom.giveRaise(.10)

print(tom.lastName())
print(tom)


As I can understand from the above code : 

When code looks like in  Case 1, it actually works with standard
"inheritance" model. (with sub and super-class definitions).
Also according to the book:
***
This code leverages the fact that a class's method can always be called
either through
an instance (the usual way, where Python sends the instance to the self
argument
automatically) or through the class (the less common scheme, where you must
pass the
instance manually). In more symbolic terms, recall that a normal method call
of this
form:
instance.method(args...)
is automatically translated by Python into this equivalent form:
class.method(instance, args...)
 ***

Furthermore:

***
Python provides it automatically only for calls made through an instance.
For calls 
through the class name, you need to send an instance to self yourself; for
code inside 
a method like giveRaise, self already is the subject of the call, and hence
the instance 
to pass along.
Calling through the class directly effectively subverts inheritance and
kicks the call
higher up the class tree to run a specific version.


What is considered as a "call" in this context?

Is it a code inside class method?

For instance(relates to the "Case 1"):

def giveRaise(self, percent, bonus = .10):
Person.giveRaise(self, percent + bonus)

The "call" will be : Person.giveRaise(self, percent + bonus)   ?

In such a case, when I create an instance:

>>> tom = Manager('Tom Jones', 5)

and then invoke giveRaise method 

>>> tom.giveRaise(.10)

I essentially say this:

"class.method(instance, args...) "

Where class is "Person" and method is "giveRaise" and instance is "tom"?

Moreover, because of how it defined (a method giveRaise), I make a "call"
through the class name?

What is the "call" through instance? 

Is it this one(according to Case 1):

class Person:
...
def giveRaise(self, percent):
self.pay = int(sel.pay * (1 + percent))
...

and then:

>>> bob = Person('Bob Smith', 'dev', 3)
>>> bob.giveRaise(.10) <    Is this call through instance? 



Questions regard to "Case 2" example:

class Person: 
the same...

class Manager: 
def __init__(self, name, pay):
self.person = Person(name, 'mgr', pay)   <---
Initialization of Manager's attribute named  'self.person" and embedding  a
Person object. 

def giveRaise(self, percent, bonus = .10):< --
Defenition of Manager's method named "giveRaise" and according to the book:
self.person.giveRaise(percent + bonus)   "Intercept and
delegate"
..

My question here is substantially the same:

On the one hand we embedding "Person" into "Manager" class, 

On the other hand, when I write this code:

>>> tom = Manager('Tom Jones', 5000)

I create an instance of Manager that have an attribute named: tom.person,
which in turn is a class named Person.

And when typing:

>>>tom.giveRaise(.10)

I do kinda same thing. 
For my assumption I say:

P

smptplib problem SMTPRecipientsRefused for emails with ! exclamation mark in local portion of email

2014-12-17 Thread radzhome
smtplib.SMTPRecipientsRefused: {'aahlin!@gmail.com': (550, 'restricted 
characters in address')}

As in this question, the answer has reference to RFCs that spec it out, and 
state that exclamations are ok, so why is smptplib throwint this error?

http://stackoverflow.com/questions/2049502/what-characters-are-allowed-in-email-address

Django uses smtplib to send emails so it in turn fails too but email validation 
allows you to enter !
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: xml SAX Parsing in python

2014-12-17 Thread Ian Kelly
On Tue, Dec 16, 2014 at 11:30 PM, Abubakar Roko
 wrote:
>
> Good day,
>
> Please I am new in using python to write program. I am trying to parse an
XML document using sax parse  and store the parsed result in a tree like
defined
> below. XNode class define an xml element which has an ID , a tag, a text
value, children element and a parent element
>
>class XNode(object):
>
> def __init__(self, ID ="", elmName="",
elmValue="", parent=None):
>
>  self.ID = ID
>  self.elmName=elmName
>  self.elmValue=elmValue
>  self.childs=[]
> self.parent=parent
>
>
>def  getPath(self):
>   if self.parent is None:
>return self.elmName
>  else:
>return self.parent.getPath()+"/"+
self.elmName
>
> I  wrote a program that parse an XML document ,  convert the  document
 into the tree like structure defined above and then return the parsed
result to
> the program that call it.  The program shown below.

I'm not sure why you would want to use a SAX parser for this. The advantage
of incremental parsing is that you never have to have the whole document in
memory at once. If you use it to construct some DOM-like structure from the
document, then you're going to have the whole document in memory anyway,
and you might as well just use one of the existing implementations (e.g.
ElementTree) rather than reinventing your own.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: smptplib problem SMTPRecipientsRefused for emails with ! exclamation mark in local portion of email

2014-12-17 Thread Ervin Hegedüs
Hi,

On Wed, Dec 17, 2014 at 08:16:23AM -0800, radzh...@gmail.com wrote:
> smtplib.SMTPRecipientsRefused: {'aahlin!@gmail.com': (550, 'restricted 
> characters in address')}
> 
> As in this question, the answer has reference to RFCs that spec it out, and 
> state that exclamations are ok, so why is smptplib throwint this error?
> 
> http://stackoverflow.com/questions/2049502/what-characters-are-allowed-in-email-address
> 
> Django uses smtplib to send emails so it in turn fails too but email 
> validation allows you to enter !

I think that this exception came from your SMTP server, not from
smtplib. Check your smtpd log.

You can try to send through that smtpd at another way (eg.
netcat) with that address - may be then you can check the result.


a.

-- 
I � UTF-8
-- 
https://mail.python.org/mailman/listinfo/python-list


signal.signal handler arity check - PEP?

2014-12-17 Thread Mike Pomraning
It strikes me as oddly dangerous that signal.signal() accepts callable handlers 
of the wrong arity:

def timeout_cleanup():
  ...

signal.signal(signal.SIGALRM, timeout_cleanup)   # I desire a TypeError 
here
signal.alarm(PROCESS_TIMEOUT)

... time passes ...

TypeError: timeout_cleanup() takes 0 positional arguments but 2 were given

(Similar TypeError with different text under python 2.)

The downside to current behavior is that the coding error is revealed only 
under certain conditions at runtime.  In the example above, you don't know that 
your seatbelt is defective until you need it.

Does anyone disagree with modifying signal.signal's behavior to raise a 
TypeError when given a user-defined handler of the wrong arity?  Any code 
relying on this behavior is, IMO, contrived beyond plausibility.  However, this 
change might break code not yet known to be incorrect.

If no disagreements, patch or PEP?

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


Re: smptplib problem SMTPRecipientsRefused for emails with ! exclamation mark in local portion of email

2014-12-17 Thread Radomir Wojcik
thanks i'll try that, I can also telnet on the server and see what I get if I 
use that recipient. I'm using exim, not sure why it would have that restriction
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: smptplib problem SMTPRecipientsRefused for emails with ! exclamation mark in local portion of email

2014-12-17 Thread Radomir Wojcik
thanks i'll try that, I can also telnet on the server and see what I get if I 
use that recipient. I'm using exim, not sure why it would have that restriction
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: smptplib problem SMTPRecipientsRefused for emails with ! exclamation mark in local portion of email

2014-12-17 Thread Radomir Wojcik
No need to do more troubleshooting, need to update the config. Found that exim 
default config denies these so nothing to do with smptlib indeed:

What this statement is doing is to accept unconditionally all recipients in 
messages that are submitted by SMTP from local processes using the standard 
input and output (that is, not using TCP/IP). A number of MUAs operate in this 
manner.

denymessage   = Restricted characters in address
domains   = +local_domains
local_parts   = ^[.] : ^.*[@%!/|]

denymessage   = Restricted characters in address
domains   = !+local_domains
local_parts   = ^[./|] : ^.*[@%!] : ^.*/\\.\\./
These statements are concerned with local parts that contain any of the 
characters "@", "%", "!", "/", "|", or dots in unusual places. Although these 
characters are entirely legal in local parts (in the case of "@" and leading 
dots, only if correctly quoted), they do not commonly occur in Internet mail 
addresses.

http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_default_configuration_file.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: smptplib problem SMTPRecipientsRefused for emails with ! exclamation mark in local portion of email

2014-12-17 Thread Radomir Wojcik
Its all in here for those using exim4

http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_default_configuration_file.html

I went into /etc/exim4 and ran this command to find where the deny message is 
stored, which lead me to the regex variable CHECK_RCPT_LOCAL_LOCALPARTS. So I 
searched for it, updated the values and restarted exim:

grep -r CHECK_RCPT_LOCAL_LOCALPARTS *

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


Is there a way to schedule my script?

2014-12-17 Thread Juan Christian
I know about the schedule modules and such but they work in situations like
'run this in a X hours/minutes/seconds interval', I already have my code in
a while loop with sleep (it's a bit ugly, I'l change to a scheduler soon).

What I really want is, for example:

24/7/365
9:00 AM -> Start
11:59 PM -> Stop

9:00 AM ~ 11:50 PM -> Running
12:00 AM ~ 8:59 AM -> Stopped

I want my script to start at a given time and stop at another given time,
is that possible?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a way to schedule my script?

2014-12-17 Thread John Gordon
In  Juan Christian 
 writes:

> --047d7b874b2c1e67eb050a6e3cc4
> Content-Type: text/plain; charset=UTF-8

> I know about the schedule modules and such but they work in situations like
> 'run this in a X hours/minutes/seconds interval', I already have my code in
> a while loop with sleep (it's a bit ugly, I'l change to a scheduler soon).

> What I really want is, for example:

> 24/7/365
> 9:00 AM -> Start
> 11:59 PM -> Stop

> 9:00 AM ~ 11:50 PM -> Running
> 12:00 AM ~ 8:59 AM -> Stopped

> I want my script to start at a given time and stop at another given time,
> is that possible?

You could write a separate program whose only job is to send a STOP or
CONTINUE signal to your main program, and then run that program from a
scheduler.

The standard system "kill" command would probably work for this purpose,
assuming you have access to your main program's process ID.

-- 
John Gordon Imagine what it must be like for a real medical doctor to
gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'.

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


[ANN]: distlib 0.2.0 released on PyPI

2014-12-17 Thread Vinay Sajip
I've just released version 0.2.0 of distlib on PyPI [1]. For newcomers,
distlib is a library of packaging functionality which is intended to be
usable as the basis for third-party packaging tools.

The main changes in this release are as follows:

Updated match_hostname to use the latest Python implementation.

Updates to better support PEP 426 / PEP 440.

You can now provide interpreter arguments in shebang lines written
by distlib.

Removed reference to __PYVENV_LAUNCHER__ (relevant to OS X only).

A more detailed change log is available at [2].

Please try it out, and if you find any problems or have any suggestions for
improvements, please give some feedback using the issue tracker! [3]

Regards,

Vinay Sajip

[1] https://pypi.python.org/pypi/distlib/0.2.0
[2] http://pythonhosted.org/distlib/overview.html#change-log-for-distlib
[3] https://bitbucket.org/pypa/distlib/issues/new
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a way to schedule my script?

2014-12-17 Thread Juan Christian
On Wed Dec 17 2014 at 5:45:31 PM John Gordon  wrote:
You could write a separate program whose only job is to send a STOP or
CONTINUE signal to your main program, and then run that program from a
scheduler.

The standard system "kill" command would probably work for this purpose,
assuming you have access to your main program's process ID.

There isn't any 'prettier' way? Such as a built-in or third-party module
for something common like that?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is there a way to schedule my script?

2014-12-17 Thread Juan Christian
Ops, sorry.

It's: 9:00 AM ~ 11:59 PM -> Running

... and not 9:00 AM ~ 11:50 PM -> Running
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Simple background sound effect playback

2014-12-17 Thread Jacob Kruger
Ok, trying simple code from a pygame tutorial snippet - nothing happens - just 
silent, but with no errors being returned:

# play a sound to the left, to the right and to the center

# import the time standard module
import time

# import the pygame module
import pygame


# start pygame
pygame.init()

# load a sound file into memory
sound = pygame.mixer.Sound("bird.ogg")

# start playing the sound
# and remember on which channel it is being played
channel = sound.play()
# set the volume of the channel
# so the sound is only heard to the left
channel.set_volume(1, 0)
# wait for 1 second
time.sleep(1)

# do the same to the right
channel = sound.play()
channel.set_volume(0, 1)
time.sleep(1)

# do the same to the center
channel = sound.play()
channel.set_volume(1, 1)
time.sleep(1)
#end code

Think this is why ignored pygame in past... - think it actually needs 
more than itself to be installed, or something.

Jacob Kruger
Blind Biker
Skype: BlindZA
...Roger Wilco wants to welcome you, to the space janitor's closet...

  - Original Message - 
  From: Ian Kelly 
  To: Python 
  Sent: Wednesday, December 17, 2014 3:49 AM
  Subject: Re: Simple background sound effect playback


  On Tue, Dec 16, 2014 at 9:57 AM, Jacob Kruger  wrote:
  >
  > Would prefer to use something free, that could work somewhat 
cross-platform, but, my primary target is for windows OS, and would primarily 
just want to be able to easily trigger playback of either .wav or .mp3 
background sound effects, but, yes, would also be nice to be able to control 
them a little bit in terms of volume, possibly stereo panning as well as 
playback rate/frequency/pitch?
  >  
  > I have used something called sound_lib, as well as another one relating to 
a sort of windows directSound effect, but, both of them had issues when working 
with either py2exe or cx_freeze when it came to compiling into executable, and 
main thing is would like to keep it simple...
  >  
  > Suggestions?


  https://wiki.python.org/moin/Audio/


--


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


Re: Is there a way to schedule my script?

2014-12-17 Thread John Gordon
In  Juan Christian 
 writes:

> The standard system "kill" command would probably work for this purpose,
> assuming you have access to your main program's process ID.

> There isn't any 'prettier' way? Such as a built-in or third-party module
> for something common like that?

If you're on Unix, 'kill' and 'cron' are already built-in.

If you want to solve your problem entirely within Python, look at the
"scheduler" module.  (Although even this isn't a complete solution, as you
still have to make sure the program is running in the first place...)

-- 
John Gordon Imagine what it must be like for a real medical doctor to
gor...@panix.comwatch 'House', or a real serial killer to watch 'Dexter'.

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


Re: Is there a way to schedule my script?

2014-12-17 Thread Juan Christian
On Wed Dec 17 2014 at 6:25:39 PM John Gordon  wrote:
If you want to solve your problem entirely within Python, look at the
"scheduler" module. (Although even this isn't a complete solution, as you
still have to make sure the program is running in the first place...)


My script is running fine, Win/OSX/Linux and I don't want to ruin that
using system specific things.

I looked at sched doc and it's only for creating a delay, maybe a good
approach would be to call the sched and check if time = 11:59PM, then set
delay to 1h and when the time goes 9AM, it returns to my normal delay.

Is there any kind of time calculation in Python that counts the time like
0, 1, 2, 3... so that 0AM would be 0, and 11:59PM would be let's say
'64562'? And everyday it gets a reset when the clock 'turns'?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: smptplib problem SMTPRecipientsRefused for emails with ! exclamation mark in local portion of email

2014-12-17 Thread Michael Ströder
Radomir Wojcik wrote:
> No need to do more troubleshooting, need to update the config. Found that 
> exim default config denies these so nothing to do with smptlib indeed:
> 
> What this statement is doing is to accept unconditionally all recipients in 
> messages that are submitted by SMTP from local processes using the standard 
> input and output (that is, not using TCP/IP). A number of MUAs operate in 
> this manner.
> 
> denymessage   = Restricted characters in address
> domains   = +local_domains
> local_parts   = ^[.] : ^.*[@%!/|]
> 
> denymessage   = Restricted characters in address
> domains   = !+local_domains
> local_parts   = ^[./|] : ^.*[@%!] : ^.*/\\.\\./
> These statements are concerned with local parts that contain any of the 
> characters "@", "%", "!", "/", "|", or dots in unusual places. Although these 
> characters are entirely legal in local parts (in the case of "@" and leading 
> dots, only if correctly quoted), they do not commonly occur in Internet mail 
> addresses.
> 
> http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_default_configuration_file.html

You should really think about why these chars were excluded in the
configuration: The reason is that those they are special in shells.

And many SMTP deployments have pretty naive (shell) scripts or software with
shell exits. So allowing those chars can cause more or less big security
risks. For this reason it's likely that you will end in spam filters / black
lists etc. because systems may assume you want to do some harm.

So I would really rethink the requirements.

Your mileage may vary. But you have been warned.

Ciao, Michael.

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


Re: Is there a way to schedule my script?

2014-12-17 Thread Chris Angelico
On Thu, Dec 18, 2014 at 7:42 AM, Juan Christian
 wrote:
> Is there any kind of time calculation in Python that counts the time like 0,
> 1, 2, 3... so that 0AM would be 0, and 11:59PM would be let's say
> '64562'? And everyday it gets a reset when the clock 'turns'?

time.time() % 86400

That's number of seconds since midnight UTC, ranging from 0 up to
86399. (I've no idea what 64562 would mean. That's an awfully big
number for a single day.) If you offset that before calculating, you
can get that in your local time. Otherwise, just do the arithmetic
directly. Time isn't all _that_ hard to work with.

I don't see what's the big problem with just using sleep() though.
Isn't that exactly what you're after?

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


Re: Is there a way to schedule my script?

2014-12-17 Thread Juan Christian
On Wed Dec 17 2014 at 7:35:10 PM Chris Angelico  wrote:

time.time() % 86400

That's number of seconds since midnight UTC, ranging from 0 up to
86399. (I've no idea what 64562 would mean. That's an awfully big
number for a single day.) If you offset that before calculating, you
can get that in your local time. Otherwise, just do the arithmetic
directly. Time isn't all _that_ hard to work with.

I don't see what's the big problem with just using sleep() though.
Isn't that exactly what you're after?

This was a random number I invented So, I'm already using sleep to make
my script execute some funcs in a defined interval, but when the time is
0AM-9AM I don't want the delay to be the normal one (randint(5,10) * 60) -
5~10min, I want it to be like 2hours.

The script will be running 24/7, but from 0AM to 9AM it will "slowdown" a
bit.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: smptplib problem SMTPRecipientsRefused for emails with ! exclamation mark in local portion of email

2014-12-17 Thread Chris Angelico
On Thu, Dec 18, 2014 at 7:59 AM, Michael Ströder  wrote:
> You should really think about why these chars were excluded in the
> configuration: The reason is that those they are special in shells.
>
> And many SMTP deployments have pretty naive (shell) scripts or software with
> shell exits. So allowing those chars can cause more or less big security
> risks. For this reason it's likely that you will end in spam filters / black
> lists etc. because systems may assume you want to do some harm.
>
> So I would really rethink the requirements.
>
> Your mileage may vary. But you have been warned.

It's worth noting that the SMTP spec never says that every server must
accept all characters. I could create a perfectly compliant mail
server in which recipient names may not include the letter 'e', for
instance. It would be a bug if smtplib rejected those, but since the
rejection is coming from the server, that's fairly legit.

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


Re: Is there a way to schedule my script?

2014-12-17 Thread Chris Cioffi
Hi Juan,

I don't know what platform you're on, but you've got several options.  

Mac:  setup a launchd job, I use http://www.soma-zone.com/LaunchControl/ to do 
the setups

Linux/unix:  setup a cron job, depending on your distro launchd may also be an 
option.

Windows:  setup a scheduled job in ??  (I don't have a windows box around any 
more, but there was a "Scheduled Jobs" section in windows explorer back in the 
XP days.  I assume it's still around.

In all cases, you'll need to add a little code in your script to STOP at 11:59, 
but the OS can handle starting the script.

The launchd option can also act as a watchdog to also restart the script if it 
fails for some reason.

Hope this helps!


> On Dec 17, 2014, at 2:11 PM, Juan Christian  wrote:
> 
> Ops, sorry.
> 
> It's: 9:00 AM ~ 11:59 PM -> Running
> 
> ... and not 9:00 AM ~ 11:50 PM -> Running
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


Re: Is there a way to schedule my script?

2014-12-17 Thread Steven D'Aprano
Juan Christian wrote:

> I know about the schedule modules and such but they work in situations
> like 'run this in a X hours/minutes/seconds interval', I already have my
> code in a while loop with sleep (it's a bit ugly, I'l change to a
> scheduler soon).
[...] 
> I want my script to start at a given time and stop at another given time,
> is that possible?

The right solution to this is probably to use your operating system's
scheduler to run your script at whatever time or times you want. Under
Unix/Linux, that is cron. I'm sure Windows will have it's own, but I don't
know what it is.

Then your script then doesn't have to care about times at all, it just runs
and does its thing, and the OS controls when it runs. cron is amazingly
flexible.

This is the proper separation of concerns. Your script doesn't have to deal
with memory management, or the file system, or scheduling times, that is
the operating system's job. The OS already has tools to do this, and can do
them *much better than you*. (What happens if your script dies? What about
when the time changes, say because of daylight savings?)

Unless you are running on some primitive OS with no way to control when jobs
run except to manually run them, the *wrong* solution is a busy-wait loop:

while True:
# Wait forever, doing nothing.
sleep(0.1)  # Yawn.
if now() == some_time():
do_this()


It doesn't matter if you use the sched module to shift the time check to
another part of your code if the main loop does nothing. The critical
question here is this:

While you are waiting for the scheduled time, does your main loop
continuously do any other work? 

If the answer is Yes, then using sched is the right approach.

If the answer is No, then your main loop is just killing time, doing nothing
but sleeping and waiting, like somebody checking their wristwatch every two
seconds. You should simplify your script by getting rid of the main loop
completely and let your OS handle the timing:

# No loop at all.
do_this()


-- 
Steven

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


Please help - Python role in Emeryville, CA - Full-time - $100K+

2014-12-17 Thread Jared E. Cardon
Hi,

I found your Python group on Google+ and I'm searching for someone with 3+ 
years of Python development experience for a full-time position in California.  
Salary north of $100K and working for an amazing company.  Ideally I'd like to 
find someone who is nice, plugged into the movie and comic culture, and very 
skilled at python and web application development.

If you know of anyone local to the area who would be interested please put me 
in touch with them.  Feel free to post my request on the group page.

Thank you,
Jared


Jared Cardon
Account Manager
Phone: (415) 635-3764 | Cell: (646) 287-7738 | 
jcar...@sisinc.com | 
www.sisinc.com

Systems Integration Solutions - A Diversity Vendor
Proud to be in our 25th year of providing IT Consulting resources and services
[cid:image004.jpg@01D01A13.ABA62E80][Description:
 cid:image008.jpg@01CDD3B3.D1FF2B20]

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


Re: Is there a way to schedule my script?

2014-12-17 Thread Juan Christian
On Wed Dec 17 2014 at 9:40:52 PM Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:

> Juan Christian wrote:
>
> > I know about the schedule modules and such but they work in situations
> > like 'run this in a X hours/minutes/seconds interval', I already have my
> > code in a while loop with sleep (it's a bit ugly, I'l change to a
> > scheduler soon).
> [...]
> > I want my script to start at a given time and stop at another given time,
> > is that possible?
>
> The right solution to this is probably to use your operating system's
> scheduler to run your script at whatever time or times you want. Under
> Unix/Linux, that is cron. I'm sure Windows will have it's own, but I don't
> know what it is.
>
> Then your script then doesn't have to care about times at all, it just runs
> and does its thing, and the OS controls when it runs. cron is amazingly
> flexible.
>
> This is the proper separation of concerns. Your script doesn't have to deal
> with memory management, or the file system, or scheduling times, that is
> the operating system's job. The OS already has tools to do this, and can do
> them *much better than you*. (What happens if your script dies? What about
> when the time changes, say because of daylight savings?)
>
> Unless you are running on some primitive OS with no way to control when
> jobs
> run except to manually run them, the *wrong* solution is a busy-wait loop:
>
> while True:
> # Wait forever, doing nothing.
> sleep(0.1)  # Yawn.
> if now() == some_time():
> do_this()
>
>
> It doesn't matter if you use the sched module to shift the time check to
> another part of your code if the main loop does nothing. The critical
> question here is this:
>
> While you are waiting for the scheduled time, does your main loop
> continuously do any other work?
>
> If the answer is Yes, then using sched is the right approach.
>
> If the answer is No, then your main loop is just killing time, doing
> nothing
> but sleeping and waiting, like somebody checking their wristwatch every two
> seconds. You should simplify your script by getting rid of the main loop
> completely and let your OS handle the timing:
>
> # No loop at all.
> do_this()
>

Thanks. That was a great answer. I'll redo my code. It's running and will
only run in my Docker container (Ubuntu Server 14.04.1) so I'll use cron.

Indeed, currently I'm using something like that:

while True:
if 9 < datetime.now().hour < 24:
# do stuff
sleep(randint(3, 6) * 60)
else:
# see you in 9 hours
sleep(9 * 60 * 60)

I knew it wasn't a good approach, but as least it was running as intended!
-- 
https://mail.python.org/mailman/listinfo/python-list


Python gethostbyname fails just one one machine.

2014-12-17 Thread abhishes
I have many machines on which the following command returns nothing (but does 
not throw an error as well

python -c 'import socket; socket.gethostbyname(socket.getfqdn())'


but on just one machine. this command throws

Traceback (most recent call last):
  File "", line 1, in 
socket.gaierror: [Errno -3] Temporary failure in name resolution


I searched the internet and most people had this problem because of a bad 
/etc/hosts file or /etc/sysconfig/network file

but in my case this files are absolutely correct

/etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
156.17.148.40 cm1work
156.17.148.41 hd1work
156.17.148.42 hd2work
156.17.148.43 hd3work

/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=h3work
GATEWAY=156.17.148.1

but this command just won't work

Please help me out.
~
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python gethostbyname fails just one one machine.

2014-12-17 Thread Chris Angelico
On Thu, Dec 18, 2014 at 2:21 PM,   wrote:
> I have many machines on which the following command returns nothing (but does 
> not throw an error as well
>
> python -c 'import socket; socket.gethostbyname(socket.getfqdn())'
>
>
> but on just one machine. this command throws
>
> Traceback (most recent call last):
>   File "", line 1, in 
> socket.gaierror: [Errno -3] Temporary failure in name resolution
>
>
> I searched the internet and most people had this problem because of a bad 
> /etc/hosts file or /etc/sysconfig/network file
>
> but in my case this files are absolutely correct
>
> /etc/hosts
> 127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
> ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
> 156.17.148.40 cm1work
> 156.17.148.41 hd1work
> 156.17.148.42 hd2work
> 156.17.148.43 hd3work
>
> /etc/sysconfig/network
> NETWORKING=yes
> HOSTNAME=h3work
> GATEWAY=156.17.148.1
>
> but this command just won't work

What you have here is a networking issue, not a Python one, so you may
well find you can't get the help you need here. But I'll try.

Have you checked /etc/nsswitch.conf? What about /etc/resolv.conf or
equivalent? What's the FQDN returned in the first step? If there's a
difference in any of those, it might give a clue.

If all else fails, try stracing the process:

strace python -c 'import socket; socket.gethostbyname(socket.getfqdn())'

and see if there are any obvious errors.

This is a bit of nutting out and analysis, so I wouldn't be surprised
if you get lots of wrong answers before you find the right one. It's
like Edison said (or is said to have said): you're finding a thousand
ways to NOT make a light bulb.

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


Re: Python gethostbyname fails just one one machine.

2014-12-17 Thread Abhishek Srivastava
I was able to resolve the issue.

since you said that there is nothing wrong with python as such... and its a 
networking issue.

I deleted the network adapter of my vm and then re-created it.

now suddenly it began to work. funny!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python gethostbyname fails just one one machine.

2014-12-17 Thread Chris Angelico
On Thu, Dec 18, 2014 at 3:26 PM, Abhishek Srivastava  wrote:
> I was able to resolve the issue.
>
> since you said that there is nothing wrong with python as such... and its a 
> networking issue.
>
> I deleted the network adapter of my vm and then re-created it.
>
> now suddenly it began to work. funny!

Huh. Well, could have been some sort of weird configuration issue, who
knows. Glad it's working now, anyway!

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


Re: Classes - "delegation" question.

2014-12-17 Thread dieter
"Ivan Evstegneev"  writes:
> I have a question about "delegation" coding pattern(I'm working with Python
> 3.4).

Unlike Java, Python supports "multiple inheritance". This means
that you need "delegation" much more rarely in Python.
Python does not have much special support for delegation: usually,
you must delegate explicitely - maybe using a delagating decorator.

> ...
> When code looks like in  Case 1, it actually works with standard
> "inheritance" model. (with sub and super-class definitions).
> Also according to the book:
> ***
> This code leverages the fact that a class's method can always be called
> either through
> an instance (the usual way, where Python sends the instance to the self
> argument
> automatically) or through the class (the less common scheme, where you must
> pass the
> instance manually). In more symbolic terms, recall that a normal method call
> of this
> form:
>   instance.method(args...)
> is automatically translated by Python into this equivalent form:
>   class.method(instance, args...)
>  ***
>
> Furthermore:
>
> ***
> Python provides it automatically only for calls made through an instance.
> For calls 
> through the class name, you need to send an instance to self yourself; for
> code inside 
> a method like giveRaise, self already is the subject of the call, and hence
> the instance 
> to pass along.
> Calling through the class directly effectively subverts inheritance and
> kicks the call
> higher up the class tree to run a specific version.
> 
>
> What is considered as a "call" in this context?

Something of the form "(args...)". I.e. any call of
a function or method.

The discussion above does not directly apply to your situation.
It targets more specifically the following case:

   class Base:
 ...
 def f(self, ...):
   ...

   class Derived(Base):
 ...
 def f(self, ...):
   ...
   Base.f(self, ...)
   ...

i.e., you have two classes "Base", and "Derived" where
"Derived" overrides the inherited "f" and its definition
involves the use of the inherited "f". Inside the redefinition,
you must make explicit that you mean the inherited "f" and not
the "f" being defined. In those cases, you typically use
the pattern "Base.f", meaning the "f" defined in "Base".
However, you may use the form anywhere - its just rarer in other
cases.

It you use "instance.f", then "instance" is automatically
passed as first argument to "f"; however, it you use
"class.f", then nothing is passed on automatically as first
parameter. When "class.f" is finally called, you usually need
to pass an instance of "class" as first parameter explicitely.


> Is it a code inside class method?

Usually, you use "class.f" inside the redefinition of "f"
in a derived class. But, you can use it anywhere (if you like).

> For instance(relates to the "Case 1"):
>
> def giveRaise(self, percent, bonus = .10):
>   Person.giveRaise(self, percent + bonus)
>
> The "call" will be : Person.giveRaise(self, percent + bonus)   ?

Yes.

> In such a case, when I create an instance:
>
 tom = Manager('Tom Jones', 5)
>
> and then invoke giveRaise method 
>
 tom.giveRaise(.10)
>
> I essentially say this:
>
> "class.method(instance, args...) "
>
> Where class is "Person" and method is "giveRaise" and instance is "tom"?

Yes.

> Moreover, because of how it defined (a method giveRaise), I make a "call"
> through the class name?

Loosely speaking, yes.

> What is the "call" through instance? 

Your "tom.giveRaise". There "tom" is a "Manager" instance.
>
> Is it this one(according to Case 1):
>
> class Person:
>   ...
>   def giveRaise(self, percent):
>   self.pay = int(sel.pay * (1 + percent))
>   ...
>
> and then:
>
 bob = Person('Bob Smith', 'dev', 3)
 bob.giveRaise(.10) <    Is this call through instance? 

Yes.


> ...
> Questions regard to "Case 2" example:
>
> class Person: 
>   the same...
>
> class Manager: 
>   def __init__(self, name, pay):
>   self.person = Person(name, 'mgr', pay)   <---
> Initialization of Manager's attribute named  'self.person" and embedding  a
> Person object. 
>   
>   def giveRaise(self, percent, bonus = .10):< --
> Defenition of Manager's method named "giveRaise" and according to the book:
>   self.person.giveRaise(percent + bonus)   "Intercept and
> delegate"
>   ..
>
> My question here is substantially the same:
>
> On the one hand we embedding "Person" into "Manager" class, 
>
> On the other hand, when I write this code:
>
 tom = Manager('Tom Jones', 5000)
>
> I create an instance of Manager that have an attribute named: tom.person,
> which in turn is a cl