Problem stripping characters from a pexpect query - python-3.x

I'm testing a python script to retrieve the software version from Cisco gear. The script works fine connecting to the remote device and obtaining the information required. The problem starts when I try to filter some unwanted information from pexpect output. The function's code in charge of getting the vesion information is as follows:
def get_version_info(session):
session.sendline('show version | include Version')
result = session.expect(['>', pexpect.TIMEOUT])
# Extract the 'version' part of the output
version_output_lines = session.before.splitlines()
version = version_output_lines[4].strip("'")
print("--- got version: ", version)
return version
The required information from the raw output after spliting lines (line 5 in code) was placed in the following list:
[b' ', b'', b'HOSTNAME#show version | include Version', b'Cisco IOS XE Software, Version 16.09.02', b'Cisco IOS Software [Fuji], ASR1000 Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.9.2, RELEASE SOFTWARE (fc4)', b'licensed under the GNU General Public License ("GPL") Version 2.0. The', b'software code licensed under GPL Version 2.0 is free software that comes', b'GPL code under the terms of GPL Version 2.0. For more details, see the', b'HOSTNAME#']
All I need from the above output is "Version 16.9.2", the rest needs to be stripped out.
I tried to isolate element 4 of the list (version_output_lines[4]) and use the strip function, but it keeps sending an error:
TypeError: a bytes-like object is required, not 'str'
So I'd like to know if you have a better idea on how to strip all the unwanted information from the list and only leave the Version info as mentioned before.
Thanks.

The .strip() method exists for type strings and also for type bytes. When applied to bytes it needs a bytes parameter instead of the string "'" you supplies. So use .strip(b"'").
You can also decide to have pexpect encode the bytes into strings by using, for example, encoding='utf8' as a parameter in the spawn() call.

Related

pgfopts: arguments with spaces don't play well with babel

