Skip to content

Commit 1e57d7e

Browse files
authored
Readline (#111)
* Added line parsing to utils. Added utils line parsing tests. * Updated changelog.
1 parent 2bf0b13 commit 1e57d7e

12 files changed

+896
-373
lines changed

.appveyor.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,17 @@ install:
4848
- "%PYTHON_DEF%\\python.exe ci/appveyor/fix_version.py ."
4949
- mv -f .git .git.bak
5050
- 7z x ci\appveyor\zlib1211.zip
51-
- ps: ls ssh2
5251

5352
build_script:
5453
- ci\\appveyor\\build_zlib.bat
5554
- for %%I in (%PYTHONVERS%) do cp C:/zlib/lib/zlibstatic.lib %%I/libs/
5655
- for %%I in (%PYTHONVERS%) do ls %%I/libs/
5756
- ci\\appveyor\\build_ssh2.bat
5857
- for %%I in (%PYTHONVERS%) do cp src/src/libssh2.lib %%I/libs/ || cp src/src/Release/libssh2.lib %%I/libs/
58+
- mv -f ssh2/find_eol.c .
5959
- rm -f ssh2/*.c
60+
- mv -f find_eol.c ssh2/
61+
- ps: ls ssh2
6062
- for %%I in (%PYTHONVERS%) do %%I\python.exe -V
6163
- for %%I in (%PYTHONVERS%) do %%I\python.exe setup.py build_ext
6264
- for %%I in (%PYTHONVERS%) do %%I\python.exe setup.py build

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ src
88
wheelhouse
99
.idea/
1010
ssh2/libssh2.so*
11+
doc/_build

Changelog.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Change Log
22
=============
33

4+
0.20.0
5+
++++++
6+
7+
Changes
8+
--------
9+
10+
* Added helper function ``ssh2.utils.find_eol`` for finding end of line characters in buffer.
11+
12+
413
0.19.0
514
+++++++
615

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ exclude .travis.yml
77
include LICENSE
88
include ssh2/*.pyx
99
include ssh2/*.pxd
10+
include ssh2/find_eol*

setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import print_function
2-
31
import platform
42
import os
53
import sys
@@ -48,7 +46,7 @@
4846

4947
# _comp_args = ["-ggdb"]
5048
_fwd_default = 0
51-
_comp_args = ["-O3"] if not ON_WINDOWS else None
49+
_comp_args = ["-O2"] if not ON_WINDOWS else None
5250
_embedded_lib = bool(int(os.environ.get('EMBEDDED_LIB', 1)))
5351
_have_agent_fwd = bool(int(os.environ.get('HAVE_AGENT_FWD', _fwd_default)))
5452

@@ -87,6 +85,10 @@
8785
)
8886
for i in range(len(sources))]
8987

88+
for ext in extensions:
89+
if ext.name == 'ssh2.utils':
90+
ext.sources.append('ssh2/find_eol.c')
91+
9092
package_data = {'ssh2': ['*.pxd', 'libssh2.so*']}
9193

9294
if ON_WINDOWS:

ssh2/find_eol.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
This file is part of ssh2-python.
3+
Copyright (C) 2017-2020 Panos Kittenis
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation, version 2.1.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#include <string.h>
20+
21+
static int CR = '\r';
22+
static int EOL = '\n';
23+
24+
int find_eol(char* data, int* new_pos) {
25+
unsigned int index;
26+
char *found;
27+
found = strchr(data, EOL);
28+
if (found == NULL) {
29+
return -1;
30+
}
31+
if (strchr(found-1, CR)) {
32+
found--;
33+
++*new_pos;
34+
}
35+
index = found - data;
36+
++*new_pos;
37+
return index;
38+
}

ssh2/find_eol.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
This file is part of ssh2-python.
3+
Copyright (C) 2017-2020 Panos Kittenis
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation, version 2.1.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
int find_eol(char* data, int* new_pos);

0 commit comments

Comments
 (0)