Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hello,I find something wrong in you code.. #3

Closed
ltfychrise opened this issue Apr 6, 2018 · 4 comments
Closed

hello,I find something wrong in you code.. #3

ltfychrise opened this issue Apr 6, 2018 · 4 comments

Comments

@ltfychrise
Copy link

ltfychrise commented Apr 6, 2018

version = '0.1.2'

When I using you project to parser a torrent file , I got some wrong,here is my found, mybe it can help you ~

  • _seek_back nerver rollback _pos
def _seek_back(self, count):
        self._content.seek(-count, 1)
        #my_code_here
        self._pos = self._pos - count
  • the encoding element in torrent files maybe wrong,using charset instead
    def _next_string(self, decode=True):
        length = self._next_int(b':')
        raw = self._read_byte(length)
        if decode:

            #my code here
            self._encoding = chardet.detect(raw)["encoding"]
            if raw == b'':
                string = self._next_string()
            else:
                string = raw.decode(self._encoding)
                
            return string
        return raw
  • _next_int maybe the negative number.

like this: file-mediali-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei-1ei0ei-1ei-1ee

    def _next_int(self, end=END_INDICATOR):
        
        #以END_INDICATOR为分隔符读出字符串个数
        negative = False
        value = 0
        char = self._read_byte(1)
        while char != end:
            #my_code
            if char == b'-':
                char = self._read_byte(1)
                negative = True 
                
            # noinspection PyTypeChecker
            if not b'0' <= char <= b'9':
                raise InvalidTorrentFileException(self._pos)
            value = value * 10 + int(char) - int(b'0')
            char = self._read_byte(1)
            
        #my_code
        if negative:
            value = -value
        
        return value
@7sDream
Copy link
Owner

7sDream commented Apr 6, 2018 via email

@7sDream
Copy link
Owner

7sDream commented Apr 6, 2018

I realized that these problems are very easy to reproduce and don't need test files anymore.

I will fix these issues and add acknowledgments to the ReadMe.

7sDream pushed a commit that referenced this issue Apr 6, 2018
- Fixed: Support negative int
- Fixed: seek_back not move pos
- Added: Auto encoding
@7sDream
Copy link
Owner

7sDream commented Apr 6, 2018

All three bug/enhancement be fixed/added in version 0.1.4.

@7sDream 7sDream closed this as completed Apr 6, 2018
@ltfychrise
Copy link
Author

thank you so much ~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants