Beispiel #1
0
 def request_write(self, data):
     """
     Accept a request to write data.
     """
     # basically we only put it into the queue
     if self.pipe_handle is None:
         LOG("chan_win_handle_write %s already closed, discard data [%s]\n" 
             % (self, pp.pp(data)))
         return None,None
     assert self.handle is not None
     if dbg>=2:
         LOG("%s handle = %s, data = [%s]\n" % (self, self.pipe_handle, pp.pp(data)))
     n = len(self.requests)
     self.requests.append(data)
     if data is None:
         self.pending_close = 1
     else:
         self.pending_writes = self.pending_writes + len(data)
     if n == 0:
         # We have not been having any data in the
         # queue, which means the channel has not
         # been watched.  Ensure it is now watched.
         self.iom.ensure_watched(self)
         # and issue an overlapping write
         self.issue_overlap_write__()
     return self.pending_writes,self.pending_close
Beispiel #2
0
 def issue_overlap_write__(self):
     if dbg>=2: LOG("%s\n" % self)
     data = self.requests[0]
     e = None
     if data is None:
         assert (self.pending_writes == 0), self.pending_writes
         assert self.pending_close
         self.requests.pop(0)
         if dbg>=2:
             LOG("%s CloseHandle(%s)\n" % (self, self.handle))
             LOG("%s CloseHandle(%s)\n" % (self, self.pipe_handle))
         self.close()
         self.pending_close = 0
     else:
         # make data garbage collectable after passing it
         # to WriteFile
         self.requests[0] = len(data)
         if dbg>=2:
             LOG("%s ResetEvent(%s)\n" % (self, self.overlap.hEvent))
             LOG("%s WriteFile(%s, %s)\n" % (self, self.pipe_handle, pp.pp(data)))
         win32event.ResetEvent(self.overlap.hEvent)
         try:
             win32file.WriteFile(self.pipe_handle, data, self.overlap)
         except pywintypes.error,e:
             if dbg>=2: 
                 LOG("%s failed to write %s\n" % (self, e.args,))
Beispiel #3
0
 def request_write(self, data):
     """
     Accept a request to write data.
     """
     if self.fd is None:
         LOG("chan_unix_fd_write %s already closed, discard data [%s]\n" 
             % (self, pp.pp(data)))
         return None,None
     if dbg>=3:
         LOG("fd = %d, data = [%s]\n" % (self.fd, pp.pp(data)))
     n = len(self.requests)
     self.requests.append(data)
     if data is None:
         self.pending_close = 1
     else:
         self.pending_writes = self.pending_writes + len(data)
     if n == 0:
         self.iom.add_channel_to_watch_write__(self)
     return self.pending_writes,self.pending_close
Beispiel #4
0
 def request_write(self, data):
     """
     Accept a request to write data.
     """
     if self.so is None:
         LOG("chan_win_socket %s already closed, discard data [%s]\n" 
             % (self, pp.pp(data)))
         return None,None
     assert self.handle is not None
     if dbg>=2:
         LOG("%s so = %s data = [%s]\n" % (self, self.so, pp.pp(data)))
     n = len(self.requests)
     self.requests.append(data)
     if data is None:
         self.pending_close = 1
     else:
         self.pending_writes = self.pending_writes + len(data)
     if n == 0:
         # The queue has been empty. 
         # Ensure this channel is watched for.
         self.reset()
     return self.pending_writes,self.pending_close
Beispiel #5
0
 def discard_socket(self):
     if dbg>=3: LOG("fd = %s\n" % self.fd)
     if len(self.requests) > 0:
         if dbg>=1:
             LOG("write_channel %d closed with buffered data %s\n"
                 % (self.fd, pp.pp(self.requests[0])))
         self.requests = []
         if self.want_read:
             self.want_read = 0
             self.iom.del_channel_to_watch_read_write__(self)
         else:
             self.iom.del_channel_to_watch_write__(self)
     else:
         if self.want_read:
             self.want_read = 0
             self.iom.del_channel_to_watch_read__(self)
         else:
             bomb()
     assert not self.iom.channels.has_key(self.fd)
     self.so = None
     self.fd = None
