Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62040

Re: [newbie] trying socket as a replacement for nc

Path csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=0559fdd6f=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'subject:: [': 0.04; 'error:': 0.07; 'only,': 0.07; 'tries': 0.07; 'string': 0.09; "'')": 0.09; 'subject:trying': 0.09; 'try:': 0.09; 'def': 0.12; 'itself.': 0.14; '"%s"\'': 0.16; 'carriage': 0.16; 'eof,': 0.16; 'idea:': 0.16; 'timeout)': 0.16; 'timeout):': 0.16; 'unexpectedly': 0.16; 'index': 0.16; 'dependent': 0.19; 'subject:] ': 0.20; 'command': 0.22; 'import': 0.22; 'error': 0.23; 'header :In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'raise': 0.29; 'forgot': 0.30; 'returned': 0.30; 'code': 0.31; 'extract': 0.31; 'index,': 0.31; "we're": 0.32; 'to:name:python-list': 0.33; 'skip:_ 10': 0.34; 'except': 0.35; 'skip:s 30': 0.35; 'something': 0.35; 'should': 0.36; 'thank': 0.38; 'skip:[ 10': 0.38; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; 'removing': 0.60; 'signal': 0.60; 'equipment': 0.61; 'you.': 0.62; 'information': 0.63; 'our': 0.64; 'received:194': 0.64; 'to:addr:gmail.com': 0.65; 'notice:': 0.67; 'person,': 0.68; 'prompt': 0.68; 'skip:r 40': 0.68; 'privileged.': 0.69; 'skip:r 30': 0.69; 'disclose': 0.74; 'medium.': 0.91
X-IronPort-AV E=Sophos;i="4.95,494,1384297200"; d="scan'208";a="2244795"
X-Virus-Scanned amavisd-new at zimbra.sequans.com
Date Mon, 16 Dec 2013 11:42:07 +0100 (CET)
From Jean-Michel Pichavant <jeanmichel@sequans.com>
To Jean Dubois <jeandubois314@gmail.com>, python-list <python-list@python.org>
In-Reply-To <1696195433.1350548.1387189752869.JavaMail.root@sequans.com>
Subject Re: [newbie] trying socket as a replacement for nc
MIME-Version 1.0
X-Mailer Zimbra 7.2.4_GA_2900 (ZimbraWebClient - GC31 (Win)/7.2.4_GA_2900)
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding base64
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4198.1387190528.18130.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1387190528 news.xs4all.nl 2938 [2001:888:2000:d::a6]:33635
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:62040

Show key headers only | View raw


> Did you try
> 
> import telnetlib
> 
> ?
> 
> Note that in the code above I forgot the EOF, which is very much
> dependent of the equipment itself.
> 
> You may have to write
> t.write('*IDN?\n')
> or
> t.write('IDN?\n\r')
> 
> JM


Additionally, here's the code we're using for our signal generators, just to give you a broad idea:

	def getError(self):
		error = self._extractRsp(self._sendCmd('SYST:ERR?', 10))
		if '"No error"' in error:
			return None
		else:
			return error

	def _sendCmd(self, aCmd, timeout):
		self.send(str(aCmd) + self.SEND_LFCR)

		waitPattern = [self.PROMPT]
		try:			
			index, _, rsp= self._telnet.expect(waitPattern, timeout)
		except  EOFError:
			self._logger.error('Connection unexpectedly closed while sending/reading/ data.')
			raise MxgError('Connection unexpectedly closed while sending the command "%s"' % aCmd)

		if index == -1:
			raise MxgError('Timeout occurred while sendind the command "%s"' % aCmd)

		return rs


	def _extractRsp(self, rawRsp):
		# the returned string should be something like '\r\n<response>\r\n<prompt>'
		# or '\r\n<prompt>'
		# tries to extract the response only, removing the additional carriage returns and prompt
		rawRsp = rawRsp.replace(self.READ_LFCR+self.PROMPT, '')
		if rawRsp.startswith(self.READ_LFCR):
			rawRsp = rawRsp[2:]
		return rawRs


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: [newbie] trying socket as a replacement for nc Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-12-16 11:42 +0100

csiph-web