If I define a new package like this
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myPlanning}[2022/07/16 my Planning class]
\LoadClass[french]{article}
\RequirePackage{pgfopts}
\pgfkeys{
/myOrg/.cd,
lang/.initial = english , lang/.store in = \myOrg#lang,
title/.initial = title , title/.store in = \myOrg#title,
}
\ProcessPgfOptions{/myOrg}
\RequirePackage[\myOrg#lang]{babel}
and I try to compile this document
\documentclass[lang=french,title={truc bidul}]{myPlanning}
\begin{document}
some text here
\end{document}
I get the following error:
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian) (preloaded format=pdflatex)
restricted \write18 enabled.
entering extended mode
(./Test.tex
LaTeX2e <2021-11-15> patch level 1
L3 programming layer <2022-01-21>
(/home/hylkema/texmf/tex/latex/local/Org/myPlanning.cls
Document Class: myPlanning 2022/07/16 my Planning class
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2021/10/04 v1.4n Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/pgfopts/pgfopts.sty
(/usr/share/texlive/texmf-dist/tex/latex/pgf/utilities/pgfkeys.sty
(/usr/share/texlive/texmf-dist/tex/generic/pgf/utilities/pgfkeys.code.tex
(/usr/share/texlive/texmf-dist/tex/generic/pgf/utilities/pgfkeysfiltered.code.t
ex))))) (/usr/share/texlive/texmf-dist/tex/generic/babel/babel.sty
(/usr/share/texlive/texmf-dist/tex/generic/babel/txtbabel.def)
(/usr/share/texlive/texmf-dist/tex/generic/babel-french/french.ldf)
! LaTeX Error: Missing \begin{document}.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.4261 \ifin#\edef\bbl#tempc{\bbl#tempb}\fi}
?
However, if I compile this (No spaces in the title argument):
\documentclass[lang=french,title=truc]{myPlanning}
\begin{document}
some text here
\end{document}
It compiles fine with no errors.
What's more, the first document with spaces in the title argument compiles fine if I remove the \RequirePackage[\myOrg#lang]{babel} line from the package definition.
Is this a known problem and is there a solution ?
Thanks for your help,
Jouke
Update: The underlying issue was fixed in upstream babel on 2022-11-24 and should be resolved in the next release.
The issue is not the key=value parser but a code block of babel that tries to detect whether the wrong language is loaded if it got both options from the \documentclass and options when the package was called. That being said, pgfopts isn't up-to-date with current LaTeX (there were substantial changes to the option-system about a year ago that pgfopts has not yet followed suit), the only solutions to key=value options that are compatible to my knowledge are the builtin mechanism and expkv-opt.
But as I said, neither will solve your issue. Using main=\myOrg#lang in the options of babel however will, as if you used the main-option the problematic code of babel will not be used. So if you change your class to the following the only (admittedly strange) warning regarding your options you'll get will be
LaTeX Warning: Unused global option(s):
[french].
(but that stems from your strange usage of \LoadClass, in which article will add french to the unused options list though it isn't in the global options list, hence babel will not pick it up and remove it from said list).
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myPlanning}[2022/07/16 my Planning class]
\LoadClassWithOptions{article}
\RequirePackage{pgfopts}
\pgfkeys{
/myOrg/.cd
,lang/.initial = english
,lang/.store in = \myOrg#lang
,title/.initial = title
,title/.store in = \myOrg#title,
}
\ProcessPgfOptions{/myOrg}
\RequirePackage[main=\myOrg#lang]{babel}

icu tokenizer in node.js 12

I have a ICU tokenizer for Python3. This python code uses BreakIterator and Locale from icu (PyICU) library:
from icu import Locale,BreakIterator
def wordSegmenter(txt, iter):
tokens = []
bi.setText(txt)
start = iter.first()
try:
while True:
end = next(iter)
tokens.append(txt[start:end])
start = end
except StopIteration:
pass
return tokens
text = u'退屈であくびばっかしていた毎日'
tokens = wordSegmenter(text, wordBreakIterator("ja"))
['退屈', 'で', 'あくび', 'ばっか', 'し', 'てい', 'た', '毎日']
I have now to port ICU to to NodeJS via node-gyp bindings. When building the native library here I get the error
../src/wordsplit.cc:82:65: error: too few arguments to function call, single argument 'context' was
not specified
Nan::New<FunctionTemplate>(SplitWords)->GetFunction());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/Users/loretoparisi/Library/Caches/node-gyp/12.13.1/include/node/v8.h:5995:3: note: 'GetFunction'
that seems to be related to Nan support and Node12.x. How to correctly correctly port to Node12 and get rid of V8 deprecations?
Well, as the error message tells you, FunctionTemplate::GetFunction now needs a Context. I don't know much about Nan, but I'd suggest to try Nan::GetCurrentContext().
That said, if you run Node 12 with --harmony-intl-segmenter, you get access to V8's supposedly complete (but not yet shipping by default) implementation of the JavaScript Intl.Segmenter proposal (https://github.com/tc39/proposal-intl-segmenter), which is also based on ICU. That might save you a bunch of work, and it's on the way towards becoming an official part of JavaScript, so it will soon be widely available.

Adding json data to json column is adding escape characters

I am using postgres database, I have a table called names which has a column named 'info' which is of type json. I am adding
{ "info": "security" , description : "Sednit update: Analysis of Zebrocy: The Sednit group \u2013 also known as APT28, Fancy Bear, Sofacy or STRONTIUM \u2013 is a group of attackers operating since 2004, if not earlier, and whose main objective is to steal confidential information from specific targets.\n\nToward the end of 2015, we started seeing a new component deployed by the group; a downloader for the main Sednit backdoor, Xagent. Kaspersky mentioned this component for the first time in 2017 in their APT trend report and recently wrote an article where they quickly described it under the name Zebrocy.\n\nThis new component is a family of malware, comprising downloaders and backdoors written in Delphi and AutoIt. These components play the same role in the Sednit ecosystem as Seduploader; that of first-stage malware."}
Here I am using node js, with sequelize as orm. When I save it in table. I see "\\n" for "\n" and "\\u" for \u. Can anyone help me to avoid escaping characters while saving to table.
I see \n for \n and \u for \u.
In your json description is type of string , so it will convert the new line/enter to \n that the default behavior , or else you will not get the new line / enter when you try to fetch the data again.
And \u is for unicode , you might be saving some smily or special character so that will be converted to such strings.
So there is no bug , this is how it works.

different numbers of variable names and field specifiers error in tcl for linux server

here i am using set numCut [scan $inline1 "%d"] in tcl script for linux server, but after execting script it's showing below error
`different numbers of variable names and field specifiers` variable $inline1
value is `2) "NYMEX UTBAPI Worker" (NYMEX UTBAPI Poller): STOPPED`
i searched in google for this then i got below
`
0x1771b07c tcl_s_cmdmz_diff_num_var_field
Text: Different numbers of variable names and field specifiers
Severity: tcl_c_general_error
Component: tcl / tcl_s_general
Explanation: The scan command detected that the number of variable names
provided differs from the number of field specifiers provided.
Action: Verify that the number of variable names is the same as the number of
field specifiers.
`
here i got the above description.
Can anyone help me out how to solve this issue?
thanks in advance...
The ability to return the matched fields was added in Tcl 8.5. Prior to that, you had to supply a variable for each field that you had in the scan, and the result would be the number of fields matched (and it still is if you provide variable names).
Change:
set numCut [scan $inline1 "%d"]
to:
scan $inline1 "%d" numCut
Or switch to a more recent version of Tcl if you can, as 8.4 is almost out of its extended support period. (There will be a final patch release this summer to address some minor issues with build problems on recent systems, but that's it. We won't support it after that.)
I think that the Tcl error message is telling you that the number of specifiers in your format string %d is different to the number of variables in your Tcl command scan $inline1 "%d".
So, you have one format specifier, and no variables and that's what the Tcl interpreter is telling you.
Try changing your command to scan $inline1 "%d" numCut and see if that works any better.

TCL (thermal control language) [printer protocol] references

I'm working on supporting of the TCL (thermal control protocol, stupid name, its a printer protocol of futurelogic) but i cannot find resources about this protocol, how it is, how it works, nothing, on theirs site i only found this mention http://www.futurelogic-inc.com/trademarks.aspx
any one had worked with it? does any one knows where can i find the data sheet?
The protocol is documented on their website http://www.futurelogic-inc.com/support/downloads/
If you are targetting the PSA66ST model it supports a number of protocols TCL, which is quite nice for delivering templated tickets and, line printing using the Epson ESC/P protocol.
This is all explained in the protocol document.
Oops, these links are incorrect and only correspond to marketing brochures. You will need to contact Futurelogic for the protocol documents. Probably also need to sign an NDA. Anyway, the information may guide you some more.
From what I can gather, it seems the FutureLogic thermal printers do not support general printing, but only printing using predefined templates stored in the printer's firmware. The basic command structure is a caret ^ followed by a one or two character command code, with arguments delimited using a pipe |, and the command ended with another caret ^. I've been able to reverse-engineer a few commands:
^S^ - Printer status
^Se^ - Extended printer status
^C|x|^ - Clear. Known arguments:
a - all
j - jam
^P|x|y0|...|yn|^ - Print fields y0 through yn using template x.
Data areas are defined in the firmware using a similar command format, command ^D|x|y0|...|yn|^, and templates are defined from data areas using command ^T|z|x0|...|xn|^.

Resources