Beispiel #6
0
 def do_write(self):
     """
     Called when this socket becomes ready for write.
     Actually perform send operation.
     """
     data = self.requests[0] # grab data to write
     e = None                # exception object if we get one
     if data is None:
         assert self.pending_close
         assert (self.pending_writes == 0), self.pending_writes
         if dbg>=1:
             LOG("os.close(%d)\n" % self.fd)
         try:
             no_intr(os.close, (self.fd,))
         except EnvironmentError,e:
             if dbg>=1:
                 LOG("os.close(%d) failed, ignored %s\n" 
                     % (self.fd, pp.pp(e)))
         if e is None:
             self.requests.pop(0)
             self.pending_close = 0
Beispiel #7
0
 def do_write(self):
     """
     Called when this socket becomes ready for write.
     Actually perform send operation.
     """
     data = self.requests[0]
     e = None
     if data is None:
         # this is send EOF request. shutdown write channel
         assert self.pending_close
         assert (self.pending_writes == 0), self.pending_writes
         if dbg>=3:
             LOG("socket.shutdown(%d)\n" % self.fd)
         try:
             no_intr(self.so.shutdown, (socket.SHUT_WR,))
         except socket.error,e:
             pass
         if e:
             if dbg>=1:
                 LOG("socket.shutdown(%d) failed %s\n" % (self.fd, pp.pp(e)))
         else:
             self.requests.pop(0)
             self.pending_close = 0
Beispiel #8
0
 e = None
 if self.pipe_broken == 0:
     # Pull data from the overlap object
     if dbg>=2: 
         LOG("%s GetOverlappedResult(%s, ...)\n" % (self, self.pipe_handle))
     try:
         sz = win32file.GetOverlappedResult(self.pipe_handle, self.overlap, 0)
         data = self.overlap_buf[:sz]
     except pywintypes.error,e_:
         if e_.args[0] == winerror.ERROR_BROKEN_PIPE: 
             if dbg>=2: 
                 LOG("-> BROKEN_PIPE (OK)\n")
         else:
             e = e_
 if dbg>=2: 
     LOG("-> data = [%s], e = %s\n" % (pp.pp(data), pp.pp(e)))
 if data == "":
     # Error or EOF. Either case, we no longer read
     # from this pipe
     if dbg>=2:
         LOG("%s CloseHandle(%s)\n" % (self, self.pipe_handle))
         LOG("%s CloseHandle(%s)\n" % (self, self.handle))
     self.close()
 elif self.want_read:
     # A read completed.  Make sure we keep issuing 
     # an overlapped read as soon as one completes.
     self.issue_overlap_read__()
 else:
     # The client does not want to pull data.
     # Record there is no outstanding read operation
     self.outstanding_read = 0
Beispiel #9
0
def ppr(s):
    """pretty result of executing the soundcloud API request s"""
    pp(client.r(s))
Beispiel #10
0
    if not os.path.exists(audio):
        print "downloading %s" % audio
        with open(meta, 'w+') as f:
            json.dump(track, f)

        with open(audio, 'wb+') as f:
            f.write(client.stream(i).read())
    else:
        print "file already exists, skipping %s" % audio


# program starts here:

group = client.r('/me/groups')[0]
pp(select(group, ["name", "id"]))


def pending(g):
    return client.rs('/groups/%d/pending_tracks' % g['id'])  #,  maximum=300)


t = "artwork_url,bpm,comment_count,genre,id,playback_count,tag_list,title"
t = t.split(',')

from requests.exceptions import HTTPError

for track in pending(group):
    try:
        pp(select(track, t))
        download("pending", track)
Beispiel #11
0
 def __str__(self):
     return ("event_accept(ch=%s, new_ch=%s, err=%s)" 
             % (self.ch, self.new_ch, pp.pp(self.err)))
Beispiel #12
0
     assert self.pending_close
     assert (self.pending_writes == 0), self.pending_writes
     if dbg>=1:
         LOG("os.close(%d)\n" % self.fd)
     try:
         no_intr(os.close, (self.fd,))
     except EnvironmentError,e:
         if dbg>=1:
             LOG("os.close(%d) failed, ignored %s\n" 
                 % (self.fd, pp.pp(e)))
     if e is None:
         self.requests.pop(0)
         self.pending_close = 0
 else:
     if dbg>=3:
         LOG("os.write(%d, [%s])\n" % (self.fd, pp.pp(data)))
     sz = len(data)
     asz = 0
     try:
         asz = no_intr(os.write, (self.fd, data))
         assert (0 < asz <= sz), (asz, sz)
     except EnvironmentError,e:
         pass
     if dbg>=3: 
         LOG("requested %s bytes, %d bytes actually written, err = %s\n" 
             % (sz, asz, pp.pp(e)))
     self.pending_writes = self.pending_writes - asz
     if e:
         if dbg>=1:
             LOG("os.close(%d)\n" % self.fd)
         try:
