Python read file in through pipe and break on EOF [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I currently have an application in which I am getting a long string of jpg's in as a string. I would like to break this string into individual files, but I can't find any clear way to recognize EOF's from within Python. I imagine this is a fairly common problem, but I haven't been able to find a solution for this. The string should only be about 20-30 jpgs long, so it's pretty small, but I'm not sure how to recognize EOF's as I go through the string.
I tried just splitting on \0, but it seems that this does not quite indicate EOF for these jpgs.

It would be better to restructure the sending of the files so that you receive them either one by one or with an unambiguous delimiter between each file in the byte stream.
If this is not possible, potentially, you can use the APPO marker and ID. So the marker would be either 0xFFE0[length]0x4A46585800 or 0xFFE0[length]0x4A46494600.
Best case:
read stream until 0xFFE0 is found;
read two byte length (up to 65535×65535 pixels);
verify format by reading the next 5 bytes - break if not nul terminated JFIF or JFXX
read that length and deal with the payload;
loop back to 1
It would be better to deal with each file one by one however.

Related

Detect / replace utf characters [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
I want to detect and/or replace weird utf, non-emoji characters that break my tokenization pipeline, like \uf0fc, which renders like a cup/glass:
That image / code is not contained in the emojis package, which I tried for filtering.
Is there a class that describes all such characters?
Is there a way I can reliably detect them?
This is a character from a Private Use Area. It happens to look like a tankard in your font, but the Unicode standard doesn't mandate a specific look or meaning for these; it has whatever meaning you assign to it. The idea is that you agree upon a meaning with whoever you're communicating with - privately, meaning without getting the Unicode Consortium involved.
You can use the standard unicodedata module to check whether a character is from the Co category, or just hardcode the ranges, as described here.

How to convert python to exe without strings saved in the exe file? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to convert my python project to an Exe file using Nuitka/Pyinstaller, but unfortunately, all of the strings I wrote in the python file, can be found easily inside of the Exe file just by opening the Exe file with notepad.
How can I convert my project to Exe and fully hide the strings and passwords saved inside the py file?
As the comments have mentioned if you want the user to know something only when you want to tell them, not by inspecting the binary, you should try to obfuscate it.
One way of achieving it is, as also suggested in the comments, by encryption. You can convert your .json file to a string and then encrypt it with a given password, which the binary will be aware of, of course.
You can also, which is probably more simple, just encode the string, for example in base 64 and then when calling it you would decode it back again. A small example is as follows:
import base64
s = "your json file as string here".encode("utf-8")
encoded = base64.b64encode(s)
And now each you want to use the string you decode it with:
decoded = base64.b64decode(encoded)
And it shouldn't be available to the end user by inspecting the binary.
Although this is theory doesn't actually prevent an expert user from figuring out what's really written in there, even with encryption, if you hold the encrypted content and the key, then its just a matter of putting the pieces together.

Robot Framework: how to encode string using ascii? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a keyword:
Verify Payment Method Field
Element Text Should Be ${paymentMethodValueField} PDF-lasku sähköpostiin
here is the logs:
Step 3 Fields verification :: OK: Display Customer Information fie... | FAIL |
The text of element '//div/span' should have been 'PDF-lasku s?hk?postiin' but in fact it was 'PDF-lasku s?hk?postiin'.
I need to write something like that, but I don't know how:
PDF-lasku s[ascii symbol]hk[ascii symbol]postiin
can somebody help me?
I would probably convert the whole thing to one format or another, then evaluate? Or is it important that ASCII characters are located in certain parts of the string? If not and you simply want to verify what is returned is exactly what you expect, I'd probably use Encode String to Bytes for simplicity, perhaps even the encoding/decoding keyword would serve your needs if the ASCII is important.
http://robotframework.org/robotframework/latest/libraries/String.html#Encode%20String%20To%20Bytes
By using the above you could set it to ignore the characters that cannot be converted or replace them with a known character that you provide. Simply get the text first, then perform whatever manipulation you want and evaluate.
The alternative with regard to decoding/encoding if ASCII location is important is:
http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Convert%20To%20Bytes

extracting data from several xml-files with python [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I just started learing python for my new job, so everything is quite difficult to me, even if the task sounds pretty straight forward.
I would like to extract several nodes from multiple xml-files, at best putting the information into an excel file in the end. Every row should contain the information from one xml-file, the columns should represent the specific nodes I am looking for, like "Zip-code" "town". Not all xml-files contain all nodes, so it would be perfect, if node "Zip-code" doesnt exist it just leaves the cell blank.
Could someone please point out a few hints how to start with this or, this is also possible, a special programm, which is easy to learn and use? My company and me only need to do it once for about 2000 files.
Thank you very much =)
For opening the files and getting their contents, you can use the Python functions: Documentation.
For XML parsing, I always use Beautiful Soup. It's a HTML/XML parser with good documentation that mostly "just works".
For creating the Excel file, you can use Xlsxwriter.

Is there a way to efficiently create Python objects from outside of Python? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to create a serialized Python object from outside of Python (in this case, from Java) in such a way that Python can read it and treat it as if it were an object in Python. I'll start with simpler objects (int, float, String, and so on) but I'd love to know if this can be done with classes as well.
Functionality is first, but being able to do it quickly is a close second. The idea is that I have some data in Java land, but some business logic in Python land. I want to be able to stream data through the python logic as quickly as possible...right now, this data is being serialized as strings and I think this is fairly wasteful.
Thank you in advance
The best answer is to use a standardized format, such as JSON, and write up something to create the objects from that format in Python, and produce the data from Java. For simple things, this will be virtually no effort, but naturally, it'll scale up.
Trying to emulate pickle from within Java will be more effort than it's worth, but I guess you could look into Jython if you were really set on the idea.

Categories