Beispiel #13
0
H1s_exp = 1.24
H1s = CGTOs.getH1s()
He1s_exp = 1.6875 * 1.24
He1s = CGTOs.getHe1s()

title = 'HeH+, spacing: 0.1 a.u.'
label = 'STO-3G\nexp(H1s): ' + str(H1s_exp) + '\nexp(He1s): ' + str(He1s_exp)

basis_set = []
basis_set.append(basis.basis(H1s))
basis_set.append(basis.basis(He1s))

basis_per_nuclei = [1, 1]

N_charge = [1, 2]

e_count = 2

x = np.arange(0.1, 3.5, 0.1)

rhf = rhf.rhf(basis_set, basis_per_nuclei, N_charge, e_count, x)

E = rhf.solve()

pp = pp.pp(title, label)

print('\nBond Length: ' + str(pp.min_energy(x, E)[0]))
print('\nTotal Energy: ' + str(pp.min_energy(x, E)[1]))

pp.plot(x, E)
Beispiel #14
0
def ppr(s):
	"""pretty result of executing the soundcloud API request s"""
	pp(client.r(s))
Beispiel #15
0
	if not os.path.exists(audio):
		print "downloading %s" % audio
		with open(meta, 'w+') as f:
			json.dump(track, f)

		with open(audio, 'wb+') as f:
			f.write(client.stream(i).read())
	else:
		print "file already exists, skipping %s" % audio


# program starts here:

group = client.r('/me/groups')[0]
pp(select(group,["name","id"]))

def pending(g):
	return client.rs('/groups/%d/pending_tracks' % g['id'])#,  maximum=300)

t = "artwork_url,bpm,comment_count,genre,id,playback_count,tag_list,title"
t = t.split(',')

from requests.exceptions import HTTPError

for track in pending(group):
	try:
		pp(select(track,t))
		download("pending", track)
	except HTTPError,e:
		print e
Beispiel #16
0
 def __str__(self):
     return ("event_write(ch=%s, pending_bytes=%d, pending_close=%d, err=%s)" 
             % (self.ch, self.pending_bytes, 
                self.pending_close, pp.pp(self.err)))
Beispiel #17
0
 def __str__(self):
     return ("event_read(ch=%s, data=%s, eof=%d, err=%s)" 
             % (self.ch, pp.pp(self.data), self.eof, pp.pp(self.err)))
Beispiel #18
0
        | angle
        | base16
    )

    pair = Group(
        namespaced_identifier
        + literal('=')
        + pairvalue
    )

    widget = Forward().setParseAction(mkWidget)
    widget << head + (
        ZeroOrMore(
            widget
            | pair
        )('nodes')
    ) + end

    doc = widget + stringEnd
    st = doc.parseFile(filepath).asList()

    return st


if __name__ == '__main__':
    source = sys.argv[1]
    st = parse(source)
    if '-d' in sys.argv:
        import pp
        pp.pp(st)
Beispiel #19
0
import scanner, adalexis, adatoken
import slr, adagrammar
import parsetree
import sys
import pp
import sbc

print 'creating scanner'
lexer = scanner.Scanner(adalexis.tokendefs)
print 'creating parser'
parser = slr.SLR(adagrammar.G)
parser2 = sbc.SBC(adagrammar.G)

print 'ready for input'
source = sys.stdin.read()
print pp.pp(source)
(tokens, errors) = lexer.lex(source)
tokens.append(adatoken.EOF(len(source), len(source), ''))
tokens[0:0] = [adatoken.BOF(0,0,'')]
print tokens
print errors
errorints = pp.points2ints(errors)
if errorints != []:
	print pp.ppi(source, errorints, True)
	sys.exit(1)
(parse, perrors) = parser2.parse(tokens)
print parse
print perrors
if perrors != []:
	perrors = map((lambda ti: (tokens[ti[0]].begin, tokens[ti[1]].end)), perrors)
	print pp.ppi(source, perrors, True)